User:Arashiryuu0/global.js

/** * @namespace Global */ importArticles({   type: 'script',    articles: [        // 'w:c:admintools:MediaWiki:Wikia.js/editCount.js',        'u:dev:RelatedDiscussionsModule/code.js',        'u:dev:MediaWiki:View_Source/code.js',        'u:dev:DifferentSkinEditor/code.js',        'u:dev:YoutubeModal/code.js',        'u:dev:PurgeButton/code.js',        'u:dev:UTCClock/code.js',        'u:dev:Message/code.js',        'u:dev:AjaxRC/code.js'    ] });

/** * Purge Button */ PurgeButtonText = 'Purge';

/** * Auto Refresh */ AjaxRCRefreshText = 'Auto-refresh'; AjaxRCRefreshHoverText = 'Automatically refresh the page'; ajaxPages = [ 'Special:RecentChanges', 'Special:WikiActivity', 'Special:AllPages', 'Special:UncategorizedPages' ];

/** * Material Theme SyntaxHighlight Stuff */ (function {   function loop(_, e) {        var text = e.textContent,            word = getWord(text),            color = getColor(text);        if (word && color && !$(e).hasClass(word)) {            $(e).addClass(word).css(color);        } else if (text.toLowerCase === 'hasownproperty') {            $(e).addClass('ownProp').css('color', '#82AAFF');        }    }

function getWord(text) { if (keywords.hasOwnProperty(text)) return keywords[text]; return null; }   function getColor(text) { if (colors.hasOwnProperty(text)) return colors[text]; return null; }   var selectors = [ '.kw1', '.kw3', '.kw4', '.sy0' ],       keywords = { 'prototype': 'prote', 'this': 'this', 'new': 'new', '=>': 'aF', '$': 'jQ' },       colors = { 'prototype': { 'color':'#f78c6a' }, 'this': { 'color':'#f95479' }, 'new': { 'color':'#89ddf3' }, '=>': { 'color':'#c792ea' }, '$': { 'color':'#89ddf3' } };   var i = 0, j = 0, ren, len = selectors.length, elements; for (i; i < len; i++) { elements = $('.javascript.source-javascript ' + selectors[i]); elements.each(loop); } });

/** * Remove featured videos */ (function {   function hasChild(e) {        return e.attributes.hasOwnProperty('itemprop');    }    var videos = document.querySelectorAll('div[itemprop="video"]'),        children, len = videos.length, i;    if (!len) return;    i = 0;    for (i; i < len; i++) {        children = Array.prototype.filter.call(videos[i].parentElement.children, hasChild);        if (children.length) children[i].parentElement.removeChild(children[i]);    } });

/** * Colour uncoloured keywords */ (function {   var codeblocks = $('pre.javascript.source-javascript, div.javascript.source-javascript .de1'),        blocks = codeblocks.length,        len, child, args, arr, j, i;    var keywords = {        '$$': 'br0',        '...': 'br0',        'with': 'kw1',        'arguments': 'kw1 this',        'Error': 'kw4',        'TypeError': 'kw4',        'RangeError': 'kw4',        'SyntaxError': 'kw4'    };    function getKw(text) {        if (keywords.hasOwnProperty(text)) return keywords[text];        return null;    }    if (!blocks) return;    arr = [        '$',        '...',        'with',        'arguments',        'Error',        'TypeError',        'RangeError',        'SyntaxError'    ];    if (wgTitle.includes('Arashiryuu0') && wgTitle.endsWith('.js')) {        if (!codeblocks[0].textContent) return;

i = 0; len = codeblocks[0].childNodes.length; if (!len) return; for (i; i < len; i++) { child = codeblocks[0].childNodes[i] || 0; if (!child) continue; if (!child.data) continue; if (!arr.includes(child.data.trim)) continue; if (child.data === '$' && child.previousSibling && child.previousSibling.textContent === '$') { args = createElement('span', {                   className: getKw('$$'),                    textContent: '$$'                }); child.previousSibling.parentElement.removeChild(child.previousSibling); child.replaceWith(args); } else if (child.data === '$') continue; args = createElement('span', {               className: getKw(child.data.trim),                textContent: child.data            }); child.replaceWith(args); }   } else { i = 0; j = 0; for (j; j < blocks; j++) { len = codeblocks[j].childNodes.length; if (!len) return; for (i; i < len; i++) { child = codeblocks[j].childNodes[i]; if (!child || typeof child === 'undefined') return; if (!child.data) continue; if (child.data && !arr.includes(child.data.trim)) continue; if (child.data === '$' && child.previousSibling && child.previousSibling.textContent === '$') { args = createElement('span', {                       className: getKw('$$'),                        textContent: '$$'                    }); child.previousSibling.parentElement.removeChild(child.previousSibling); child.replaceWith(args); } else if (child.data === '$') continue; args = createElement('span', {                   className: getKw(child.data.trim),                    textContent: child.data                }); child.replaceWith(args); }       }    } });

/** * LineNumbers on Codeblocks */ (function {   var validBlocks = ['de1', 'theme-solarized-dark', 'theme-solarized-light'],        stylesheet, css;    function addLines(codeblock) {        codeblock.innerHTML = codeblock.innerHTML.split('\n').map(function(line) { if (line.trim.indexOf('*') === 0 || line.trim.indexOf('/*') === 0) { return '' + line + ''; } else if (!!line) { return '' + line + ''; }       })        .join('');        return codeblock;    }    function blockFilter(e) {        if (e.tagName === 'PRE') {            return (e.classList && validBlocks.includes(e.classList[0])) || validBlocks.includes(e.id);        }    }    function notOL(e) {        return !e.querySelector('ol');    }    function processCodeblocks {        var blocks = Array.prototype.slice.call($$('pre')),            len, ol, i;        if (!blocks.length) return;        blocks = blocks            .filter(notOL)            .filter(blockFilter);        ol = createElement('ol', { className: 'lineNumbers' });       i = 0; len = blocks.length;        for (i; i < len; i++) wrapInner(addLines(blocks[i]), ol);    }    function wrapInner(parent, wrapper) {        if (typeof wrapper === 'string')            wrapper = createElement(wrapper);        $a(parent, wrapper);        while (parent.firstChild !== wrapper) {            $a(wrapper, parent.firstChild);        }    }    css = 'pre ol {' +            'list-style: none !important;' +            'counter-reset: lines;' +            'border-left: 1px solid rgba(0, 0, 0, 0.5) !important;' +        '}' +        'pre ol li {' +            'text-indent: -4ch;' +            'margin-left: -0.5ch;' +            'padding-left: 0.5ch;' +        '}' +        'pre ol li::before {' +            'color: #718184;' +            'display: inline-block;' +            'width: 3ch;' +            'margin-right: 0.5ch;' +            'padding-right: 0.5ch;' + 'text-align: right;' + 'counter-increment: lines;' + 'content: counter(lines);' + 'user-select: none;' + '-webkit-user-select: none;' + '}'.replace(/\s+/g, ' ').trim; stylesheet = createElement('style', {       id: 'lineNumbersCss',        textContent: css    }); $a(document.head, stylesheet); processCodeblocks; });

/** * Cookies */ function getCookies { if (!window.cookies) { Object.defineProperty(window, 'cookies', {           get: function {                return document.cookie.split(';').reduce(function(cookies, cookie) { cookies[cookie.split('=')[0].trim] = unescape(cookie.split('=')[1]); return cookies; }, {});           }        });        return window.cookies; }   return window.cookies; }

/** * Utility */ function createElement(type, properties) { var attributes, element, events, prop, name, len, val, ev, ty, pr, i;   type = type || ''; properties = properties || {}; ty = type.constructor.name; pr = properties.constructor.name; if (ty !== 'String' || pr !== 'Object') throw new TypeError('Expected: String, Object. Received: ' + ty + ', ' + pr); element = document.createElement(type); attributes = [ 'text', 'class' ];   events = { 'click': 'onclick', 'clicks': 'ondblclick', 'context': 'oncontextmenu', 'keyup': 'onkeyup', 'keydown': 'onkeydown', 'keypress': 'onkeypress', 'mouseup': 'onmouseup', 'mousedown': 'onmousedown', 'mousemove': 'onmousemove', 'mouseover': 'onmouseover', 'mouseout': 'onmouseout', 'mouseenter': 'onmouseenter', 'mouseleave': 'onmouseleave' };   for (prop in properties) { val = properties[prop]; if (!val) continue; name = val.constructor.name; if (attributes.includes(prop)) { if (prop === 'text') { element.textContent = val; continue; }           element.setAttribute(prop, val); } else if (events.hasOwnProperty(prop) && name === 'Function') { ev = events[prop]; element[ev] = val; } else if (prop === 'dataset' && name === 'Object') { for (i in val) element[prop][i] = val[i]; } else if (prop === 'childNodes' && name === 'Array') { i = 0; len = val.length; for (i; i < len; i++) { if (![1, 3].includes(val[i].nodeType)) continue; $a(element, val[i]); }       } else { element[prop] = val; }   }    element.props = properties; return element; }

function $$(selector) { return document.querySelectorAll.call(document, selector); }

function $a(target, element) { if (!target) return; return Node.prototype.appendChild.call(target, element); }

/*@end@*/