From 2cb91e36eed08993c0a9ca693f910b153705da65 Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 6 Aug 2018 22:34:41 +0200 Subject: Fixed regression, commit #13ea9430ff74174b0e1043119e4d855259b62a30 breaking reporting when intrinsic scripts are detected. --- main_background.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main_background.js b/main_background.js index 62ff18e..c409959 100644 --- a/main_background.js +++ b/main_background.js @@ -750,11 +750,11 @@ function license_read(script_src, name, external = false){ * Asynchronous function, returns the final edited script as a string, * or an array containing it and the index, if the latter !== -1 */ -async function get_script(response, url, tabId, whitelisted = false, index = -1) { +async function get_script(response, url, tabId = -1, whitelisted = false, index = -1) { function result(scriptSource) { return index === -1 ? scriptSource : [scriptSource, index]; } - let report = unused_data[tabId] || (unused_data[tabId] = createReport({url, tabId})); + let scriptName = url.split("/").pop(); if (whitelisted) { @@ -767,8 +767,14 @@ async function get_script(response, url, tabId, whitelisted = false, index = -1) return result(`/* LibreJS: script whitelisted by user preference. */\n${response}`); } let [verdict, editedSource, reason] = license_read(response, scriptName, index === -2); + + if (tabId < 0) { + return result(verdict ? response : editedSource); + } + let sourceHash = hash(response); let domain = get_domain(url); + let report = unused_data[tabId] || (unused_data[tabId] = createReport({url, tabId})); let blockedCount = report.blocked.length + report.blacklisted.length; dbg_print(`amt. blocked on page: ${blockedCount}`); if (blockedCount > 0 || !verdict) { @@ -1012,7 +1018,7 @@ function edit_html(html,url,tabid,wl){ // "i" is an index in html_doc.all // "j" is an index in intrinsic_events function edit_event(src,i,j,name){ - var edited = get_script(src, name, tabid); + var edited = get_script(src, name); edited.then(function(){ html_doc.all[i].attributes[intrinsic_events[j]].value = edited[0]; }); -- cgit v1.2.3