Skip to content

Instantly share code, notes, and snippets.

@jcuenod
Last active September 25, 2018 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcuenod/6950b98fd06eee3960e50875b6fb08e5 to your computer and use it in GitHub Desktop.
Save jcuenod/6950b98fd06eee3960e50875b6fb08e5 to your computer and use it in GitHub Desktop.
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