Skip to content

Instantly share code, notes, and snippets.

@0xBADDCAFE
Last active April 9, 2020 13:06
Show Gist options
  • Save 0xBADDCAFE/cbaaa17cd75805d32b72fa4284dc83a6 to your computer and use it in GitHub Desktop.
Save 0xBADDCAFE/cbaaa17cd75805d32b72fa4284dc83a6 to your computer and use it in GitHub Desktop.
// ==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