User:.jun/common.js

importScriptURI('http://monchbox.wikia.com/wiki/User:Monchoman45/monobook.js?action=raw&ctype=text/javascript&templates=expand&debug=true');

window.localStorage.setItem('torus-pings', '{"#global":{"enabled":true,"alert":"Activity!","interval":500,"beep":true,"sound":"http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg","regex":[],"literal":[]},"community":{"enabled":true,"alert":"Activity!","interval":500,"beep":true,"sound":"http://images.wikia.com/monchbox/images/0/01/Beep-sound.ogg","regex":["/slyst/gi", "/mod(|s)\\b/gi", "/[A-Z]{10,}/g"],"literal":[]}}');

/* chat connect - vanilla version */ var chatconnect = { regex: { timestamp: /[0-2]{1}\d{1}:[0-5]{1}\d{1}, \w* \d{1,2}, \d{4}/gi, ip: /(?:\d{1,3}\.){3}\d{1,3}/gi },       title: document.title, css: => { var css = document.createElement('style'); css.type = 'text/css'; css.innerHTML = '.banned {' + 'background-color: #ffbfbf;' + '}' +               '.banned:after {' + 'content: \' [banned]\';' + 'font-weight: bold;' + 'color: darkred;' + '}' +               '.banned a {' + 'color: #c34d4d;' + '}' +               '.inchat {' + 'background-color: #c6e4ef;' + '}' +               '.inchat:after {' + 'content: \' [in chat]\';' + 'font-weight: bold;' + 'color: #000;' + '}';           document.head.appendChild(css); },       add: doc => { var doc = doc || document, list = doc.getElementsByClassName('mw-logline-chatconnect'); Array.prototype.forEach.call(list, (item, i) => {               list[i].innerHTML = list[i].innerHTML.replace(chatconnect.regex.timestamp, match => { return ' ' + match + ' '; }).replace(chatconnect.regex.ip, match => { return ' ' + match + ' '; });           });        },        get: doc => { var doc = doc || document; chatconnect.add(doc); var list = {}, logs = doc.getElementsByClassName('mw-logline-chatconnect'), rev = [].slice.call(logs, 0).reverse; Array.prototype.forEach.call(rev, item => {               list[item.children[1].innerText] = {                    timestamp: item.children[0].innerText,                    ip: item.children[4].innerText                };            }); return list; },       process: list => { var dupes = {}, users = Object.keys(list); for (var i in list) { for (var j in list) { if (i !== j && list[i].ip == list[j].ip) { var ip = list[i].ip; if (typeof dupes[ip] == 'undefined') { dupes[ip] = {}; dupes[ip][i] = list[i].timestamp; }                       dupes[ip][j] = list[j].timestamp; delete list[j]; }               }            }            chatconnect.dupes = dupes; chatconnect.users = users; chatconnect.banned; },       banned:  => { var xhr = new XMLHttpRequest; xhr.open('GET', '/api.php?action=query&list=logevents&letype=chatban&lelimit=100&format=json', true); xhr.onload = => { var users = JSON.parse(xhr.responseText).query.logevents.filter(obj => {                       return chatconnect.users.indexOf(obj.title.substr(5)) > -1;                }), banned = {}; for (var i = 0; i < users.length; i++) { banned[users[i].title.substr(5)] = new Date(new Date(users[i].timestamp).getTime + (users[i][4] * 1000)).getTime > new Date.getTime; }               chatconnect.generate(banned); }           xhr.send; },       generate: banned => { var dupes = chatconnect.dupes; require(['wikia.nirvana'], nirvana => {               nirvana.sendRequest({ controller: 'ChatRail', type: 'GET', method: 'executeGetUsers', callback: data => { var inchat = []; for (var i in data.users) { inchat.push(data.users[i].username); }                       var html = ' '; for (var i in dupes) { html += '' + i + ' (whois)'; for (var j in dupes[i]) { var classes = []; for (var k = 0; k < inchat.length; k++) { if (j == inchat[k]) { classes.push('inchat'); break; }                               }                                for (var l in banned) { if (j == l && banned[l]) { classes.push('banned'); }                               }                                var enc = mw.util.wikiUrlencode(j); html += '' + dupes[i][j] + ' ' + j + ' (wall | contribs | check | bans | blocks</a>)</li>'; }                           html += '</ul></li>'; }                       html += '</ul>'; if (!document.getElementById('chat-connect')) { document.querySelectorAll('#mw-content-text > ul')[0].insertAdjacentHTML('beforebegin', ' Breakdown A total of 0 duplicate IP entries were found. </ul> Chat connection log '); }                       document.getElementById('dupe-count').textContent = Object.keys(dupes).length; document.getElementById('dupes').outerHTML = html; document.title = '[' + Object.keys(dupes).length + '] | ' + chatconnect.title; setTimeout(chatconnect.update, 30000); }               });            });        },        update:  => { document.title = '[ ... ] | ' + chatconnect.title; var xhr = new XMLHttpRequest; xhr.open('GET', window.location.href, true); xhr.onload = => { if (xhr.status == 200) { var doc = (str => {                       var temp = document.implementation.createHTMLDocument;                        temp.body.innerHTML = str;                        return temp;                    })(xhr.responseText); var list = document.querySelector('#mw-content-text > ul'); list.insertAdjacentHTML('afterEnd', doc.querySelector('#mw-content-text > ul').outerHTML); list.parentNode.removeChild(list); chatconnect.process(chatconnect.get(doc)); }           };            xhr.send; },       init:  => { chatconnect.css; chatconnect.process(chatconnect.get); }   };    if (mw.config.get('wgTitle') == 'Log/chatconnect') { chatconnect.init; } });