-
-
Save cxx/428554 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Twittfilter for hitode909-RT | |
// @namespace http://d.hatena.ne.jp/send/ | |
// @description twitter filter | |
// @include http://twitter.com/* | |
// @include http://mobile.twitter.com/* | |
// ==/UserScript== | |
// | |
(function (){ | |
function rt (elem, i) { | |
var s = elem.childNodes[i].data; | |
var ids, screen_names, id_cands; | |
ids = []; screen_names = []; id_cands = []; | |
if (s != null) { | |
if(s.match(/RT\s*\{\"id\"\s*\:\s*\"?(\d+)\"?(?:\s*\,\s*\"screen\_name\"\s*\:\s*\"([\w\d\_]+)\"\s*)?\}/)) { | |
ids = [RegExp.$1]; | |
screen_names = [RegExp.$2]; | |
} | |
else if (s.match(/(RT\s*\[\s*(?:\s*\,?\s*\{\"id\"\s*\:\s*\"?\d+\"?\s*\})+\s*\])/)) { | |
id_cands_cands = RegExp.$1; | |
id_cands = id_cands_cands.match(/(\d+)/g); | |
} | |
else if (s.match(/RT\s+([\d\w]+)/)) { | |
id_cands = [RegExp.$1]; | |
} | |
else if (s.match(/([\d\w]+)\s*$/)) { | |
id_cands = [RegExp.$1]; | |
} | |
} | |
if (id_cands) { | |
id_cands.forEach(function (id_cand) { | |
if (id_cand.match(/^0([0-7]+)$/)) { | |
ids.push(parseInt(RegExp.$1, 8)); | |
} | |
else if (id_cand.match(/^[0-9]+$/)) { | |
ids.push(id_cand); | |
} | |
else if (id_cand.match(/^[0-9a-f]+$/i)) { | |
ids.push(parseInt(id_cand, 16)); | |
} | |
}); | |
} | |
for (var i=0; i<ids.length; i++) { | |
var id = ids[i]; | |
var screen_name = screen_names[i]; | |
var link = document.createElement('A'); | |
var decoration; | |
if (screen_name) { | |
decoration = document.createElement('marquee'); | |
link.href = | |
"http://twitter.com/"+screen_name+"/status/"+id; | |
link.innerHTML = " "+link.href; | |
} | |
else { | |
decoration = document.createElement('blink'); | |
link.href = | |
"http://mobile.twitter.com/statuses/"+id; | |
link.innerHTML = " "+link.href; | |
} | |
decoration.appendChild(link); | |
elem.appendChild(decoration); | |
} | |
} | |
var filter = function(node) { | |
var f = { | |
anouncement : function (context){ | |
var path = './/span[@class="entry-content"] | .//span[@class="status"]'; | |
var elems = document.evaluate(path, context, null, 7, null); | |
for(var e = 0 ; e < elems.snapshotLength; e++) { | |
var elem = elems.snapshotItem(e); | |
for(var i = 0 ; i < elem.childNodes.length; i++) { | |
rt(elem, i); | |
} | |
} | |
}, | |
}; | |
for (var func in f) f[func](node); | |
} | |
filter(document); | |
document.getElementById('timeline').addEventListener('DOMNodeInserted', function(event) { | |
filter(event.target); | |
}, false); | |
})(); | |
//.user.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment