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).text,            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, 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 = $('.javascript.source-javascript'),        blocks = codeblocks.length,        keywords = {            'arguments': 'args',            'Error': 'err',            'TypeError': 'typeErr',            'RangeError': 'rangeErr',            'SyntaxError': 'syntaxErr'        },        css = '.args { color: #F95479; } .err, .typeErr, .rangeErr, .syntaxErr { color: #FFCB6B; }',        styleCSS = createElement('style', { id: 'KeywordColourCSS', className: 'colourCss', textContent: css }),       i, j, len, child, args;    function getKw(text) {        if (keywords.hasOwnProperty(text)) return keywords[text];        return null;    }    if (!blocks) return;    if (!document.getElementById('KeywordColourCSS')) document.head.appendChild(styleCSS);    if (wgPageName.endsWith('Arashiryuu0/wikia.js')) {        if (!codeblocks[0].textContent) return;        (function { i = 0; len = codeblocks[0].childNodes.length; for (i; i < len; i++) { child = codeblocks[0].childNodes[i]; if (!child.data) continue; else if (child.data && !['arguments', 'Error', 'TypeError', 'RangeError', 'SyntaxError'].includes(child.data.trim)) 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;            for (i; i < len; i++) {                child = codeblocks[j].childNodes[i];                if (!child.data) continue;                else if (child.data && !['arguments', 'Error', 'TypeError', 'RangeError', 'SyntaxError'].includes(child.data.trim)) continue;                args = createElement('span', { className: getKw(child.data.trim), textContent: child.data });               child.replaceWith(args);            }        }    } });

/** * 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; }

/** * createElement */ function createElement(type, properties) { if (typeof type !== 'string' || typeof properties !== 'object') throw new TypeError('`type` must be string, `properties` must be object.'); var element = document.createElement(type), prop; for (prop in properties) { element[prop] = properties[prop]; }   return element; }

/*@end@*/