From b849b8d461479cf6530c77b97b094807840ce0d7 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 12 Oct 2022 19:11:20 +1100 Subject: adding force display noscript. --- content/noscript.js | 38 +++++++++++++++++++++++++++ html/display_panel/content/display-panel.html | 1 + html/display_panel/content/main_panel.js | 13 ++++++--- manifest.json | 3 ++- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 content/noscript.js diff --git a/content/noscript.js b/content/noscript.js new file mode 100644 index 0000000..9ea2f08 --- /dev/null +++ b/content/noscript.js @@ -0,0 +1,38 @@ +/** +* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript. +* +* Copyright (C) 2022 Yuchen Pei +* +* This file is part of GNU LibreJS. +* +* GNU LibreJS is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GNU LibreJS is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GNU LibreJS. If not, see . +*/ +"use strict"; +{ + browser.runtime.onMessage.addListener(async m => { + if (m.action === 'forceNoscript') { + try { + debug("Received message", m); + for (const noscript of document.querySelectorAll( + 'noscript:not([data-librejs-nodisplay])')) { + const replacement = document.createElement('span'); + replacement.innerHTML = noscript.innerHTML; + noscript.replaceWith(replacement); + } + } catch (e) { + console.error(e); + } + } + }); +} diff --git a/html/display_panel/content/display-panel.html b/html/display_panel/content/display-panel.html index 7d1fdf5..5d99e19 100644 --- a/html/display_panel/content/display-panel.html +++ b/html/display_panel/content/display-panel.html @@ -53,6 +53,7 @@ + diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js index 7a5e2c3..dc3ee2d 100644 --- a/html/display_panel/content/main_panel.js +++ b/html/display_panel/content/main_panel.js @@ -83,17 +83,24 @@ document.querySelector("#info").addEventListener("click", e => { myPort.postMessage({ [action]: entry, site, tabId: currentReport.tabId }); }); -document.querySelector("#report-tab").onclick = e => { +document.querySelector("#report-tab").onclick = _ => { myPort.postMessage({ report_tab: currentReport }); close(); } -document.querySelector("#complain").onclick = e => { +document.querySelector("#complain").onclick = _ => { myPort.postMessage({ invoke_contact_finder: currentReport }); close(); } -document.querySelector("#open-options").onclick = e => { +document.querySelector("#force-noscript").onclick = async _ => { + await browser.tabs.sendMessage(currentReport.tabId, { + action: 'forceNoscript' + }); + document.querySelector("#force-noscript").disabled = true; +} + +document.querySelector("#open-options").onclick = _ => { browser.runtime.openOptionsPage(); close(); } diff --git a/manifest.json b/manifest.json index 2a7a5f1..0c8c28d 100644 --- a/manifest.json +++ b/manifest.json @@ -54,7 +54,8 @@ "match_about_blank": true, "all_frames": true, "js": [ - "content/externalLicenseChecker.js" + "content/externalLicenseChecker.js", + "content/noscript.js" ] } ] -- cgit v1.2.3