Created
November 11, 2023 20:58
-
-
Save lylejantzi3rd/a2e2104406b56986c82833e753880675 to your computer and use it in GitHub Desktop.
Block ads on Twitter as they appear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const targetNode = document.querySelector('div[aria-label*="Timeline: Conversation"]') | |
const config = { attributes: false, childList: true, subtree: true } | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
const callback = (mutationList, observer) => { | |
// We don't care what was mutated. The Xpath has to run at the document level anyway | |
const foundElement = getElementByXpath("//span[contains (text(), 'Ad')]//ancestor::article") | |
if (foundElement) { | |
foundElement.style.display = 'none' | |
console.log("AD REMOVED") | |
} | |
} | |
const observer = new MutationObserver(callback) | |
observer.observe(targetNode, config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment