Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New metadata request: minimum Firefox and Greasemonkey version requirement #1788

Open
wants to merge 5 commits into from

4 participants

janekptacijarabaci Mayhem Tobias Engelmann arantius
janekptacijarabaci

Ad #1726
The suggestion (for example).

janekptacija... added some commits
Mayhem

Does it disable the userscript when downgrading Firefox too?

janekptacijarabaci

The minimal version has to be checked before every start - changing in the file scriptMatchesUrlAndRuns.js. The user can also change the Metadata Block!

David Lohle Proplex referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
AchtBit AchtBit referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Mayhem

@arantius
Pretty please!

arantius arantius modified the milestone: 1.17, 1.16
arantius arantius modified the milestone: 2.2, 2.1
arantius arantius modified the milestone: 2.4, 2.3
arantius arantius modified the milestone: 2.4, 2.5
janekptacijarabaci janekptacijarabaci deleted the branch
janekptacijarabaci janekptacijarabaci restored the branch
janekptacijarabaci

Oops... I'm sorry.

Tobias Engelmann

Looks a little bit like some discussion in JasonBarnabe/greasyfork#30
But I'd prefer a more general syntax as metioned there, so the keyword is the same for every engine supporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 12, 2013
  1. Update script.js

    janekptacijarabaci authored
  2. Update parseScript.js

    janekptacijarabaci authored
  3. Update scriptMatchesUrlAndRuns.js

    janekptacijarabaci authored
  4. Update greasemonkey.properties

    janekptacijarabaci authored
  5. Update greasemonkey.properties

    janekptacijarabaci authored
