nuggies-public/BraveScriptlets/fuck-twitter-promote-buttons.js

27 lines
841 B
JavaScript
Raw Permalink Normal View History

// Add this line to "Create Custom Filters" box:
// x.com##+js(fuck-twitter-promote-buttons.js)
const callback = (mutationList, observer) => {
const walker = document.createTreeWalker(
document.documentElement,
NodeFilter.SHOW_TEXT, null, false);
let node;
while (node = walker.nextNode()) {
if (node.nodeValue.includes("Promote")) {
let ancestor = node.parentNode;
while (ancestor && ancestor.tagName !== 'A') {
ancestor = ancestor.parentNode;
}
if (ancestor && ancestor.tagName === 'A') {
ancestor.remove();
}
}
}
}
const targetNode = document.documentElement;
const observer = new MutationObserver(callback);
observer.observe(targetNode, { attributes: false, childList: true, subtree: true });