Greasemonkey Script Version Constant

I defined the version of my user script in the metablock, for example:

// ==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 any way to get the version number that I determined? I want to do something like alert("This is version " + SCRIPT_VERSION + "."); .

+6
source share
1 answer

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

You can add this to your example script above:

 var myVersion = GM_info.script.version; console.log ('Version: ', myVersion, myVersion === "5.3.0"); 

Which prints this to the console:

 Version: 5.3.0 true 



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

+11
source

Source: https://habr.com/ru/post/908193/


All Articles