Skip to content

Commit 4775a84

Browse files
ghostery-adblocker-bot[bot]Ghostery Adblocker Bot
andauthored
Update scriptlets (#43)
Co-authored-by: Ghostery Adblocker Bot <ghostery-adblocker-bot@users.noreply.github.com>
1 parent 1a68cc9 commit 4775a84

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"type": "module",
77
"scripts": {
8-
"build": "deno build.ts --tagName 1.69.1b3 > ubo.js",
8+
"build": "deno build.ts --tagName 1.69.1b4 > ubo.js",
99
"test": "node --test"
1010
},
1111
"author": {

ubo.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,26 +1195,34 @@ function trustedCreateHTML(
11951195
const duration = parseInt(durationStr, 10);
11961196
const domParser = new DOMParser();
11971197
const externalDoc = domParser.parseFromString(htmlStr, 'text/html');
1198-
const docFragment = new DocumentFragment();
1199-
const toRemove = [];
1198+
const toAppend = [];
12001199
while ( externalDoc.body.firstChild !== null ) {
1201-
const imported = document.adoptNode(externalDoc.body.firstChild);
1202-
docFragment.appendChild(imported);
1203-
if ( isNaN(duration) ) { continue; }
1204-
toRemove.push(imported);
1200+
toAppend.push(document.adoptNode(externalDoc.body.firstChild));
12051201
}
1206-
if ( docFragment.firstChild === null ) { return; }
1202+
if ( toAppend.length === 0 ) { return; }
1203+
const toRemove = [];
12071204
const remove = ( ) => {
12081205
for ( const node of toRemove ) {
12091206
if ( node.parentNode === null ) { continue; }
12101207
node.parentNode.removeChild(node);
12111208
}
12121209
safe.uboLog(logPrefix, 'Node(s) removed');
12131210
};
1211+
const appendOne = (target, nodes) => {
1212+
for ( const node of nodes ) {
1213+
target.append(node);
1214+
if ( isNaN(duration) ) { continue; }
1215+
toRemove.push(node);
1216+
}
1217+
};
12141218
const append = ( ) => {
1215-
const parent = document.querySelector(parentSelector);
1216-
if ( parent === null ) { return false; }
1217-
parent.append(docFragment);
1219+
const targets = document.querySelectorAll(parentSelector);
1220+
if ( targets.length === 0 ) { return false; }
1221+
const limit = Math.min(targets.length, extraArgs.limit || 1) - 1;
1222+
for ( let i = 0; i < limit; i++ ) {
1223+
appendOne(targets[i], toAppend.map(a => a.cloneNode(true)));
1224+
}
1225+
appendOne(targets[limit], toAppend);
12181226
safe.uboLog(logPrefix, 'Node(s) appended');
12191227
if ( toRemove.length === 0 ) { return true; }
12201228
setTimeout(remove, duration);
@@ -20722,6 +20730,7 @@ function preventFetchFn(
2072220730
const propNeedles = parsePropertiesToMatchFn(propsToMatch, 'url');
2072320731
const validResponseProps = {
2072420732
ok: [ false, true ],
20733+
status: [ 403 ],
2072520734
statusText: [ '', 'Not Found' ],
2072620735
type: [ 'basic', 'cors', 'default', 'error', 'opaque' ],
2072720736
};
@@ -21237,6 +21246,7 @@ function preventFetchFn(
2123721246
const propNeedles = parsePropertiesToMatchFn(propsToMatch, 'url');
2123821247
const validResponseProps = {
2123921248
ok: [ false, true ],
21249+
status: [ 403 ],
2124021250
statusText: [ '', 'Not Found' ],
2124121251
type: [ 'basic', 'cors', 'default', 'error', 'opaque' ],
2124221252
};

0 commit comments

Comments
 (0)