Script Update Checker

By Jarett Last update Apr 30, 2009 — Installed 17,336 times.

How to get the @version ?

in
Subscribe to How to get the @version ? 10 posts, 3 voices



Arias Scriptwright
FirefoxWindows

Is there anyway to make var for @version from local and remote ?

So you can see the "real" version number instead av the version number that its getting now.

Thanks for the code btw !

 
Jarett Script's Author
FirefoxWindows

I don't know of a way to get any meta-data for the local copy of the script; however, Greasemonkey probably has a way to do it by now.

 
Arias Scriptwright
FirefoxWindows

the local version can you just add a variable manually. dont you know about getting the remote "real" version number ?

 
Jarett Script's Author
FirefoxWindows

I'm not sure what you're asking.

 
Arias Scriptwright
FirefoxWindows

hm, how to creating a var from the version on the site.

for example if you take my script http://userscripts.org/scripts/show/56716, in the code i got the meta-data "@version".

var localver = "1.2.4.1.1"; //this value can I change manually every time I update the script
var remotever = ? //this value should be the value you can find on the script page, in the upper left corner "Version: 1.2.4.1.1" (it's from the metadata @version in the latest code).

so i can get this to work I can just be using a message when a new version is out, like;
("I new version is out: "+remotever+". Your current version is: "+localver+". Wanna download new one?");

My english is not the best, hope you get what I meant.

 
Jarett Script's Author
FirefoxWindows

You'd have to parse it out of the meta.js file for that script. Probably something like this (I haven't tested this, so there might be some syntax errors):

var script_number=56716;

try
{
	GM_xmlhttpRequest(
	{
		method: 'GET',
		url: 'http://userscripts.org/scripts/source/'+ script_number +'.meta.js?'+new Date().getTime(),
		headers: {'Cache-Control': 'no-cache'},
		onload: function(resp)
		{
			var remote_version;
			
			remote_version=parseInt(/@version\s*(.*?)\s*$/m.exec(resp.responseText)[1]);
			alert('Remote version is: '+ remote_version);
		}
	});
}
catch (err)
{
	alert('An error occurred while checking the version:\n'+ err);
}

 
Arias Scriptwright
FirefoxWindows

yes, that was something i was looking for.
I will try it ! thanks for your time and help !

 
Jarett Script's Author
FirefoxWindows

No problem.

 
ViXaY Xavier Scriptwright
FirefoxWindows

also check out the metadata block info on http://wiki.greasespot.net/Metadata_block. This has a very good example on parsing metadata for local and remote scripts! :)
I found a problem though when parsing remote meta data I had to make a minor modification.
from

  for each (line in lines) {

to
  var i=0;
  for each (line in lines) {
    if (++i > lines.length) break; // to control error in looping from remote responses

because the loop was continuing even after reaching the last element... don't know why.

 
Jarett Script's Author
FirefoxWindows

Ah, thanks. I figured there was a way to get the local metadata; I just didn't know what it was.