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/PlaceHolder.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/PlaceHolder.js')
-rw-r--r-- | src/content/PlaceHolder.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/content/PlaceHolder.js b/src/content/PlaceHolder.js index f32c812..ac4dc14 100644 --- a/src/content/PlaceHolder.js +++ b/src/content/PlaceHolder.js @@ -1,6 +1,6 @@ var PlaceHolder = (() => { const HANDLERS = new Map(); - + let checkStyle = async () => { checkStyle = () => {}; if (!ns.embeddingDocument) return; @@ -11,7 +11,7 @@ var PlaceHolder = (() => { (await fetch(browser.extension.getURL("/content/content.css"))).text(); } } - + class Handler { constructor(type, selector) { this.type = type; @@ -20,10 +20,16 @@ var PlaceHolder = (() => { HANDLERS.set(type, this); } filter(element, request) { - if (request.embeddingDocument) return true; + if (request.embeddingDocument) { + return document.URL === request.url; + } let url = request.initialUrl || request.url; return "data" in element ? element.data === url : element.src === url; } + selectFor(request) { + return [...document.querySelectorAll(this.selector)] + .filter(element => this.filter(element, request)) + } } new Handler("frame", "iframe"); @@ -59,6 +65,9 @@ var PlaceHolder = (() => { static canReplace(policyType) { return HANDLERS.has(policyType); } + static handlerFor(policyType) { + return HANDLERS.get(policyType); + } static listen() { PlaceHolder.listen = () => {}; @@ -83,7 +92,7 @@ var PlaceHolder = (() => { this.policyType = policyType; this.request = request; this.replacements = new Set(); - this.handler = HANDLERS.get(policyType); + this.handler = PlaceHolder.handlerFor(policyType); if (this.handler) { [...document.querySelectorAll(this.handler.selector)] .filter(element => this.handler.filter(element, request)) @@ -100,7 +109,11 @@ var PlaceHolder = (() => { let { url } = this.request; - this.origin = new URL(url).origin; + let objUrl = new URL(url) + this.origin = objUrl.origin; + if (this.origin === "null") { + this.origin = objUrl.protocol; + } let TYPE = `<${this.policyType.toUpperCase()}>`; let replacement = createHTMLElement("a"); @@ -129,7 +142,7 @@ var PlaceHolder = (() => { replacement._placeHolderObj = this; replacement._placeHolderElement = element; - + element.parentNode.replaceChild(replacement, element); this.replacements.add(replacement); |