Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greasemonkey Script Version Constant

I defined the version of my user script in the meta block, like this:

// ==UserScript==
// @name Script Name
// @description Something about what this script does 
// @include http://www.example.com/
// @version 5.3.0
// @run-at document-end
// ==/UserScript==

Is there a way to get the version number that I defined? I want to be able to do something like alert("This is version " + SCRIPT_VERSION + ".");.

like image 806
wecsam Avatar asked Feb 11 '12 02:02

wecsam


1 Answers

If you upgrade to Greasemonkey 0.9.16 (just released), you can use the brand new GM_info object.

You can add this to your script example, above:

var myVersion = GM_info.script.version; 

console.log ('Version: ', myVersion, myVersion === "5.3.0");

Which would output this to the console:

Version: 5.3.0 true 



For GM versions prior to 0.9.16, you'd have to either read your own script in as a @resource or use encapsulation techniques as shown in "Knowing Your Own Metadata".

like image 186
Brock Adams Avatar answered Oct 07 '22 18:10

Brock Adams