This page is out of date. Refresh to see the latest.
4 locale/cs/greasemonkey.properties
View
@@ -26,6 +26,10 @@ parse.require-failed=Nezdařilo se @require URL: %1
parse.resource-syntax=Neplatná syntaxe pro @resource deklaraci "%1". Zdroje / resources jsou deklarovány jako "@resource <název> <url>".
parse.resource-duplicate=Detekován duplicitní název zdroje / resource "%s". Každý zdroj / resource musí mít jedinečný / unikátní název.
parse.resource-failed=Nezdařilo se načtení @resource %1 z %2
+parse.ff-failed=Minimální Firefox verze: %1
+parse.gm-failed=Minimální Greasemonkey verze: %1
+run.ff-failed=Uživatelský skript "%1" nebyl spuštěn, minimální Firefox verze: %2
+run.gm-failed=Uživatelský skript "%1" nebyl spuštěn, minimální Greasemonkey verze: %2
remotescript.name-unknown=RemoteScript.install(): Skript má neznámý základní název.
remotescript.not-downloaded=RemoteScript.install(): Skript není stažen.
remotescript.unsafe-url=Nebude staženo nebezpečné URL:\n%1
4 locale/en-US/greasemonkey.properties
View
@@ -26,6 +26,10 @@ parse.require-failed=Failed to @require URL: %1
parse.resource-syntax=Invalid syntax for @resource declaration "%1". Resources are declared like "@resource <name> <url>".
parse.resource-duplicate=Duplicate resource name "%s" detected. Each resource must have a unique name.
parse.resource-failed=Failed to get @resource %1 from %2
+parse.ff-failed=The minimal Firefox version: %1
+parse.gm-failed=The minimal Greasemonkey version: %1
+run.ff-failed=User Script "%1" not run, the minimal Firefox version: %2
+run.gm-failed=User Script "%1" not run, the minimal Greasemonkey version: %2
remotescript.name-unknown=RemoteScript.install(): Script base name unknown.
remotescript.not-downloaded=RemoteScript.install(): Script is not downloaded.
remotescript.unsafe-url=Will not download unsafe URL:\n%1
28 modules/parseScript.js
View
@@ -19,6 +19,13 @@ var gStringBundle = Components
.getService(Components.interfaces.nsIStringBundleService)
.createBundle("chrome://greasemonkey/locale/greasemonkey.properties");
+var GM_GUID = "{e4a8a97b-f2ed-450b-b12d-ee082ba24781}";
+var gGreasemonkeyVersion = 'unknown';
+Components.utils.import("resource://gre/modules/AddonManager.jsm");
+AddonManager.getAddonByID(GM_GUID, function(addon) {
+ gGreasemonkeyVersion = '' + addon.version;
+});
+
/** Get just the stuff between ==UserScript== lines. */
function extractMeta(aSource) {
var meta = aSource.match(gAllMetaRegexp);
@@ -156,6 +163,27 @@ function parse(aSource, aUri, aFailWhenMissing, aNoMetaOk) {
case 'run-at':
script._runAt = value;
break;
+ case 'minFFVer':
+ if ((null !== value) && (GM_util.compareFirefoxVersion(value) < 0)) {
+ script.parseErrors.push(
+ gStringBundle.GetStringFromName('parse.ff-failed')
+ .replace('%1', value)
+ );
+ }
+ script._minFFVer = value;
+ break;
+ case 'minGMVer':
+ var versionChecker = Components
+ .classes["@mozilla.org/xpcom/version-comparator;1"]
+ .getService(Components.interfaces.nsIVersionComparator);
+ if ((null !== value) && (versionChecker.compare(gGreasemonkeyVersion, value) < 0)) {
+ script.parseErrors.push(
+ gStringBundle.GetStringFromName('parse.gm-failed')
+ .replace('%1', value)
+ );
+ }
+ script._minGMVer = value;
+ break;
}
}
16 modules/script.js
View
@@ -53,6 +53,8 @@ function Script(configNode) {
this._updateURL = null;
this._userExcludes = [];
this._userIncludes = [];
+ this._minFFVer = null;
+ this._minGMVer = null;
this._uuid = [];
this._version = null;
@@ -191,6 +193,12 @@ function Script_getResources() { return this._resources.concat(); });
Script.prototype.__defineGetter__('runAt',
function Script_getRunAt() { return this._runAt; });
+Script.prototype.__defineGetter__('minFFVer',
+function Script_getMinFFVer() { return this._minFFVer; });
+
+Script.prototype.__defineGetter__('minGMVer',
+function Script_getMinGMVer() { return this._minGMVer; });
+
Script.prototype.__defineGetter__('filename',
function Script_getFilename() { return this._filename; });
@@ -343,6 +351,8 @@ Script.prototype._loadFromConfigNode = function(node) {
this._description = node.getAttribute("description");
this._runAt = node.getAttribute("runAt") || "document-end"; // legacy default
this.icon.fileURL = node.getAttribute("icon");
+ this._minFFVer = node.getAttribute("minFFVer");
+ this._minGMVer = node.getAttribute("minGMVer");
this._enabled = node.getAttribute("enabled") == true.toString();
};
@@ -410,6 +420,8 @@ Script.prototype.toConfigNode = function(doc) {
scriptNode.setAttribute("name", this._name);
scriptNode.setAttribute("namespace", this._namespace);
scriptNode.setAttribute("runAt", this._runAt);
+ scriptNode.setAttribute("minFFVer", this._minFFVer);
+ scriptNode.setAttribute("minGMVer", this._minGMVer);
scriptNode.setAttribute("uuid", this._uuid);
scriptNode.setAttribute("version", this._version);
@@ -466,6 +478,8 @@ Script.prototype.info = function() {
// 'requires': ???,
'resources': resources,
'run-at': this.runAt,
+ 'minFFVer': this.minFFVer,
+ 'minGMVer': this.minGMVer,
'version': this.version,
},
'scriptMetaStr': extractMeta(this.textContent),
@@ -562,6 +576,8 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin) {
this._matches = newScript._matches;
this._description = newScript._description;
this._runAt = newScript._runAt;
+ this._minFFVer = newScript._minFFVer;
+ this._minGMVer = newScript._minGMVer;
this._version = newScript._version;
this._downloadURL = newScript._downloadURL;
this.updateURL = newScript.updateURL;
58 modules/util/scriptMatchesUrlAndRuns.js
View
@@ -1,9 +1,57 @@
const EXPORTED_SYMBOLS = ['scriptMatchesUrlAndRuns'];
+Components.utils.import('resource://greasemonkey/util.js');
+
+var gStringBundle = Components
+ .classes["@mozilla.org/intl/stringbundle;1"]
+ .getService(Components.interfaces.nsIStringBundleService)
+ .createBundle("chrome://greasemonkey/locale/greasemonkey.properties");
+
+var GM_GUID = "{e4a8a97b-f2ed-450b-b12d-ee082ba24781}";
+var gGreasemonkeyVersion = 'unknown';
+Components.utils.import("resource://gre/modules/AddonManager.jsm");
+AddonManager.getAddonByID(GM_GUID, function(addon) {
+ gGreasemonkeyVersion = '' + addon.version;
+});
+
function scriptMatchesUrlAndRuns(script, url, when) {
- return !script.pendingExec.length
- && script.enabled
- && !script.needsUninstall
- && (script.runAt == when || 'any' == when)
- && script.matchesURL(url);
+ var result = !script.pendingExec.length
+ && script.enabled
+ && !script.needsUninstall
+ && (script.runAt == when || 'any' == when)
+ && script.matchesURL(url);
+
+ var minFFVer = true;
+ var minGMVer = true;
+
+ if (result && ('null' !== script.minFFVer) && (GM_util.compareFirefoxVersion(script.minFFVer) < 0)) {
+ GM_util.logError(
+ gStringBundle.GetStringFromName('run.ff-failed')
+ .replace('%1', script.name)
+ .replace('%2', script.minFFVer),
+ true, // is a warning
+ script.fileURL,
+ null
+ );
+ minFFVer = false;
+ }
+
+ var versionChecker = Components
+ .classes["@mozilla.org/xpcom/version-comparator;1"]
+ .getService(Components.interfaces.nsIVersionComparator);
+ if (result && ('null' !== script.minGMVer) && (versionChecker.compare(gGreasemonkeyVersion, script.minGMVer) < 0)) {
+ GM_util.logError(
+ gStringBundle.GetStringFromName('run.gm-failed')
+ .replace('%1', script.name)
+ .replace('%2', script.minGMVer),
+ true, // is a warning
+ script.fileURL,
+ null
+ );
+ minGMVer = false;
+ }
+
+ return result
+ && minFFVer
+ && minGMVer;
}
Something went wrong with that request. Please try again.