[Greasemonkey] Long literal strings of html

Edward Lee edilee at gmail.com
Sun Apr 17 17:51:07 EDT 2005

Well, I'll move my post into here because seems like people don't want
to talk about "Variable Text Block" :p

I modifed my browser.xul modification to create a GM_getString()
function instead of creating the variables in the user script scope.
You still define the long literal string (now constant) in a /*=
varname data stuff *=/ block, and now you just do
GM_getString('varname') to get the value.

Test script: http://ed.agadak.net/greasemonkey/GM_getStringTest.user.js
Modifed browser.xul: http://ed.agadak.net/greasemonkey/browser.GM_getString.xul
Diff/patch: http://ed.agadak.net/greasemonkey/browser.old.GM_getString.diff

Also, the script still works fine if no /=* *=/ blocks are found.. it
just adds a function that'll return null for any key.

var GM_getString = (function(hash) { return function(key) { return
hash[key]; }; }) ({});
Set GM_getString to a function that takes a key that looks it up in a
hash variable that is kept available with the closure... in this case,
the hash is {}.


More information about the Greasemonkey mailing list