User:Doork/chat.js

// Modification of EmoticonsWindow by KockaAdmiralac (w:c:dev:EmoticonsWindow) /* Diff: * Changes the location of the button, * adds space between emote, * adds img title that displays emote trigger. */ $(window).load(function {   // Adding neccessary CSS    mw.util.addCSS(".kockaEmoticonsIcon{width:19px;height:19px;border:1px solid black;padding: 10px;border-radius: 5px;background:#004281;}.kockaEmoticonsIcon:hover{background:#19548d;}#kockaEmoticonsModalMain{height:400px;overflow-y:auto;} #kockaOpenModal{text-align:center;}");    // Initializing variables    var obj = window.kockaEmoticons || {};    obj.emoticons = {};    obj.vocab = obj.vocab || {};    // Parsing emoticons    EMOTICONS.split("\n").forEach(function(el, index, arr) { if(el[0] === "*" && el[1] !== "*") obj.emoticons[arr[index + 1].substring(2).trim] = el.substring(1).trim; }, this);    /**     * Function for creating an emoticon element     * @param [String] emote - Emote code     * @method     */    function createEmoteElement(emote) {        var el = document.createElement("img");        el.className = "kockaEmoticonsIcon"; el.src = obj.emoticons[emote]; el.setAttribute('title', emote); el.onclick = function { var ap = $(".message textarea").last; ap.val(ap.attr("value") + ' ' + emote); $("#kockaEmoticonsModal").closeModal; };       $("#kockaEmoticonsModalMain").append(el); }   // Creating Emoticons button var butt = document.createElement("div"); butt.id = "kockaOpenModal"; butt.innerHTML = "Emoticons "; butt.onclick = function { // Show modal $.showCustomModal(obj.vocab.emoticons || "Emoticons", " ", {           id: "kockaEmoticonsModal",            buttons: [{                id: "kockaEmoticonsClose",                defaultButton: true,                message: obj.vocab.close || "Close",                handler: function{ $("#kockaEmoticonsModal").closeModal; }            }]        }); // Adding help to modal $("#kockaEmoticonsModal .modalContent").prepend(" " + (typeof obj.help === 'undefined' ? "Choose an emoticon by clicking on it.": obj.help) + " "); // Adding emoticons to modal for(var emote in obj.emoticons) if(obj.emoticons.hasOwnProperty(emote)) createEmoteElement(emote); };   // Adding button to title $('#chatOptionsButton + .chat-button').after(butt); }); /* (function { if (mw.config.get('wgCanonicalSpecialPageName') !== 'Chat') return function z(a, b) { var d = x if (b === 1) { if (d.indexOf(a) === -1) { d.push(a) $('li[data-user="' + a + '"]').hide y(d) }       } else if (b === 2) { if (d.indexOf(a) > -1) { d.pop(d.indexOf(a)) $('li[data-user="' + a + '"]').show y(d) }       } else if (b === 3) { $('.Chat ul').append('' + d.join(', ') + '') }   }    function y(a) { localStorage.setItem('mute', JSON.stringify(a)) }   function x { return JSON.parse(localStorage.getItem('mute') || '[]') }   $('textarea[name=message]').keypress(function(e) {        if (e.which == 13) {            var a = $(this).val,                bc = '/mute',                cc = '/unmute',                dc = '/list';                d.shift                d = d.join(' ')            if (a[0] === '/') {                e.preventDefault                $(this).val()                if (this.value.indexOf(bc) > -1 && this.value.indexOf(bc) < 6) {                    z(d, 1)                } else if (this.value.indexOf(cc) > -1 && this.value.indexOf(cc) < 8) {                    z(d, 2)                } else if (this.value.indexOf(dc) > -1 && this.value.indexOf(dc) < 6) {                    z(, 3)                }            }        }    }) window.mainRoom.model.chats.bind('afteradd', function {       var a = x,            i = 0;        for (i; i < a.length; i++) {            $('li[data-user="' + a[i] + '"]').hide        }    }) });