Skip to content

Instantly share code, notes, and snippets.

@RobinDev
Last active January 15, 2019 15:39
Show Gist options
  • Save RobinDev/612a29a2ec24b631c3b19ba0f7c7b686 to your computer and use it in GitHub Desktop.
Save RobinDev/612a29a2ec24b631c3b19ba0f7c7b686 to your computer and use it in GitHub Desktop.
Twitter Personalization : Remove Sidebar and Ads
// 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