User:TheOneFootTallBrickWall/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: /(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/gi },       title: document.title, css: function { 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: function(doc) { var doc = doc || document, list = doc.getElementsByClassName('mw-logline-chatconnect'); Array.prototype.forEach.call(list, function(item, i) {               list[i].innerHTML = list[i].innerHTML.replace(chatconnect.regex.timestamp, function(match) { return ' ' + match + ' '; }).replace(chatconnect.regex.ip, function(match) { return ' ' + match + ' '; });           });        },        get: function(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, function(item) {               list[item.children[1].innerText] = {                    timestamp: item.children[0].innerText,                    ip: item.children[4].innerText                };            }); return list; },       process: function(list) { var dupes = {}, users = Object.keys(list); for (var i in list) { if (list.hasOwnProperty(i)) { for (var j in list) { if (list.hasOwnProperty(j)) { 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: function { var xhr = new XMLHttpRequest; xhr.open('GET', '/api.php?action=query&list=logevents&letype=chatban&lelimit=100&format=json', true); xhr.onload = function { var users = JSON.parse(xhr.responseText).query.logevents.filter(function(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: function(banned) { var dupes = chatconnect.dupes; require(['wikia.nirvana'], function(nirvana) {               nirvana.sendRequest({ controller: 'ChatRail', type: 'GET', method: 'executeGetUsers', callback: function(data) { var inchat = []; for (var i in data.users) { if (data.users.hasOwnProperty(i)) { inchat.push(data.users[i].username); }                       }                        var html = ' '; for (i in dupes) { if (dupes.hasOwnProperty(i)) { html += '' + i + ' (whois)'; for (var j in dupes[i]) { if (dupes[i].hasOwnProperty(j)) { 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: function { document.title = '[ ... ] | ' + chatconnect.title; var xhr = new XMLHttpRequest; xhr.open('GET', window.location.href, true); xhr.onload = function { if (xhr.status == 200) { var doc = (function(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: function { chatconnect.css; chatconnect.process(chatconnect.get); }   };    if (mw.config.get('wgTitle') == 'Log/chatconnect') { chatconnect.init; } }); //
 * (function {

// removes listings entries from a json tree // and also makes it into an easy array function removeListings (data) { filteredList = data.filter(function(element) {       if ((element.title).indexOf('/') !== -1) {            return element;        }    }); return filteredList; }

function renderStamp (iso) { date = new Date(iso); return date.getDate + ' ' + wgMonthNames[date.getMonth+1] + ' ' + date.getFullYear; }

function createCommentCounts ($this, admins, commentLink) { var count = 0, myusercount = 0, allmyusercount = 0, admincount = 0; $.get('/api.php', {       action: 'query',        list: 'allpages',        apnamespace: '501',        apfrom: commentLink,        aplimit: '80',        format: 'json'    }).done(function(d) {        var adminList = [];        for (var j = 0; j < 80; j++) {            var w = d.query.allpages[j].title;            if (w.indexOf(commentLink) !== -1) {                count++;                var rgxend = new RegExp('@comment-' + wgUserName + '-\\d*$', 'g'),                    rgxany = new RegExp('@comment-' + wgUserName + '-\\d*', 'g');                if (w.match(rgxend)) {                    myusercount++;                }                if (w.match(rgxany)) {                    allmyusercount++;                }                for (var k = 0; k < admins.length; k++) {                    if (w.indexOf("@comment-" + admins[k]) !== -1) {                        admincount++;                        if (adminList.indexOf(admins[k]) === -1) { adminList.push(admins[k]); }                   }                }            }            else { break; }       }

$this.prepend(' <div class="comments-counters-total" data-count="' + count + '">' + count + ' ' +            '<div class="comments-counters-admins" data-count="' + admincount + '">' + admincount + ' ' +             '<div class="comments-counters-own" data-count="' + myusercount + '">' + myusercount + ' ' +             '<div class="comments-counters-responses" data-count="' + (allmyusercount - myusercount) + '">' + (allmyusercount - myusercount) + '  ' +             ' ' + $this.attr('data-timestamp') + ' '); if (adminList.length) { $this.append(' Replies from ' + adminList.join(", ") + ' '); } else if (!count) { $this.append(' No comments! '); }       $this.append('');

if (count === 0) { $this.addClass("no-comments"); } else { $this.addClass("many-comments"); }       if (myusercount === 0) { $this.addClass("no-own-comments"); } else { $this.addClass("many-own-comments"); }       if (admincount === 0) { $this.addClass("no-admin-comments"); } else { $this.addClass("many-admin-comments"); }   }); }

if (mw.config.get('wgCanonicalSpecialPageName') === "Blankpage" && $.getUrlVar('blankspecial') === "blogreport") { $('#mw-content-text p').html(' '); $('.header-column.header-title h1').text('Blog Report Interface'); }   if ($('#CC-blog-interface').length === -1 || mw.config.get("wgCityId") !== "177") { return; }   importStylesheetURI('http://internal.community.wikia.com/index.php?title=MediaWiki:BlogReport.css&action=raw&ctype=text/css'); $('#CC-blog-interface').empty; $.getJSON('/api.php', {        action: 'query',         list: 'recentchanges',         rcnamespace: '500',         rctype: 'new',         rclimit: '500',         rcprop: 'user|title|timestamp|ids|sizes|redirect',         format: 'json'     }, function (blogData) {         var newBlogs = removeListings(blogData.query.recentchanges);         for (var i = 0; i < newBlogs.length; i++) {            var $newBlog = $(' ' + '' + newBlogs[i].title + '</a>' + ' ');           if (typeof newBlogs[i].redirect !== "undefined") {                var $newBlog = $(' ' + '' + newBlogs[i].title + '#redirect' + '</a>' + ' ');           }
 * (function($, mw) {

$('#CC-blog-interface').append($newBlog); }       $('.new-blog').each(function {            var admins = ['2Actimv','AdorableDarling','Callofduty4','Jr Mime','Noreplyz','Sactage','Slyst','Spongebob456','TheOneFootTallBrickWall','TyA','Yatalu','Sannse', 'Kirkburn', 'BertH'],                $this = $(this).find('a'),                newBlogTitle = $(this).find('a').text,                commentLink = newBlogTitle.replace('User blog','');                if (newBlogTitle.indexOf("#redirect") !== -1) {                    $.getJSON('/api.php', { action: 'query', prop: 'info', inprop: 'redirect', titles: newBlogTitle.slice(0, -9), format: 'json' }, function (redirectInfo) { redirectInfo = redirectInfo.query.pages; for (var keyname in redirectInfo) { commentLink = redirectInfo[keyname]["redirectto"].replace('User_blog','').replace(/_/g,' '); $this.find('a').html(redirectInfo[keyname]["redirectto"].replace(/_/g,' ')); createCommentCounts ($this, admins, commentLink); }                    });                } else {                    createCommentCounts ($this, admins, commentLink);                }        }); }); })(this.jQuery, this.mediaWiki); //