Created
January 6, 2012 04:49
-
-
Save yuanchuan/1569043 to your computer and use it in GitHub Desktop.
play
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
/** | |
* 估算有多少人投票 | |
*/ | |
Math.round([].slice.call( | |
document.querySelectorAll( | |
'tbody td[bgcolor="#ffffff"]:nth-child(2)' | |
), 1) | |
.map(function(n){ | |
return parseInt( | |
n.innerHTML.split(':(')[1] | |
); | |
}) | |
.reduce(function(a, b){ | |
return a + b; | |
}) / 2.7 | |
); | |
/** | |
* 显示排名 | |
*/ | |
var map = [ | |
[].slice.call(document.querySelectorAll('tbody td[bgcolor="#ffffff"]:nth-child(1)'), 1, 16) | |
.map(function(n){ return n.innerHTML.trim();}), | |
[].slice.call(document.querySelectorAll('tbody td[bgcolor="#ffffff"]:nth-child(2)'), 1) | |
.map(function(n){ return parseInt(n.innerHTML.split(':(')[1]);}), | |
[] | |
]; | |
while (map[0].length && map[2].push( | |
{name:map[0].pop(),vote:map[1].pop()} | |
)); | |
map[2] | |
.sort(function(a,b){return b.vote - a.vote;}) | |
.forEach(function(s){console.log(s.name, s.vote);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment