/usr/share/xul-ext/greasemonkey/modules/parseScript.js is in xul-ext-greasemonkey 1.15-1~deb7u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | var EXPORTED_SYMBOLS = [
'extractMeta', 'parse', 'gLineSplitRegexp', 'gMetaLineRegexp'];
Components.utils.import('resource://greasemonkey/script.js');
Components.utils.import('resource://greasemonkey/scriptIcon.js');
Components.utils.import('resource://greasemonkey/scriptRequire.js');
Components.utils.import('resource://greasemonkey/scriptResource.js');
Components.utils.import('resource://greasemonkey/third-party/MatchPattern.js');
Components.utils.import('resource://greasemonkey/util.js');
var gIoService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var gLineSplitRegexp = /.+/g;
var gAllMetaRegexp = new RegExp(
'^// ==UserScript==([\\s\\S]*?)^// ==/UserScript==', 'm');
var gMetaLineRegexp = new RegExp('// @(\\S+)(?:\\s+(.*))?');
var gStringBundle = Components
.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService)
.createBundle("chrome://greasemonkey/locale/greasemonkey.properties");
/** Get just the stuff between ==UserScript== lines. */
function extractMeta(aSource) {
var meta = aSource.match(gAllMetaRegexp);
if (meta) return meta[1].replace(/^\s+/, '');
return '';
}
/** Parse the source of a script; produce Script object. */
function parse(aSource, aUri, aFailWhenMissing, aNoMetaOk) {
var meta = extractMeta(aSource).match(gLineSplitRegexp);
if (aFailWhenMissing && !meta && !aNoMetaOk) return null;
var script = new Script();
if (aUri) script.downloadURL = aUri.spec;
if (aUri && aUri.spec) {
var name = aUri.spec;
name = name.substring(0, name.indexOf(".user.js"));
name = name.substring(name.lastIndexOf("/") + 1);
script._name = name;
}
if (aUri) script._namespace = aUri.host;
if (!meta && aNoMetaOk) {
setDefaults(script);
return script;
}
var resourceNames = {};
if (meta) for (var i = 0, metaLine = ''; metaLine = meta[i]; i++) {
metaLine = metaLine.replace(/\s+$/, '');
var match = metaLine.match(gMetaLineRegexp);
if (!match) continue;
var header = match[1];
var value = match[2] || null;
switch (header) {
case 'description':
case 'name':
case 'namespace':
case 'version':
script['_' + header] = value;
break;
case 'installURL':
header = 'downloadURL';
case 'downloadURL':
case 'updateURL':
try {
var uri = GM_util.uriFromUrl(value, aUri);
script[header] = uri.spec;
} catch (e) {
dump('Failed to parse ' + header + ' "' + value + '":\n' + e + '\n');
}
break;
case 'exclude':
script._excludes.push(value);
break;
case 'grant':
script._grants.push(value);
break;
case 'icon':
try {
script.icon.setMetaVal(value);
script._rawMeta += header + '\0' + value + '\0';
} catch (e) {
script.parseErrors.push(e.message);
}
break;
case 'include':
script._includes.push(value);
break;
case 'match':
try {
var match = new MatchPattern(value);
script._matches.push(match);
} catch (e) {
script.parseErrors.push(
gStringBundle.GetStringFromName('parse.ignoring-match')
.replace('%1', value).replace('%2', e)
);
}
break;
case 'require':
try {
var reqUri = GM_util.uriFromUrl(value, aUri);
var scriptRequire = new ScriptRequire(script);
scriptRequire._downloadURL = reqUri.spec;
script._requires.push(scriptRequire);
script._rawMeta += header + '\0' + value + '\0';
} catch (e) {
script.parseErrors.push(
gStringBundle.GetStringFromName('parse.require-failed')
.replace('%1', value)
);
}
break;
case 'resource':
var res = value.match(/(\S+)\s+(.*)/);
if (res === null) {
script.parseErrors.push(
gStringBundle.GetStringFromName('parse.resource-syntax')
.replace('%1', value)
);
break;
}
var resName = res[1];
if (resourceNames[resName]) {
script.parseErrors.push(
gStringBundle.GetStringFromName('parse.resource-duplicate')
.replace('%1', resName)
);
break;
}
resourceNames[resName] = true;
try {
var resUri = GM_util.uriFromUrl(res[2], aUri);
var scriptResource = new ScriptResource(script);
scriptResource._name = resName;
scriptResource._downloadURL = resUri.spec;
script._resources.push(scriptResource);
script._rawMeta += header + '\0' + resName + '\0' + resUri.spec + '\0';
} catch (e) {
script.parseErrors.push(
gStringBundle.GetStringFromName('parse.resource-failed')
.replace('%1', resName).replace('%2', res[2])
);
}
break;
case 'run-at':
script._runAt = value;
break;
}
}
setDefaults(script);
return script;
}
function setDefaults(script) {
if (!script.updateURL && script.downloadURL) {
script.updateURL = script.downloadURL;
}
if ('document-start' != script._runAt && 'document-end' != script._runAt) {
script._runAt = 'document-end';
}
if (script._includes.length == 0 && script._matches.length == 0) {
script._includes.push('*');
}
}
|