]> git.example.dev Git - binbsis50.git/commitdiff
minor refactor
authorLuigi Pinca <luigipinca@gmail.com>
Tue, 24 Mar 2015 10:15:21 +0000 (11:15 +0100)
committerLuigi Pinca <luigipinca@gmail.com>
Tue, 24 Mar 2015 10:23:39 +0000 (11:23 +0100)
public/js/app.js

index 62ea6abb3b77a36378425931abcc9c38368435a3..76ff4c5b586a5eb02663c3891f532763795ad4d7 100644 (file)
@@ -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?'
         meantime = (meantime / 1000).toFixed(1) + ' s';
       }
 
-      html.push('<td>' +meantime + '</td>');
+      html.push('<td>' + meantime + '</td>');
       html.push('</tr>');
     });
 
 
   // 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);
     }
       $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);
 
   // 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 = $('<span class="guess-time"></span>')
         , $li = $('<li></li>')
         , $pnts = $('<span class="points">(' + user.points + ')</span>')