1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-14 23:12:28 +02:00

Avoid redundant logger entries for scriptlet injection

Report only when the scriptlets have been successfully injected.
This commit is contained in:
Raymond Hill 2022-11-06 17:23:06 -05:00
parent 47cb7baff0
commit 8a34425ca5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -89,36 +89,34 @@ const contentscriptCode = (( ) => {
const parts = [ const parts = [
'(', '(',
function(hostname, scriptlets) { function(hostname, scriptlets) {
const doc = document;
if ( if (
document.location === null || doc.location === null ||
hostname !== document.location.hostname || hostname !== doc.location.hostname ||
typeof self.uBO_scriptletsInjected === 'boolean' typeof self.uBO_scriptletsInjected === 'boolean'
) { ) {
return; return;
} }
const injectScriptlets = function(d) { let script;
let script; try {
try { script = doc.createElement('script');
script = d.createElement('script'); script.appendChild(doc.createTextNode(
script.appendChild(d.createTextNode( decodeURIComponent(scriptlets))
decodeURIComponent(scriptlets)) );
); (doc.head || doc.documentElement).appendChild(script);
(d.head || d.documentElement).appendChild(script); self.uBO_scriptletsInjected = true;
self.uBO_scriptletsInjected = true; } catch (ex) {
} catch (ex) { }
} if ( script ) {
if ( script ) { script.remove();
script.remove(); script.textContent = '';
script.textContent = ''; }
} if ( typeof self.uBO_scriptletsInjected === 'boolean' ) { return 0; }
};
injectScriptlets(document);
}.toString(), }.toString(),
')(', ')(',
'"', 'hostname-slot', '", ', '"', 'hostname-slot', '", ',
'"', 'scriptlets-slot', '"', '"', 'scriptlets-slot', '"',
');', ');',
'\n0;',
]; ];
return { return {
parts: parts, parts: parts,