Skip to content

Commit

Permalink
https://github.com/gorhill/uBlock/commit/11ca4a39239478e35605ec072fca…
Browse files Browse the repository at this point in the history
…140ac4c70d3b
  • Loading branch information
uBlock-user authored Oct 26, 2024
1 parent dc06bc1 commit 1a609b1
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,58 +447,3 @@ function moveAttrProp(
};
runAt(( ) => { map(); }, 'interactive');
}

/// trusted-set-attr.js
/// alias tsa.js
/// dependency run-at.fn
/// world ISOLATED
// example.com##+js(tsa, selector, attr, value)
function trustedSetAttr(
selector = '',
token = '',
attrValue = ''
) {
if ( token === '' ) { return; }
const tokens = token.split(/\s*\|\s*/);
if ( selector === '' ) { selector = `[${tokens.join('],[')}]`; }
const setAttr = () => {
const nodes = document.querySelectorAll(selector);
try {
for (const node of nodes) {
for ( const attr of tokens ) {
if ( attr !== attrValue) {
node.setAttribute(attr, attrValue);
}
}
}
} catch { }
};
let observer, timer;
const onDomChanged = mutations => {
if ( timer !== undefined ) { return; }
let shouldWork = false;
for ( const mutation of mutations ) {
if ( mutation.addedNodes.length === 0 ) { continue; }
for ( const node of mutation.addedNodes ) {
if ( node.nodeType !== 1 ) { continue; }
shouldWork = true;
break;
}
if ( shouldWork ) { break; }
}
if ( shouldWork === false ) { return; }
timer = self.requestAnimationFrame(( ) => {
timer = undefined;
setAttr();
});
};
const start = ( ) => {
if ( setAttr() === false ) { return; }
observer = new MutationObserver(onDomChanged);
observer.observe(document.body, {
subtree: true,
childList: true,
});
};
runAt(( ) => { start(); }, 'interactive');
}

0 comments on commit 1a609b1

Please sign in to comment.