Advertisement
gray_btc

JustDice Chat Ignore

Jul 5th, 2013
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Just Dice Ignore Functionality
  3. // @namespace   Gray
  4. // @description Does what it says.
  5. // @include     https://just-dice.com/*
  6. // @version     1
  7. // @tip     1BxDR3sHBn2yHjamLuGi5H6bR7J1NBy2Do (works with input.io)
  8. // ==/UserScript==
  9.  
  10. $(function() {
  11.     var data = localStorage.getItem('ignoredUsers'),
  12.         userList = {},
  13.         ignoreList = data ? JSON.parse(data) : {},
  14.         chatEvent = socket['$events'].chat;
  15.         $panel = $('#account').children('.panel'),
  16.         $heading = $('<h3>').text('Ignore Users in Chat'),
  17.         $list = $('<ul>'),
  18.         $input = $('<input>').attr('placeholder', 'User ID'),
  19.         $button = $('<button>').text('Ignore');
  20.  
  21.     $panel.append($heading);
  22.     $panel.append($('<p>').text('Click users to remove them from the ignore list.'));
  23.     $panel.append($list, $input, ' ', $button);
  24.  
  25.     socket.removeAllListeners('chat');
  26.     socket.on('chat', function(txt, date) {
  27.         var txtdata = txt.match(/^\(([0-9]+)\) <([^>]+)>/),
  28.             id = parseInt(txtdata[1],10),
  29.             name = txtdata[2];
  30.  
  31.         // Update username
  32.         if(!userList[id] || userList[id] !== name) {
  33.             updateUser(id, name);
  34.         }
  35.  
  36.         if(typeof ignoreList[id] !== 'string') {
  37.             chatEvent(txt, date);
  38.         }
  39.     });
  40.  
  41.     $list.on('click', 'a', function() {
  42.         var $el = $(this),
  43.             id = $el.attr('data-userid');
  44.         delete ignoreList[id];
  45.         $el.parent().fadeOut();
  46.     });
  47.  
  48.     $button.on('click', function() {
  49.         var id = parseInt($input.val(), 10),
  50.             name = userList[id] || "[unknown]";
  51.  
  52.         if(!ignoreList[id]) {
  53.             ignoreList[id] = name;
  54.             updateList();
  55.         }
  56.  
  57.         $input.val('');
  58.         $input.focus();
  59.     });
  60.  
  61.     function updateUser(id, name, i) {
  62.         userList[id] = name;
  63.         if(ignoreList[id]) {
  64.             ignoreList[id] = name;
  65.             updateList();
  66.         }
  67.     }
  68.  
  69.     function updateList() {
  70.         localStorage.setItem('ignoredPlayers', JSON.stringify(ignoreList));
  71.  
  72.         $list.empty();
  73.         for(var id in ignoreList) {
  74.             if(!ignoreList.hasOwnProperty(id)) {
  75.                 continue;
  76.             }
  77.             name = ignoreList[id];
  78.             $liEl = $('<li>').appendTo($list),
  79.             $a = $('<a>').text('('+id+') <'+name+'>').appendTo($liEl).attr('data-userid', id);
  80.         }
  81.     }
  82.  
  83.     // Array Remove - By John Resig (MIT Licensed) // Thanks John!
  84.     function arrayRemove(array, from, to) {
  85.         var rest = array.slice((to || from) + 1 || array.length);
  86.         array.length = from < 0 ? array.length + from : from;
  87.         return array.push.apply(array, rest);
  88.     };
  89.  
  90.     updateList();
  91. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement