From 8a34425ca563a1475bffed5a4d668e007adc4912 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 6 Nov 2022 17:23:06 -0500 Subject: [PATCH] Avoid redundant logger entries for scriptlet injection Report only when the scriptlets have been successfully injected. --- src/js/scriptlet-filtering.js | 38 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 9b6ba7251..f7ff31b71 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -89,36 +89,34 @@ const contentscriptCode = (( ) => { const parts = [ '(', function(hostname, scriptlets) { + const doc = document; if ( - document.location === null || - hostname !== document.location.hostname || + doc.location === null || + hostname !== doc.location.hostname || typeof self.uBO_scriptletsInjected === 'boolean' ) { return; } - const injectScriptlets = function(d) { - let script; - try { - script = d.createElement('script'); - script.appendChild(d.createTextNode( - decodeURIComponent(scriptlets)) - ); - (d.head || d.documentElement).appendChild(script); - self.uBO_scriptletsInjected = true; - } catch (ex) { - } - if ( script ) { - script.remove(); - script.textContent = ''; - } - }; - injectScriptlets(document); + let script; + try { + script = doc.createElement('script'); + script.appendChild(doc.createTextNode( + decodeURIComponent(scriptlets)) + ); + (doc.head || doc.documentElement).appendChild(script); + self.uBO_scriptletsInjected = true; + } catch (ex) { + } + if ( script ) { + script.remove(); + script.textContent = ''; + } + if ( typeof self.uBO_scriptletsInjected === 'boolean' ) { return 0; } }.toString(), ')(', '"', 'hostname-slot', '", ', '"', 'scriptlets-slot', '"', ');', - '\n0;', ]; return { parts: parts,