Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove promotions from twitter
// ==UserScript==
// @name Unpromote Twitter
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author James Cuénod
// @match https://twitter.com/home
// @grant none
// ==/UserScript==
(function() {
'use strict';
const clearPromotions = () => {
const articles = document.querySelectorAll("article")
articles.forEach(a => {
const hasPromotedDiv = Array.from(a.querySelectorAll("div")).filter(d => d.textContent == "Promoted").length > 0
if (hasPromotedDiv) {
a.remove()
}
})
}
const throttled = (delay, fn) => {
let lastCall = 0;
return function (...args) {
const now = (new Date).getTime();
if (now - lastCall < delay) {
return;
}
lastCall = now;
return fn(...args);
}
}
document.addEventListener("scroll", throttled(200, clearPromotions))
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment