From 9353f7145523864e9b554ad95fc5915869453a88 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 23 Jan 2020 15:23:56 +0100 Subject: [PATCH] Added notice for privacy.resistFingerprinting Fixes #427 --- _locales/de/messages.json | 6 +++++- _locales/en/messages.json | 4 ++++ lib/extension.js | 32 ++++++++++++++++++++++++++++++++ manifest.json | 3 ++- options/options.css | 6 ++++++ options/options.js | 23 +++++++++++++++++++++++ options/presets.js | 27 +-------------------------- 7 files changed, 73 insertions(+), 28 deletions(-) diff --git a/_locales/de/messages.json b/_locales/de/messages.json index 545a670..0370d33 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -83,6 +83,10 @@ "message": "Bei Aktualisierung nicht wieder anzeigen.", "description": "" }, + "resistFingerprintingNotice": { + "message": "Sie haben privacy.resistFingerprinting aktiviert. Dies verändert das Verhalten von CanvasBlocker ein wenig. Weitere Informationen finden Sie {link:hier:https://github.com/kkapsner/CanvasBlocker/issues/158} und {link:hier:https://github.com/ghacksuserjs/ghacks-user.js/issues/767}.", + "description": "" + }, "openInTab": { "message": "In separatem Tab öffnen", "description": "" @@ -1543,4 +1547,4 @@ "message": "Der window-API-Schutz macht reCAPTCHA unbenutzbar. Diese Voreinstellung erlaubt die Benutzung der window.name-API in eingebetteten Seiten. Dadurch funktioniert es wieder.", "description": "" } -} +} \ No newline at end of file diff --git a/_locales/en/messages.json b/_locales/en/messages.json index f2e21f5..03a5eef 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -88,6 +88,10 @@ "message": "Don't show up again after update.", "description": "" }, + "resistFingerprintingNotice": { + "message": "You have privacy.resistFingerprinting enabled. This slightly changes the behaviour of CanvasBlocker. See further information {link:here:https://github.com/kkapsner/CanvasBlocker/issues/158} and {link:here:https://github.com/ghacksuserjs/ghacks-user.js/issues/767}.", + "description": "" + }, "openInTab": { "message": "Open in separate tab", "description": "" diff --git a/lib/extension.js b/lib/extension.js index 0f017bf..e0df229 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -27,6 +27,38 @@ return id; }; + scope.parseTranslation = function parseTranslation(message){ + const container = document.createDocumentFragment(); + + message.split(/(\{[^}]+\})/).forEach(function(part){ + if (part.startsWith("{") && part.endsWith("}")){ + part = part.substring(1, part.length - 1); + const args = part.split(":"); + switch (args[0]){ + case "image": { + const image = document.createElement("img"); + image.className = "noticeImage"; + image.src = args.slice(1).join(":"); + container.appendChild(image); + break; + } + case "link": { + const link = document.createElement("a"); + link.target = "_blank"; + link.textContent = args[1]; + link.href = args.slice(2).join(":"); + container.appendChild(link); + break; + } + } + } + else { + container.appendChild(document.createTextNode(part)); + } + }); + return container; + }; + scope.extensionID = browserAvailable? browser.extension.getURL(""): "extensionID"; scope.inIncognitoContext = browserAvailable? browser.extension.inIncognitoContext: false; diff --git a/manifest.json b/manifest.json index 7955b07..24323e6 100644 --- a/manifest.json +++ b/manifest.json @@ -91,7 +91,8 @@ "webRequest", "webRequestBlocking", "contextualIdentities", - "cookies" + "cookies", + "privacy" ], "applications": { diff --git a/options/options.css b/options/options.css index 5a469b8..0618009 100644 --- a/options/options.css +++ b/options/options.css @@ -37,6 +37,12 @@ header .bookmarkNotice .dontShowOptionsOnUpdate input { vertical-align: sub; } +.resistFingerprintingNotice { + margin: 0.5em 0; + padding: 0.5em; + border: 1px solid var(--input-error-background-color); +} + .settings { width: 100%; border-spacing: 0; diff --git a/options/options.js b/options/options.js index 0688db3..464e48e 100644 --- a/options/options.js +++ b/options/options.js @@ -228,6 +228,29 @@ groupTabs.classList = "groupTabs"; document.body.appendChild(groupTabs); + if ( + browser.privacy && + browser.privacy.websites && + browser.privacy.websites.resistFingerprinting && + browser.privacy.websites.resistFingerprinting.get + ){ + browser.privacy.websites.resistFingerprinting.get({}).then(function({value}){ + if (value){ + const rfpNotice = document.createElement("div"); + rfpNotice.className = "resistFingerprintingNotice"; + rfpNotice.appendChild( + extension.parseTranslation( + extension.getTranslation("resistFingerprintingNotice") + ) + ); + document.body.insertBefore(rfpNotice, groupTabs); + } + return undefined; + }).catch(function(error){ + logging.warning("Unable to read resistFingerprinting:", error); + }); + } + const groups = document.createElement("ul"); groups.className = "groups"; groupTabs.appendChild(groups); diff --git a/options/presets.js b/options/presets.js index 092acda..04f2b05 100644 --- a/options/presets.js +++ b/options/presets.js @@ -141,32 +141,7 @@ if (noticeText){ const notice = document.createElement("div"); notice.className = noticeName + " notice"; - noticeText.split(/(\{[^}]+\})/).forEach(function(part){ - if (part.startsWith("{") && part.endsWith("}")){ - part = part.substring(1, part.length - 1); - const args = part.split(":"); - switch (args[0]){ - case "image": { - const image = document.createElement("img"); - image.className = "noticeImage"; - image.src = args[1]; - notice.appendChild(image); - break; - } - case "link": { - const link = document.createElement("a"); - link.target = "_blank"; - link.textContent = args[1]; - link.href = args[2]; - notice.appendChild(link); - break; - } - } - } - else { - notice.appendChild(document.createTextNode(part)); - } - }); + notice.appendChild(extension.parseTranslation(noticeText)); head.appendChild(notice); }