Welcome to Gaia! ::

Keist's & Highpass's Gaia Modifications

Back to Guilds

Home of the Gaia Enhancement Suite! Come check out our mods, and join to receive updates via PM about new tweaks. 

Tags: modifications, tweaks, scripts, styles, javascript 

Reply Keist's & Highpass's Gaia Modifications
GES Module Programming Guide

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

Highpass
Vice Captain

Aged Genius

PostPosted: Sat Jun 11, 2011 5:58 pm


Most of you will probably find this thread useless. If there are any programmers out there interested in writing their own modules, though, this is the thread for you.

In an effort to make things easier for myself, the module interface is fairly standard. The module list is stored in an array, and each module is an object. The object has a few properties (name, description, and options) and one method (run).

Name is just a string defining the name of the module. Description is another string, giving a little more info about the module.

The run method is what actually does all (or most) of the work.

Options is an array of objects, each of which represents an option for the module. There are a few option types available to you: text, password, toggle, action, and textbox.

Each option object has a few properties. All of them have a type (as listed above) and a label.

Text, password, textbox, and toggle have two more properties, initial and varname. initial refers to the value of the option before the user changes it. Texts, passwords, and textboxes should have a string, and toggles should have a boolean (true or false). The varname is the identifier by which its value is stored. More on that later. One important note about the varname: to avoid interaction with other modules, you'll want this to be uniquely named. I normally name them something like ges_[module identifier]_[option identifier] to avoid overlap.

Texts and passwords have a property called check. This is a regular expression used to verify the format of the data.

Finally, actions have two other properties: action, which is a function, and wait_text, which is the text to display while the function is executing.

If you need more complicated options, you can create a new tab, but so far that is essentially for me only. The interface for that isn't exactly clean at the moment.

In addition, GES uses jQuery, so (almost) anything you can do with that, you can do with a GES module.
PostPosted: Sat Jun 11, 2011 6:06 pm


Let's take a look at a real example: the thread highlighter. I'm using ` to indent the code because Gaia's code tag is broken.

{
````name: "Thread Highlighter",
````description: "Highlights threads meeting certain criteria.",
````options:
````[
````````{
````````````type: "text",
````````````label: "Limit highlight color (e.g., #FFD700)",
````````````varname: "ges_thread_highlight_color",
````````````check: /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/,
````````````initial: "#FFD700"
````````},
````````{
````````````type: "text",
````````````label: "Highlight limit (0 = disabled)",
````````````varname: "ges_thread_highlight_limit",
````````````check: /^[0-9]+$/,
````````````initial: "0"
````````},
````````{
````````````type: "text",
````````````label: "Friend highlight color (e.g., #78D0CC)",
````````````varname: "ges_thread_highlight_friend_color",
````````````check: /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/,
````````````initial: "#78D0CC"
````````},
````````{
````````````type: "toggle",
````````````label: "Highlight friends' threads",
````````````varname: "ges_thread_highlight_friends",
````````````initial: false
````````},
````````{
````````````type: "action",
````````````label: "Update locally stored friend list",
````````````action: ges_update_friend_list,
````````````wait_text: "Updating, please wait..."
````````}
````],
````run: function(){
````````limit = GM_getValue("ges_thread_highlight_limit","0")
````````color = GM_getValue("ges_thread_highlight_color","#ffd700")
````````fcolor = GM_getValue("ges_thread_highlight_friend_color","#78D0CC")
````````$(".forum-list .replies").filter(function(){return parseInt($(this).text())````````if( GM_getValue("ges_thread_highlight_friends",false) ){
````````````friendlist = JSON.parse(GM_getValue("ges_friend_list","[]"))
````````````$(".forum-list .creator a").each(function(){
````````````````if( $.inArray($(this).text(),friendlist) != -1 )
````````````````````$(this).parents("tr").css("background",fcolor)
````````````})
````````}
````}
}


So the first thing we do, naturally, is define the name and the description. Pretty self-explanatory.

The options list you can see by looking at the module in GES (assuming you have it installed). The checks are reasonably understandable if you understand regular expressions; the colours are set to require something of the type #fff or #ffffff. The number must be a number.

The action may look a little strange, because I defined this function elsewhere and just referred to it by name. In your own modules, you could simply define the function there, the same way run is defined below.

And speaking of run, here's the meat. First things first: we fetch the values of the options that are stored. Option settings are saved automatically, but not retrieved... this will probably change in a future version. Anyway, the first few lines retrieve the options. GM_getValue is a greasemonkey function for retrieving stored values. In this case, the first argument is the varname of the option, and the second is the initial value.

Next is a line that does all the post count-based highlighting. In one line. I love jQuery.

Next, it checks if the friend highlighting option was enabled, and if so, it gets the local copy of the friends list. Because GreaseMonkey can only store strings, more complicated data types must be stringified before storage, and unstringified after storage. That's what the JSON.parse function does.

After that, it just loops over the topics, checks if any are made by your friends, and highlights them.

That's it. Module: done.

Highpass
Vice Captain

Aged Genius


dandy dickhead

PostPosted: Sat Jun 11, 2011 9:52 pm


http://pastebin.com/JveUs1Lp

Simple word filtering module. Cool guide, hope more people enjoy it.

http://pastebin.com/7iAfhTq9

And a reminder to take breaks from gaya.
Updated to remind you on every page load for specified number of minutes. smile
Reply
Keist's & Highpass's Gaia Modifications

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum