16

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 + ".");.

1 Answer 1

24

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.