mirror of https://github.com/gorhill/uBlock.git
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:
parent
2af198d959
commit
49d9929191
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue