Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created September 1, 2011 12:50
Show Gist options
  • Save joseanpg/1186102 to your computer and use it in GitHub Desktop.
Save joseanpg/1186102 to your computer and use it in GitHub Desktop.
GEJS 5.3 Recuento de votos
/*
RECUENTO DE VOTOS PARA
http://www.meetup.com/madridjs/pages/Votaci%F3n_para_%22Yo_tambi%E9n_quiero_una_birra%22/
Abre la consola, pega el siguiente código en ella
y ejecuta el siguiente código :)
Verficado en Firefox a las 14:46 del 2011-09-01
*/
alert(
[].reduce.call(document.querySelectorAll('.D_bbcode ul > li'),function(acu,li){
var t = /^(@.+)\s*:\s*([\+\d\s]*?)\s*$/.exec(li.textContent);
var p = t[2].match(/\+\d{1,3}/g);
p = p ? t[1]+':'+p.reduce(function(acu,item){return acu+Number(item);},0)+'\n'
: '';
return acu+p;
},''));
@joseanpg
Copy link
Author

joseanpg commented Sep 1, 2011

Versión utilizando eval (cuidadito con eval en situaciones como esta :)

alert(
  [].reduce.call(document.querySelectorAll('.D_bbcode ul > li'),function(acu,li){
     var t = /^(@.+)\s*:\s*([\+\d\s]*?)\s*$/.exec(li.textContent);
     var p = eval(t[2]);
     p = typeof p === 'number' ? t[1]+':'+p+'\n'
                               : '';
    return acu+p;
},''));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment