aboutsummaryrefslogtreecommitdiff
path: root/content/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'content/main.js')
-rw-r--r--content/main.js54
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);