diff options
author | hackademix | 2018-09-03 19:20:39 +0200 |
---|---|---|
committer | hackademix | 2018-09-04 00:22:39 +0200 |
commit | 81ac052e1d1b0db924c9ef14a90bf22ce1dc4d8b (patch) | |
tree | 8e3f904e4cec2c0c8f6132dc0760994baae9fa65 /src/content/content.js | |
parent | 16cdbbe1cb7402ed795923128a4bc7bfb4415f1e (diff) | |
download | noscript-81ac052e1d1b0db924c9ef14a90bf22ce1dc4d8b.tar.gz noscript-81ac052e1d1b0db924c9ef14a90bf22ce1dc4d8b.tar.xz noscript-81ac052e1d1b0db924c9ef14a90bf22ce1dc4d8b.zip |
Better file: protocol support.
Diffstat (limited to 'src/content/content.js')
-rw-r--r-- | src/content/content.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/content/content.js b/src/content/content.js index e73feb6..fb68ae4 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -1,6 +1,5 @@ 'use strict'; // debug = () => {}; // REL_ONLY - var _ = browser.i18n.getMessage; function createHTMLElement(name) { @@ -50,7 +49,7 @@ var notifyPage = async () => { if (document.readyState === "complete") { try { if (!("canScript" in ns)) { - let childPolicy = await Messages.send("fetchChildPolicy", {url: document.URL, contextUrl: top.location.href}); + let childPolicy = await Messages.send("fetchChildPolicy", {url: document.URL}); ns.config.CURRENT = childPolicy.CURRENT; ns.setup(childPolicy.DEFAULT, childPolicy.MARKER); return; @@ -82,11 +81,22 @@ ns.on("capabilities", () => { }, allowed: ns.canScript }); - - if (!ns.canScript) { + if (!ns.canScript) { + addEventListener("beforescriptexecute", e => e.preventDefault()); + let mo = new MutationObserver(mutations => { + for (let m of mutations) { + console.log(`Mutation `, m); + if (m.type !== "attribute") continue; + if (/^on\w+/i.test(m.attributeName)) { + m.target.removeAttribute(m.attributeName); + } else if (/^\s*(javascript|data):/i.test(m.target.attributes[m.attributeName])) { + m.target.setAttribute(m.attributeName, "#"); + } + } + }); + // mo.observe(document.documentElement, {attributes: true, subtree: true}); if ("serviceWorker" in navigator && navigator.serviceWorker.controller) { - addEventListener("beforescriptexecute", e => e.preventDefault()); (async () => { for (let r of await navigator.serviceWorker.getRegistrations()) { await r.unregister(); @@ -97,6 +107,6 @@ ns.on("capabilities", () => { if (document.readyState !== "loading") onScriptDisabled(); window.addEventListener("DOMContentLoaded", onScriptDisabled); } - + notifyPage(); }); |