aboutsummaryrefslogtreecommitdiff
path: root/main_background.js
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@fsf.org>2018-10-31 14:05:26 -0400
committerRuben Rodriguez <ruben@fsf.org>2018-10-31 14:05:26 -0400
commit82ad83dd6fb74ff26d41c57332bb8d0df37c408d (patch)
tree8f5d771a0517b288c5957dbdda49a6a7b6dd7703 /main_background.js
parent93578165ff522bca4f8ee031e43a363f7f2ecc01 (diff)
Correctly handle multiple inline scripts, multiple intrinsic events, whitelisting/blacklisting and listing in the panel.
Before this, only the first inline script would get properly handled. This also corrects script comments for href="javascript:foo" types of scripts, which cannot get comments added in to state the result of LibreJS parsing.
Diffstat (limited to 'main_background.js')
-rw-r--r--main_background.js35
1 files changed, 26 insertions, 9 deletions
diff --git a/main_background.js b/main_background.js
index 0b6e407..06fd6cb 100644
--- a/main_background.js
+++ b/main_background.js
@@ -676,7 +676,10 @@ function license_read(scriptSrc, name, external = false){
editedSrc += s;
} else {
partsDenied = true;
- editedSrc += `\n/*\nLIBREJS BLOCKED: ${message}\n*/\n`;
+ if (s.startsWith("javascript:"))
+ editedSrc += `# LIBREJS BLOCKED: ${message}`;
+ else
+ editedSrc += `/*\nLIBREJS BLOCKED: ${message}\n*/`;
}
reason += `\n${message}`;
return trivial;
@@ -756,7 +759,10 @@ async function get_script(response, url, tabId = -1, whitelisted = false, index
: "Address whitelisted by user";
addReportEntry(tabId, url, {"whitelisted": [url, reason], url});
}
- return result(`/* LibreJS: script whitelisted by user preference. */\n${response}`);
+ if (response.startsWith("javascript:"))
+ return result(response);
+ else
+ return result(`/* LibreJS: script whitelisted by user preference. */\n${response}`);
}
let [verdict, editedSource, reason] = license_read(response, scriptName, index === -2);
@@ -773,10 +779,20 @@ async function get_script(response, url, tabId = -1, whitelisted = false, index
let scriptSource = verdict ? response : editedSource;
switch(category) {
case "blacklisted":
+ if (response.startsWith("javascript:"))
+ return result(`# LibreJS: script ${category} by user.`);
+ else
+ return result(`/* LibreJS: script ${category} by user. */`);
case "whitelisted":
- return result(`/* LibreJS: script ${category} by user. */\n${scriptSource}`);
+ if (response.startsWith("javascript:"))
+ return result(scriptSource);
+ else
+ return result(`/* LibreJS: script ${category} by user. */\n${scriptSource}`);
default:
- return result(`/* LibreJS: script ${category}. */\n${scriptSource}`);
+ if (response.startsWith("javascript:"))
+ return result(scriptSource);
+ else
+ return result(`/* LibreJS: script ${category}. */\n${scriptSource}`);
}
}
@@ -1061,6 +1077,7 @@ async function editHtml(html, documentUrl, tabId, frameId, whitelisted){
let modifiedInline = false;
for(let i = 0, len = scripts.length; i < len; i++) {
let script = scripts[i];
+ let url = `${documentUrl}# script ${i}`;
if (!script.src && !(script.type && script.type !== "text/javascript")) {
let edited = await get_script(script.textContent, url, tabId, whitelisted, i);
if (edited) {
@@ -1072,11 +1089,11 @@ async function editHtml(html, documentUrl, tabId, frameId, whitelisted){
}
}
}
- if (modified) {
- return modifiedInline
- ? await remove_noscripts(html_doc)
- : doc2HTML(html_doc);
- }
+ }
+ if (modified) {
+ return modifiedInline
+ ? await remove_noscripts(html_doc)
+ : doc2HTML(html_doc);
}
}
return null;