From 55c748d6a50af4e93b138bf73e37c71f946fab19 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 13 Oct 2022 11:50:15 +1100 Subject: minor fix of noscript.js, and make it show up in console debugger --- content/noscript.js | 20 ++++++++++++-------- html/display_panel/content/main_panel.js | 4 ++-- main_background.js | 4 +++- test/spec/LibreJSSpec.js | 12 ++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/content/noscript.js b/content/noscript.js index 9ea2f08..9cf1ac1 100644 --- a/content/noscript.js +++ b/content/noscript.js @@ -20,16 +20,20 @@ */ "use strict"; { - browser.runtime.onMessage.addListener(async m => { + const showNoScript = () => { + for (const noscript of document.querySelectorAll( + 'noscript:not([data-librejs-nodisplay])')) { + const replacement = document.createElement('span'); + replacement.innerHTML = noscript.innerHTML; + noscript.replaceWith(replacement); + } + }; + + browser.runtime.onMessage.addListener(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); - } + console.log("Received message", m); + showNoScript(); } catch (e) { console.error(e); } diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js index dc3ee2d..e2988d6 100644 --- a/html/display_panel/content/main_panel.js +++ b/html/display_panel/content/main_panel.js @@ -93,8 +93,8 @@ document.querySelector("#complain").onclick = _ => { close(); } -document.querySelector("#force-noscript").onclick = async _ => { - await browser.tabs.sendMessage(currentReport.tabId, { +document.querySelector("#force-noscript").onclick = _ => { + browser.tabs.sendMessage(currentReport.tabId, { action: 'forceNoscript' }); document.querySelector("#force-noscript").disabled = true; diff --git a/main_background.js b/main_background.js index 87b80ae..ab70d00 100644 --- a/main_background.js +++ b/main_background.js @@ -891,7 +891,9 @@ async function initAddon() { editHtml, handleScript, ExternalLicenses, - ListManager, ListStore, Storage, + ListManager, + ListStore, + Storage }; // create or focus the autotest tab if it's a debugging session if ((await browser.management.getSelf()).installType === 'development') { diff --git a/test/spec/LibreJSSpec.js b/test/spec/LibreJSSpec.js index 7828bcb..70ec339 100644 --- a/test/spec/LibreJSSpec.js +++ b/test/spec/LibreJSSpec.js @@ -257,6 +257,18 @@ describe('LibreJS\' components', () => { }); }); + describe('FIXME: dummy test to get noscript.js displayed in the console debugger', () => { + beforeAll(async () => { + await browser.tabs.executeScript(tab.id, { + file: '/content/noscript.js' + }); + }); + + it('IGNORE ME', () => { + expect(1).toBe(1); + }); + }); + describe('The external (Web Labels) license checker', () => { let { ExternalLicenses } = LibreJS; let check; -- cgit v1.2.3