Revision b7e2870f
Added by koszko about 2 years ago
content/main.js | ||
---|---|---|
12 | 12 |
* IMPORT url_extract_target |
13 | 13 |
* IMPORT gen_unique |
14 | 14 |
* IMPORT csp_rule |
15 |
* IMPORT is_privileged_url |
|
15 | 16 |
* IMPORT sanitize_attributes |
16 | 17 |
* IMPORT script_suppressor |
17 | 18 |
* IMPORT is_chrome |
18 | 19 |
* IMPORT is_mozilla |
20 |
* IMPORT start_activity_info_server |
|
19 | 21 |
* IMPORTS_END |
20 | 22 |
*/ |
21 | 23 |
|
... | ... | |
35 | 37 |
|
36 | 38 |
const suppressor = script_suppressor(unique); |
37 | 39 |
|
38 |
function needs_blocking() |
|
40 |
|
|
41 |
function is_http() |
|
39 | 42 |
{ |
40 |
if (url.startsWith("https://") || url.startsWith("http://"))
|
|
41 |
return false;
|
|
43 |
return !!/^https?:\/\//i.exec(document.URL);
|
|
44 |
}
|
|
42 | 45 |
|
46 |
function is_whitelisted() |
|
47 |
{ |
|
43 | 48 |
const parsed_url = url_extract_target(document.URL); |
44 | 49 |
|
45 | 50 |
if (parsed_url.target !== undefined && |
... | ... | |
49 | 54 |
else |
50 | 55 |
history.replaceState(null, "", parsed_url.base_url); |
51 | 56 |
|
52 |
console.log(["allowing whitelisted", document.URL]); |
|
53 |
return false; |
|
57 |
return true; |
|
54 | 58 |
} |
55 | 59 |
|
56 |
console.log(["disallowing", document.URL]); |
|
57 |
return true; |
|
60 |
return false; |
|
58 | 61 |
} |
59 | 62 |
|
60 | 63 |
function handle_mutation(mutations, observer) |
... | ... | |
120 | 123 |
head.insertBefore(meta, head.firstElementChild); |
121 | 124 |
} |
122 | 125 |
|
123 |
if (needs_blocking()) { |
|
124 |
block_nodes_recursively(document.documentElement); |
|
125 |
|
|
126 |
if (is_chrome) { |
|
127 |
var observer = new MutationObserver(handle_mutation); |
|
128 |
observer.observe(document.documentElement, { |
|
129 |
attributes: true, |
|
130 |
childList: true, |
|
131 |
subtree: true |
|
132 |
}); |
|
126 |
if (!is_privileged_url(document.URL)) { |
|
127 |
start_activity_info_server(); |
|
128 |
handle_page_actions(unique); |
|
129 |
|
|
130 |
if (is_http()) { |
|
131 |
/* rely on CSP injected through webRequest */ |
|
132 |
} else if (is_whitelisted()) { |
|
133 |
/* do not block scripts at all */ |
|
134 |
} else { |
|
135 |
block_nodes_recursively(document.documentElement); |
|
136 |
|
|
137 |
if (is_chrome) { |
|
138 |
var observer = new MutationObserver(handle_mutation); |
|
139 |
observer.observe(document.documentElement, { |
|
140 |
attributes: true, |
|
141 |
childList: true, |
|
142 |
subtree: true |
|
143 |
}); |
|
144 |
} |
|
145 |
|
|
146 |
if (is_mozilla) |
|
147 |
addEventListener('beforescriptexecute', suppressor, true); |
|
133 | 148 |
} |
134 |
|
|
135 |
if (is_mozilla) |
|
136 |
addEventListener('beforescriptexecute', suppressor, true); |
|
137 | 149 |
} |
138 |
|
|
139 |
handle_page_actions(unique); |
Also available in: Unified diff
show some settings of the current page in the popup