From b7e2870ff58ef85370781aa04e9e0126988e39fd Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 6 Jul 2021 18:25:34 +0200 Subject: show some settings of the current page in the popup --- content/main.js | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'content/main.js') diff --git a/content/main.js b/content/main.js index 65ac008..5d88a6d 100644 --- a/content/main.js +++ b/content/main.js @@ -12,10 +12,12 @@ * IMPORT url_extract_target * IMPORT gen_unique * IMPORT csp_rule + * IMPORT is_privileged_url * IMPORT sanitize_attributes * IMPORT script_suppressor * IMPORT is_chrome * IMPORT is_mozilla + * IMPORT start_activity_info_server * IMPORTS_END */ @@ -35,11 +37,14 @@ let unique = gen_unique(url); const suppressor = script_suppressor(unique); -function needs_blocking() + +function is_http() { - if (url.startsWith("https://") || url.startsWith("http://")) - return false; + return !!/^https?:\/\//i.exec(document.URL); +} +function is_whitelisted() +{ const parsed_url = url_extract_target(document.URL); if (parsed_url.target !== undefined && @@ -49,12 +54,10 @@ function needs_blocking() else history.replaceState(null, "", parsed_url.base_url); - console.log(["allowing whitelisted", document.URL]); - return false; + return true; } - console.log(["disallowing", document.URL]); - return true; + return false; } function handle_mutation(mutations, observer) @@ -120,20 +123,27 @@ function inject_csp(head) head.insertBefore(meta, head.firstElementChild); } -if (needs_blocking()) { - block_nodes_recursively(document.documentElement); - - if (is_chrome) { - var observer = new MutationObserver(handle_mutation); - observer.observe(document.documentElement, { - attributes: true, - childList: true, - subtree: true - }); +if (!is_privileged_url(document.URL)) { + start_activity_info_server(); + handle_page_actions(unique); + + if (is_http()) { + /* rely on CSP injected through webRequest */ + } else if (is_whitelisted()) { + /* do not block scripts at all */ + } else { + block_nodes_recursively(document.documentElement); + + if (is_chrome) { + var observer = new MutationObserver(handle_mutation); + observer.observe(document.documentElement, { + attributes: true, + childList: true, + subtree: true + }); + } + + if (is_mozilla) + addEventListener('beforescriptexecute', suppressor, true); } - - if (is_mozilla) - addEventListener('beforescriptexecute', suppressor, true); } - -handle_page_actions(unique); -- cgit v1.2.3