Enquirer Home Page | Twitter | Back to Improbable Island
 

Tips for Scripting

Getting started

Once you have Greasemonkey (or equivalent) installed, and some vague idea of what it is you want to do, it's mostly just googling how to do anything you want to do, and a lot of trial and error. If you're really stuck, try asking Banter about your problems.

Misc

Alright, let's get this straight first of all: the correct way to spell and capitalize the word is "Greasemonkey".

If you're modifying a script, you can (and should) replace all instances of GM_log with console.log.

If you improve a script significantly, you might add your name to the list of authors, or a note that the script was modified by you.

By pseudo-arbitrary convention, all scripts should have a name of the form "ii-some-words". Scripts should be hosted on the wiki in the greasemonkey namespace, in a page with the same name as the script. You can see a full list of pages in the greasemonkey namespace here.

It's pretty poor style to use jQuery in your userscript, since jQuery is presumably far more complex than the entire rest of your userscript. But if you need a copy, you can use the version hosted by II:1) https://www.improbableisland.com/js/jquery.js (v1.7 as of 2019). Since Greasemonkey caches anything it @requires, this will only request one copy of jQuery, when the script is installed by the user, and so this will not put strain upon II's servers.

Metadata

It's customary to include a metadata block in your script. Some of the lines in the metadata block influence how the script runs, like @match, and some are just for people reading the script, like @author.

Please include an @version line in your script, and increment some part of it when you change the script. Version numbers typically look like 1 or 1.0. Add 1 to the number after the dot when you make a minor change, and add 1 to the number before the dot when you make a major change.2) If you just change the metadata of the script you don't have to change the version number.3) The purpose of a version number is, generally, to allow users to make sure they have the correct version of the script.

If you don't have a good namespace for your script, why not use http://enquirer.improbableisland.com/dokuwiki/doku.php?id=greasemonkey?

If you don't have a good icon for your script, why not use @icon https://improbableisland.com/favicon.ico?4)

Firefox will complain for a second if you don't include an ''@grant'' line. You probably want @grant none.

Chrome will make it sound scarier if you use @include instead of match. For this reason, it is recommend to use @match *://*.improbableisland.com/* and @exclude *://enquirer.improbableisland.com/* if you want a script that just runs during the game.

Example Empty Script

Look at the source of this page in order to see how to set up a code block. You have to have a character after the first >, or else it won't give a download link!

ii-your-script
// ==UserScript==
// @name           ii-your-script
// @namespace      http://enquirer.improbableisland.com/dokuwiki/doku.php?id=greasemonkey
// @author         You!
// @description    This is my script!
// @version        1
// @match          *://*.improbableisland.com/*
// @exclude        *://enquirer.improbableisland.com/*
// @icon           https://improbableisland.com/favicon.ico
// @grant          none
// ==/UserScript==
1) To be clear, you can also use any other version, hosted by anyone else. This is just an option. However, it might be a wiser option than @requireing a script stored on an external website that might go kaput.
2) Opinions differ on what happens when you make a minor change to version 1.9. Do you get version 2, version 1.10, or version 1.91? Luckily, we've never had to make more than 9 minor changes to a script, so we've never found out.
3) Some userscripts here on the wiki were written by people with other ideas of what a version number should be like, so those userscripts have that style of version number.
 
Logged in as: Guest (Guest)
greasemonkey/scripting.txt · Last modified: 2019/12/30 20:36 by Full Metal Lion