/usr/share/xul-ext/greasemonkey/content/newscript.js is in xul-ext-greasemonkey 3.8-1~deb8u1.
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 | Components.utils.import("chrome://greasemonkey-modules/content/extractMeta.js");
Components.utils.import('chrome://greasemonkey-modules/content/parseScript.js');
Components.utils.import('chrome://greasemonkey-modules/content/prefmanager.js');
Components.utils.import('chrome://greasemonkey-modules/content/util.js');
/////////////////////////////// global variables ///////////////////////////////
var gClipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
.getService(Components.interfaces.nsIClipboard);
var gClipText = null;
var bundle = null;
////////////////////////////////// functions ///////////////////////////////////
window.addEventListener("load", function window_load() {
// init the global string bundle
bundle = document.getElementById("gm-browser-bundle");
// load default namespace from pref
document.getElementById("namespace").value =
GM_prefRoot.getValue("newscript_namespace", "");
// default the includes with the current page's url
var content = window.opener.gBrowser;
if (content) {
var messageHandler = null;
messageHandler = function (aMessage) {
window.opener.messageManager.removeMessageListener(
"greasemonkey:newscript-load-end", messageHandler);
document.getElementById("include").value = aMessage.data.href;
};
window.opener.messageManager
.addMessageListener("greasemonkey:newscript-load-end", messageHandler);
content.selectedBrowser.messageManager
.sendAsyncMessage("greasemonkey:newscript-load-start", {});
}
gClipText = getClipText();
document.documentElement.getButton('extra2').collapsed =
!(gClipText && extractMeta(gClipText));
}, false);
function doInstall() {
var scriptSrc = createScriptSource();
if (!scriptSrc) return false;
var config = GM_util.getService().config;
// Create a script object with parsed metadata, and ...
var scope = {};
Components.utils.import('chrome://greasemonkey-modules/content/parseScript.js', scope);
var script = scope.parse(scriptSrc);
// ... make sure entered details will not ruin an existing file.
if (config.installIsUpdate(script)) {
var overwrite = confirm(bundle.getString("newscript.exists"));
if (!overwrite) return false;
}
// finish making the script object ready to install
// (put this created script into a file -- only way to install it)
GM_util.installScriptFromSource(scriptSrc, function() {
// Persist namespace value.
GM_prefRoot.setValue("newscript_namespace", script.namespace);
// Now that async write is complete, close the window.
close();
});
return false;
}
function getClipText() {
var clipText = '';
try {
var transferable = Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
if ('init' in transferable) transferable.init(null);
transferable.addDataFlavor('text/unicode');
gClipboard.getData(transferable, gClipboard.kGlobalClipboard);
var str = new Object(), strLen = new Object();
transferable.getTransferData('text/unicode', str, strLen);
if (str) {
str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
clipText = str.data.substring(0, strLen.value / 2);
}
} catch (e) {
dump('Error reading clipboard:\n' + e + '\n');
}
return clipText;
}
function installFromClipboard() {
GM_util.installScriptFromSource(gClipText);
}
// assemble the XUL fields into a script template
function createScriptSource() {
var source = GM_prefRoot.getValue('newScript.template');
var removeUnused = GM_prefRoot.getValue('newScript.removeUnused');
function removeMetaLine(aMetaName) {
if (!removeUnused) return;
var re = new RegExp('^//\\s*@' + aMetaName + '.*\\n?', 'im');
source = source.replace(re, '');
}
function replaceSingleVal(aMetaName, aOptional) {
var replaceKey = '%' + aMetaName + '%';
if (-1 == source.indexOf(replaceKey)) return;
var replaceVal = document.getElementById(aMetaName).value;
if (!aOptional && !replaceVal) {
throw {
'name': 'Metadata Value Error',
'message': bundle.getString('newscript.no' + aMetaName),
};
}
if (aOptional && !replaceVal) {
removeMetaLine(aMetaName);
} else {
source = source.replace(replaceKey, replaceVal);
}
return true;
}
function replaceMultiVal(aMetaName) {
var replaceKey = '%' + aMetaName + '%';
if (-1 == source.indexOf(replaceKey)) return;
var replaceVal = document.getElementById(aMetaName).value.match(/[^\s]+/g);
if (!replaceVal || 0 == replaceVal.length) {
removeMetaLine(aMetaName);
} else {
var re = new RegExp('(.+)' + replaceKey);
var m = source.match(re);
source = source.replace(replaceKey, replaceVal.join('\n' + m[1]));
}
}
try {
replaceSingleVal('name', false);
replaceSingleVal('namespace', false);
replaceSingleVal('description', true);
replaceMultiVal('include');
replaceMultiVal('exclude');
} catch (e) {
if (e.name && e.name == 'Metadata Value Error') {
GM_util.alert(e.message);
return false;
} else {
throw e;
}
}
if (window.navigator.platform.match(/^Win/)) {
source = source.replace("\n", "\r\n");
}
return source;
}
|