Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Just Dice Ignore Functionality
- // @namespace Gray
- // @description Does what it says.
- // @include https://just-dice.com/*
- // @version 1
- // @tip 1BxDR3sHBn2yHjamLuGi5H6bR7J1NBy2Do (works with input.io)
- // ==/UserScript==
- $(function() {
- var data = localStorage.getItem('ignoredUsers'),
- userList = {},
- ignoreList = data ? JSON.parse(data) : {},
- chatEvent = socket['$events'].chat;
- $panel = $('#account').children('.panel'),
- $heading = $('<h3>').text('Ignore Users in Chat'),
- $list = $('<ul>'),
- $input = $('<input>').attr('placeholder', 'User ID'),
- $button = $('<button>').text('Ignore');
- $panel.append($heading);
- $panel.append($('<p>').text('Click users to remove them from the ignore list.'));
- $panel.append($list, $input, ' ', $button);
- socket.removeAllListeners('chat');
- socket.on('chat', function(txt, date) {
- var txtdata = txt.match(/^\(([0-9]+)\) <([^>]+)>/),
- id = parseInt(txtdata[1],10),
- name = txtdata[2];
- // Update username
- if(!userList[id] || userList[id] !== name) {
- updateUser(id, name);
- }
- if(typeof ignoreList[id] !== 'string') {
- chatEvent(txt, date);
- }
- });
- $list.on('click', 'a', function() {
- var $el = $(this),
- id = $el.attr('data-userid');
- delete ignoreList[id];
- $el.parent().fadeOut();
- });
- $button.on('click', function() {
- var id = parseInt($input.val(), 10),
- name = userList[id] || "[unknown]";
- if(!ignoreList[id]) {
- ignoreList[id] = name;
- updateList();
- }
- $input.val('');
- $input.focus();
- });
- function updateUser(id, name, i) {
- userList[id] = name;
- if(ignoreList[id]) {
- ignoreList[id] = name;
- updateList();
- }
- }
- function updateList() {
- localStorage.setItem('ignoredPlayers', JSON.stringify(ignoreList));
- $list.empty();
- for(var id in ignoreList) {
- if(!ignoreList.hasOwnProperty(id)) {
- continue;
- }
- name = ignoreList[id];
- $liEl = $('<li>').appendTo($list),
- $a = $('<a>').text('('+id+') <'+name+'>').appendTo($liEl).attr('data-userid', id);
- }
- }
- // Array Remove - By John Resig (MIT Licensed) // Thanks John!
- function arrayRemove(array, from, to) {
- var rest = array.slice((to || from) + 1 || array.length);
- array.length = from < 0 ? array.length + from : from;
- return array.push.apply(array, rest);
- };
- updateList();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement