diff options
author | Ruben Rodriguez <ruben@gnu.org> | 2015-11-28 15:24:36 -0600 |
---|---|---|
committer | Ruben Rodriguez <ruben@gnu.org> | 2015-11-28 16:27:06 -0600 |
commit | e4a3586a14996bbece3b26c9e3b7704ea6af8615 (patch) | |
tree | 499bdd16b3a90c30b01e4b47a5882d13b4800f50 /data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scriptish/userscript-manager.js | |
parent | 4dbc2fae927bb02ef243c87938e638af9afee8fa (diff) |
LibreJS upgraded to 6.0.10
Diffstat (limited to 'data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scriptish/userscript-manager.js')
-rw-r--r-- | data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scriptish/userscript-manager.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scriptish/userscript-manager.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scriptish/userscript-manager.js new file mode 100644 index 0000000..f1eec70 --- /dev/null +++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/node_modules/pathfinder/lib/scriptish/userscript-manager.js @@ -0,0 +1,44 @@ +'use strict'; + +var { Services } = require("../chrome/services"); +var obs = require("sdk/deprecated/observer-service"); + +var sandboxFactory = require("./userscript-sandbox"); + +var userscripts = []; + +// TODO: register obs only when there is a userscript +obs.add("content-document-global-created", docReady); +obs.add("chrome-document-global-created", docReady); + +function docReady(safeWin, data) { + let href = (safeWin.location.href + || (safeWin.frameElement && safeWin.frameElement.src)) || ""; + + safeWin.addEventListener("load", function() { + userscripts.forEach(function(script) { + // check that the userscript should be run on this page + if (!script.matchesURL(href)) + return; + + sandboxFactory.evalInSandbox( + script._source, + sandboxFactory.createSandbox(safeWin, script, href), + script.jsversion); + }); + }, true); +} + +exports.register = function(aScript) { + unregister(aScript); + userscripts.push(aScript); +}; + +var unregister = exports.unregister = function unregister(aScript) { + for (var i = userscripts.length - 1; ~i; i--) { + if (userscripts[i] == aScript) { + userscripts.splice(i, 1); + break; + } + } +}; |