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.