Skip to content

Commit

Permalink
Add remove-class scriptlet (alias: rc)
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#935

Arguments are similar to that of remove-attr
scriptlet.
  • Loading branch information
gorhill committed Mar 18, 2020
1 parent 2af198d commit 49d9929
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 49d9929

Please sign in to comment.