diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-07-06 18:27:38 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-07-06 18:27:38 +0200 |
commit | c86bdfcd9d56309faca69b58830cea1fa98870e0 (patch) | |
tree | aba830cbebf3a3a7a3af94c65103f14585651441 /content/main.js | |
parent | 2059fab6c01a0793e8a82f80d9518ed2bd6d1e29 (diff) | |
parent | b7e2870ff58ef85370781aa04e9e0126988e39fd (diff) | |
download | browser-extension-c86bdfcd9d56309faca69b58830cea1fa98870e0.tar.gz browser-extension-c86bdfcd9d56309faca69b58830cea1fa98870e0.zip |
Merge popup display
Diffstat (limited to 'content/main.js')
-rw-r--r-- | content/main.js | 54 |
1 files changed, 32 insertions, 22 deletions
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); |