1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Add remove-class scriptlet (alias: rc)

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/935

Arguments are similar to that of remove-attr
scriptlet.
This commit is contained in:
Raymond Hill 2020-03-18 09:44:18 -04:00
parent 2af198d959
commit 49d9929191
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -458,6 +458,37 @@
})();
/// remove-class.js
/// alias rc.js
(function() {
const token = '{{1}}';
if ( token === '' || token === '{{1}}' ) { return; }
const tokens = token.split(/\s*\|\s*/);
let selector = '{{2}}';
if ( selector === '' || selector === '{{2}}' ) {
selector = '.' + tokens.map(a => CSS.escape(a)).join(',.');
}
const rmclass = function() {
try {
const nodes = document.querySelectorAll(selector);
for ( const node of nodes ) {
node.classList.remove(...tokens);
}
} catch(ex) {
}
};
if ( document.readyState === 'loading' ) {
window.addEventListener(
'DOMContentLoaded',
rmclass,
{ capture: true, once: true }
);
} else {
rmclass();
}
})();
/// requestAnimationFrame-if.js
/// alias raf-if.js
(function() {