Created
March 30, 2011 13:59
-
-
Save motemen/894439 to your computer and use it in GitHub Desktop.
Make one's tweets boring
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 BoringTwitter | |
// @namespace http://tokyoenvious.net/ | |
// @description Make one's tweets boring | |
// @include http://twitter.com/#!/* | |
// @include https://twitter.com/#!/* | |
// @require https://github.com/cho45/jsdeferred/raw/master/jsdeferred.userscript.js | |
// ==/UserScript== | |
with (D()) + function () { | |
var match = /^#!\/(\w+)/.exec(location.hash); | |
if (!match) return; | |
var screenName = match[1]; | |
var isInterestingTweetID = null; | |
var tweetElemsToCheck = []; | |
getInterestingTweetIDs(screenName).next(function (ids) { | |
isInterestingTweetID = ids; | |
tweetElemsToCheck.forEach(filterTweetElem); | |
}); | |
document.addEventListener('DOMNodeInserted', function (e) { | |
var elem = e.target; | |
if (elem.className.indexOf('stream-item') == -1) return; | |
if (!isInterestingTweetID) { | |
tweetElemsToCheck.push(elem); | |
} else { | |
filterTweetElem(elem); | |
} | |
}, false); | |
function getInterestingTweetIDs (screenName) { | |
try { | |
var cache = eval(GM_getValue('favstar-' + screenName, '({})')); | |
} catch (e) { | |
} | |
if (cache && cache.expire > new Date().getTime()) { | |
return next(function () { return cache.ids }); | |
} | |
return xhttp.get('http://favstar.fm/users/' + screenName + '/rss').next(function (r) { | |
var ids = {}; | |
var d = DOMParser().parseFromString(r.responseText, 'text/xml'); | |
Array.forEach( | |
d.querySelectorAll('item link'), function (link) { | |
if (/(\d+)$/.exec(link.textContent)) { | |
ids[RegExp.$1] = true; | |
} | |
} | |
); | |
GM_setValue( | |
'favstar-' + screenName, | |
uneval({ | |
expire: new Date().getTime() + 60 * 60 * 1000, // 1 hour | |
ids: ids | |
}) | |
); | |
return ids; | |
}).error(function (e) { alert(e) }); | |
} | |
function filterTweetElem (elem) { | |
var tweetID = elem.getAttribute('data-item-id'); | |
if (isInterestingTweetID[tweetID]) { | |
elem.style.visibility = 'hidden'; | |
} | |
} | |
} () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment