Skip to content

Instantly share code, notes, and snippets.

@ToadKing
Created September 1, 2015 01:44
Show Gist options
  • Select an option

  • Save ToadKing/20710a49945715fae3e7 to your computer and use it in GitHub Desktop.

Select an option

Save ToadKing/20710a49945715fae3e7 to your computer and use it in GitHub Desktop.
Remove Promoted Stream Items
// ==UserScript==
// @name Remove Promoted Stream Items
// @namespace http://userscripts.org/
// @version 0.1
// @description Hides promoted items from Twitter streams. Was only able to test with the stream from a sponsered hash tag, because promoted items in timelines are elusive. More specifically, sets style "display: none" on the parent of divs with classes promoted-tweet and stream-item-content.
// @include http://twitter.com/*
// @include https://twitter.com/*
// @author Dan Carleton
// @copyright 2011+, Public Domain
// ==/UserScript==
// interval in milliseconds at which to check for new sponsered links to hide.
hideInterval = 2000
// the expression to match on for
promotedItemXpath = "//li[*[contains(@class,'promoted')]]"
function hideSponseredItems() {
var result = document.evaluate(
promotedItemXpath,
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (var i = 0; i < result.snapshotLength; i++) {
var target = result.snapshotItem(i);
target.style.display = 'none';
}
}
var checkAgain = false
function doCheck() {
if (checkAgain) {
hideSponseredItems();
checkAgain = false;
}
}
// hide any sponsered items that exist in the initial content from the server.
document.addEventListener("DOMContentLoaded", function(){
document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
window.setInterval(doCheck, 500);
hideSponseredItems();
}, false);
// periodically look for new sponsered items that have appeared and hide those too.
document.addEventListener("DOMNodeInserted", function(){
checkAgain = true;
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment