1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-01 16:49:39 +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 = [
'(',
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,