From: Luigi Pinca Date: Tue, 24 Mar 2015 10:15:21 +0000 (+0100) Subject: minor refactor X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=a87ed7179b78ca30ef76c3947909aab171a7f8b9;p=binbsis50.git minor refactor --- diff --git a/public/js/app.js b/public/js/app.js index 62ea6ab..76ff4c5 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -34,8 +34,8 @@ , subscriber = false , timer , urlregex = /(https?:\/\/[\-A-Za-z0-9+&@#\/%?=~_()|!:,.;]*[\-A-Za-z0-9+&@#\/%=~_()|])/ - , userscounters = {} - , usersnicks = []; + , users = [] + , userscounters = {}; var amstrings = [ 'Do you also know the title?' @@ -495,7 +495,7 @@ meantime = (meantime / 1000).toFixed(1) + ' s'; } - html.push('' +meantime + ''); + html.push('' + meantime + ''); html.push(''); }); @@ -961,7 +961,7 @@ // Send a private message to a user var privateMessage = function(args, $outcome) { - if ($.inArray(args[0], usersnicks) === -1) { + if (!~users.indexOf(args[0])) { $outcome.text('(From binb): There\'s no one here by that name.'); return addChatEntry($outcome); } @@ -974,8 +974,8 @@ $outcome.text('(From binb): There\'s no one to reply to.'); return addChatEntry($outcome); } - if ($.inArray(replyto, usersnicks) === -1) { - $outcome.text('(From binb):' + replyto + ' isn\'t here anymore.'); + if (!~users.indexOf(replyto)) { + $outcome.text('(From binb): ' + replyto + ' isn\'t here anymore.'); return addChatEntry($outcome); } addPrivate(replyto); @@ -1010,23 +1010,18 @@ // Update the list of players var updateUsers = function(usersData) { - var users = []; - - usersnicks = []; $users.empty(); - for (var key in usersData) { - users.push(usersData[key]); - usersnicks.push(key); - } - users.sort(function(a, b) { - return b.points - a.points; + users = Object.keys(usersData).sort(function(a, b) { + return usersData[b].points - usersData[a].points; }); // Flag to test if our private recipient is in the list of active users var found = false; users.forEach(function(user, index) { + user = usersData[user]; + var $guesstime = $('') , $li = $('
  • ') , $pnts = $('(' + user.points + ')')