Last active
January 15, 2019 15:39
-
-
Save RobinDev/612a29a2ec24b631c3b19ba0f7c7b686 to your computer and use it in GitHub Desktop.
Twitter Personalization : Remove Sidebar and Ads
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
// Share for educationnal purpose only | |
// -------------------- | |
// To remove ads or sidebar from twitter, just inject this code (via cjs for example) : | |
// Current code work for the new Twitter TL from you favorite navigator (january 2019) | |
// -------------------- | |
function removeSidebar() { | |
var elem = document.querySelector('[data-testid=sidebarColumn]'); | |
if (elem) elem.parentNode.removeChild(elem); | |
} | |
function hidePromotedTweets() { | |
var a = "//div[text()='Promoted']"; | |
var b = document.evaluate(a, document, null, XPathResult.ANY_TYPE, null); | |
while (node = b.iterateNext()) { | |
var e = node.closest("article[role=article]") | |
if (e) e.parentNode.removeChild(e); | |
} | |
} | |
setTimeout(function() { | |
hidePromotedTweets(); | |
removeSidebar(); | |
}, 1000); | |
document.addEventListener("click", function() { | |
hidePromotedTweets(); | |
removeSidebar(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment