Last active
April 9, 2020 13:06
-
-
Save 0xBADDCAFE/cbaaa17cd75805d32b72fa4284dc83a6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name NoAd Timeline | |
// @namespace http://0xbd.cf/ | |
// @version 0.1 | |
// @description display:none; for Ad | |
// @author 0xBADDCAFE | |
// @match https://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
const pastNodes = []; | |
function displayNoneIfAd(article){ | |
let sibling = article.querySelector("[role=group]"); | |
if (!sibling) return; | |
if (sibling.nextSibling) { | |
var parent = sibling.parentNode; | |
while (parent.tagName != "ARTICLE") { | |
parent = parent.parentNode; | |
if (!parent) return; | |
} | |
if (parent.getBoundingClientRect().top > 0) { | |
parent.style.display = "none"; | |
console.log("Dismiss Ad"); | |
console.log(parent); | |
} | |
} | |
} | |
(function() { | |
'use strict'; | |
new MutationObserver((mutationsList) => { | |
for (var mutation of mutationsList) { | |
if (mutation.type === "childList") { | |
for (var node of mutation.addedNodes) { | |
if (node.querySelectorAll) { | |
let articles = node.querySelectorAll("[data-testid^=tweet]"); | |
for (var article of articles) { | |
if (article && !pastNodes.includes(article)) { | |
pastNodes.push(article); | |
displayNoneIfAd(article); | |
} | |
} | |
} | |
} | |
} | |
} | |
}).observe( | |
document, | |
{ childList: true, subtree: true } | |
) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment