User:Arashiryuu0/global.js

/** * Global code - affects all wikias/fandoms I use. * @namespace Global.js */ var has = Object.prototype.hasOwnProperty, slice = Array.prototype.slice, push = Array.prototype.push, toString = Object.prototype.toString, config = mw.config.get([           'wgIsEditPage',            'wgPageName'        ]), imports = [ {               type: 'script', articles: [ 'u:dev:RelatedDiscussionsModule/code.js', 'u:dev:MediaWiki:JavascriptEditor.js', 'u:dev:CodeblockLineNumbers/code.js', 'u:dev:DifferentSkinEditor/code.js', 'u:dev:YoutubeModal/code.js', 'u:dev:PurgeButton/code.js', 'u:dev:View_Source/code.js', 'u:dev:MediaWiki:FANSUN.js', 'u:dev:UTCClock/code.js', 'u:dev:Message/code.js', 'u:dev:I18n-js/code.js', 'u:dev:AjaxRC/code.js', 'u:dev:Toasts.js' ]           },            {                type: 'script', articles: [ // 'u:bloodborne:JSHighlightFixes.js', 'u:bloodborne:DOMTools.js' ]           },            {                type: 'style', articles: [ 'u:bloodborne:MediaWiki:CodeblockIdentifiers.css' ]           }        ],        fansun = [ 'u:dev:MediaWiki:FANSUN/community.css', 'u:dev:MediaWiki:FANSUN/council.css', 'u:dev:MediaWiki:FANSUN/dev.css', 'u:dev:MediaWiki:FANSUN.css' ],       dc = [ 'page-dark', 'oasis-dark-theme' ];   function isObject (o) { return toString.call(o) === '[object Object]'; }   ;(function  {        var target = imports[2],            pTypes = ['js', 'css'],            darkPages = ['dev', 'community'],            host = location.host.split('.').shift,            pageExt = config.wgPageName.split('.').pop,            combined = ['u:dev:MediaWiki:Nord.css'].concat(fansun),            bodyHasClass = function (cn) {                return document.body.classList.contains(cn);            };        if (dc.some(bodyHasClass)) {            target.articles.push('u:dev:MediaWiki:Nord.css');        } else if (config.wgIsEditPage && pTypes.includes(pageExt)) {            document.body.classList.add('oasis-dark-theme');            target.articles.push('u:dev:MediaWiki:Nord.css');        }        darkPages.includes(host) && push.apply(target.articles, combined);    }); window.PurgeButtonText = 'Purge'; window.AjaxRCRefreshText = 'Auto-refresh'; window.AjaxRCRefreshHoverText = 'Automatically refresh the page'; window.ajaxSpecialPages = [ 'RecentChanges', 'WikiActivity', 'AllPages', 'UncategorizedPages' ];   importArticles.apply(this, imports); function wait { if (!has.call(window, 'DOMTools')) return setTimeout(wait, 1000); run; }   function run  { /**        * Remove featured videos */       ;(function  {            var items;            function hasChild (target) {                return has.call(target.attributes, 'itemprop');            }            function removeChild (child) {                return child.parentElement.removeChild(child);            }            function removeChildren (children) {                children.forEach(removeChild);            }            function filterChildren (children) {                return children.filter(hasChild);            }            function handleChildren (children) {                removeChildren(filterChildren(children));            }            function mapVideos (video) {                return slice.call(video.parentElement.children);            }            items = DOMTools.queryAll('div[itemprop="video"]').map(mapVideos);            items.forEach(handleChildren);        }); /**        * LineNumbers on Codeblocks * Moved to: https://dev.wikia.com/wiki/CodeblockLineNumbers */       /**         * Cancel button for edit pages. */       ;(function  {            var button, head, url;            if (!config.wgIsEditPage || window.CancelEditLoaded) return;            head = document.querySelector('#EditPageHeader h2');            if (!head) return;            window.CancelEditLoaded = true;            url = window.location.href.slice(0, -('?action=edit'.length));            button = DOMTools.parseHTML([ '', 'Cancel', '' ].join('').trim);           head.appendChild(button);            mw.util.addCSS('#cancel-button { margin-top: -2px; }');        }); /**        * Copy Code button */       ;(function  {            var init, preinit, preload, toastHook;            init = function (i18n, toasts) {                var s = [                        'div[class*="source-"]',                        '#theme-solarized-light',                        '#theme-solarized-dark',                        'code[class]:not(.no-language)'                    ],                    targets = DOMTools.queryAll(s.join(', ')),                    addButton;                addButton = function (codeblock) {                    var button, child;                    if (DOMTools.hasClass(codeblock, 'de1')) return;                    child = codeblock.firstChild;                    button = document.createElement('button');                    button.setAttribute('id', 'CopyCodeButton');                    DOMTools.text(button, i18n.msg('copy').plain);                    DOMTools.on(button, 'click.CopyButton', function (e) { var range = document.createRange, selection, success, error; this.blur; window.getSelection.removeAllRanges; range.selectNode(codeblock); codeblock.focus; selection = window.getSelection; selection.addRange(range); document.execCommand('copy'); toasts.info('Successfully copied.'); selection.removeAllRanges; });                   if (!['hljs', 'lineNumbers', 'de1'].includes(child.className)) return;                    codeblock.prepend(button);                };                targets.forEach(addButton);            };            preload = function (toasts, i18n) {                i18n.loadMessages('CopyCodeButton').then(function (i18no) { setTimeout(function {                        init(i18no, toasts);                    }, 1000); });           };            toastHook = function (toast) {                mw.hook('dev.i18n').add(preload.bind(null, toast));            };            mw.hook('dev.toasts').add(toastHook);        }); /**        * Make light-theme Discord widget use dark-theme */       ;(function  {            var tries = 0;            var init = function (rail) {                var w = rail.querySelector('.discord-widget-container .widget');                if (!w.classList.contains('widget-theme-light')) return;                w.classList.replace('widget-theme-light', 'widget-theme-dark');            };            var retry = function  {                if (tries >= 6) return;                if (!window.Discord) return (tries++, setTimeout(retry, 1000));                init(window.Discord.$rail.get(0));            };            retry;        }); }   addOnloadHook(wait); });
 * (function {

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

/*@end@*/