Created
June 26, 2010 12:46
-
-
Save fuba/454027 to your computer and use it in GitHub Desktop.
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 decode hitode909 | |
// @namespace http://d.hatena.ne.jp/send/ | |
// @description twitter filter | |
// @include http://twitter.com/* | |
// @include http://mobile.twitter.com/* | |
// ==/UserScript== | |
// | |
(function (){ | |
function decode_hitode909 (elem) { | |
unsafeWindow.console.log(elem.childNodes.length); | |
for (var i=0; i<elem.childNodes.length; i++) { | |
var e = elem.childNodes[i]; | |
if (e.nodeName == "#text") { | |
var count = []; | |
var lastchar = null; | |
var charnum = 0; | |
var s = e.textContent; | |
for (var j=0;j<s.length;j++) { | |
var c = s.charAt(j); | |
if (lastchar != c) { | |
if (lastchar != null) { | |
count.push({ | |
num: charnum, | |
char: lastchar, | |
}); | |
} | |
charnum = 1; | |
lastchar = c; | |
} | |
else { | |
charnum++; | |
} | |
} | |
count.push({ | |
num: charnum, | |
char: lastchar, | |
}); | |
var freq = {0:0}; | |
var m = 0; | |
count.map(function(item){return item.num}).sort().forEach( | |
function (num) { | |
if (!freq[num]) freq[num] = 0; | |
freq[num]++; | |
if (freq[num] > freq[m]) { | |
m = num; | |
} | |
} | |
) | |
var result = count.map(function(item){ | |
var result = ''; | |
var num = Math.floor(item.num / m); | |
if (num < 1) num = 1; | |
for (var i=0;i<num;i++) { | |
result += item.char; | |
} | |
return result; | |
}).join(''); | |
unsafeWindow.console.log(count, freq, e.textContent, result); | |
e.textContent = result; | |
} | |
else { | |
decode_hitode909(e); | |
} | |
} | |
} | |
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++) { | |
decode_hitode909(elems.snapshotItem(e)); | |
} | |
}, | |
}; | |
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