Last active
September 25, 2018 18:12
-
-
Save jcuenod/6950b98fd06eee3960e50875b6fb08e5 to your computer and use it in GitHub Desktop.
Remove promotions from twitter
This file contains 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
// ==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