From 8f71c8f4d35f3af21b59439e7afb6ebf3b6ea8e8 Mon Sep 17 00:00:00 2001 From: hackademix Date: Sun, 21 Jul 2019 10:55:59 +0200 Subject: Add "Collapse blocked objects" option to the Blocked Objects prompt. --- src/_locales/en/messages.json | 2 +- src/bg/RequestGuard.js | 10 +++++++--- src/content/PlaceHolder.js | 20 ++++++++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index cce0ed5..ec5b577 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -63,7 +63,7 @@ "message": "Blocked $1 of $2 items." }, "BlockedObjects": { - "message": "NoScript Blocked Objects" + "message": "NoScript Blocked\u00A0Objects" }, "BookmarkSync": { "message": "Backup NoScript configuration in a bookmark for easy synchronization" diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js index bdf2ea2..a3631c8 100644 --- a/src/bg/RequestGuard.js +++ b/src/bg/RequestGuard.js @@ -173,7 +173,7 @@ var RequestGuard = (() => { TabStatus.recordAll(sender.tab.id, message.seen); return true; }, - async enable(message, sender) { + async blockedObjects(message, sender) { let {url, documentUrl, policyType} = message; let TAG = `<${policyType.toUpperCase()}>`; let origin = Sites.origin(url); @@ -184,7 +184,8 @@ var RequestGuard = (() => { } options = [ {label: _("allowLocal", siteKey), checked: true}, - {label: _("allowLocal", origin)} + {label: _("allowLocal", origin)}, + {label: _("CollapseBlockedObjects")}, ]; let t = u => `${TAG}@${u}`; let ret = await Prompts.prompt({ @@ -193,6 +194,9 @@ var RequestGuard = (() => { options}); debug(`Prompt returned %o`); if (ret.button !== 0) return; + if (ret.option === 2) { + return {collapse: "all"}; + } let key = [siteKey, origin][ret.option || 0]; if (!key) return; let {siteMatch, contextMatch, perms} = ns.policy.get(key, documentUrl); @@ -210,7 +214,7 @@ var RequestGuard = (() => { ns.policy.set(key, perms); await ns.savePolicy(); } - return true; + return {enable: key}; }, } const Content = { diff --git a/src/content/PlaceHolder.js b/src/content/PlaceHolder.js index a13ae37..4c860ec 100644 --- a/src/content/PlaceHolder.js +++ b/src/content/PlaceHolder.js @@ -1,10 +1,11 @@ var PlaceHolder = (() => { const HANDLERS = new Map(); - + const CLASS_NAME = "__NoScript_PlaceHolder__"; + const SELECTOR = `a.${CLASS_NAME}`; let checkStyle = async () => { checkStyle = () => {}; if (!ns.embeddingDocument) return; - let replacement = document.querySelector("a.__NoScript_PlaceHolder__"); + let replacement = document.querySelector(SELECTOR); if (!replacement) return; if (window.getComputedStyle(replacement, null).opacity !== "0.8") { document.head.appendChild(createHTMLElement("style")).textContent = await @@ -126,7 +127,7 @@ var PlaceHolder = (() => { let TYPE = `<${this.policyType.toUpperCase()}>`; let replacement = createHTMLElement("a"); - replacement.className = "__NoScript_PlaceHolder__"; + replacement.className = CLASS_NAME; cloneStyle(element, replacement); let setImage = () => replacement.style.backgroundImage = `url(${ICON_URL})`; @@ -163,13 +164,20 @@ var PlaceHolder = (() => { async enable(replacement) { debug("Enabling %o", this.request, this.policyType); - let ok = await Messages.send("enable", { + let ret = await Messages.send("blockedObjects", { url: this.request.url, policyType: this.policyType, documentUrl: document.URL }); - debug("Received response", ok); - if (!ok) return; + debug("Received response", ret); + if (!ret) return; + if (ret.collapse) { + for (let collapsing of (ret.collapse === "all" ? document.querySelectorAll(SELECTOR) : [replacement])) { + this.replacements.delete(collapsing); + collapsing.remove(); + } + return; + } if (this.request.embeddingDocument) { window.location.reload(); return; -- cgit v1.2.3