User:Arashiryuu0/global.js

/** * Global code - affects all wikias/fandoms I use. * @namespace Global.js */

// jshint browser: true, devel: true, jquery: true // jshint strict: true, freeze: true, eqeqeq: true, futurehostile: true // jshint newcap: true, noarg: true, quotmark: single, shadow: outer // jshint latedef: true, undef: true, unused: true /* globals mw */

/** * The callback to be fired when Fandom is ready. * @callback hookFunct * @returns {void} */

/** * Initialization IIFE. */   'use strict'; const importArticles = window.importArticles; const has = Object.prototype.hasOwnProperty; const slice = Array.prototype.slice; const config = mw.config.get([       'wgNamespaceNumber',        'wgArticlePath',        'wgIsEditPage',        'wgPageName'    ]); const imports = [ {           type: 'script', articles: [ 'u:dev:MediaWiki:ConsistentModules/code.js', 'u:dev:MediaWiki:RelatedDiscussionsModule/code.js', 'u:dev:MediaWiki:JavascriptEditor.js', 'u:dev:MediaWiki:CodeblockLineNumbers/code.js', 'u:dev:MediaWiki:DifferentSkinEditor/code.js', 'u:dev:MediaWiki:YoutubeModal/code.js', 'u:dev:MediaWiki:PurgeButton/code.js', 'u:dev:MediaWiki:View_Source/code.js', 'u:dev:MediaWiki:UTCClock/code.js', 'u:dev:MediaWiki:Message/code.js', 'u:dev:MediaWiki:I18n-js/code.js', 'u:dev:MediaWiki:AjaxRC/code.js', 'u:dev:MediaWiki:CodeEditor.js', 'u:dev:MediaWiki:Toasts.js' ]       },        {            type: 'script', articles: [ 'u:bloodborne:MediaWiki:JSHighlightFixes.js', 'u:bloodborne:MediaWiki:DOMTools.js' ]       },        {            type: 'style', articles: [ 'u:bloodborne:MediaWiki:CodeblockIdentifiers.css', 'u:bloodborne:MediaWiki:Codeblocks.css', 'u:dev:MediaWiki:Responsive_mobile.css' ]       }    ];    const fired = new mw.Map; window.PurgeButtonText = 'Purge'; window.AjaxRCRefreshText = 'Auto-refresh'; window.AjaxRCRefreshHoverText = 'Automatically refresh the page'; window.ajaxSpecialPages = [ 'RecentChanges', 'WikiActivity', 'AllPages', 'UncategorizedPages' ];   const loaded = function  { if (fired.exists('loaded')) return; importArticles.apply(this, imports); mw.hook('DOMTools').add(function (DOMTools) {           if (fired.exists('DOMTools')) return;            /**             * Remove featured videos             */            ;(function  { 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); }               const 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  { if (!config.wgIsEditPage || window.CancelEditLoaded) return; const head = document.querySelector('#EditPageHeader h2'); if (!head) return; window.CancelEditLoaded = true; const url = mw.util.getUrl; const button = DOMTools.parseHTML([                   '',                    'Cancel',                    ''                ].join('').trim); head.appendChild(button); mw.util.addCSS('#cancel-button { margin-top: -2px; }'); });           /**             * Copy Code button             */            ;(function  { const init = function (i18n, toasts) { const s = [ 'div[class*="source-"]', '#theme-solarized-light', '#theme-solarized-dark', 'code[class]:not(.no-language)' ];                   const targets = DOMTools.queryAll(s.join(', ')); const addButton = function (codeblock) { if (DOMTools.hasClass(codeblock, 'de1')) return; const child = codeblock.firstChild; const button = document.createElement('button'); button.setAttribute('id', 'CopyCodeButton'); DOMTools.text(button, i18n.msg('copy').plain); DOMTools.on(button, 'click.CopyButton', function {                            const range = document.createRange;                            window.getSelection.removeAllRanges;                            range.selectNode(codeblock);                            codeblock.focus;                            const selection = window.getSelection;                            selection.addRange(range);                            document.execCommand('copy');                            selection.removeAllRanges;                            toasts.info('Successfully copied.');                        }); if (!['hljs', 'lineNumbers', 'de1'].includes(child.className)) return; codeblock.prepend(button); };                   targets.forEach(addButton); };               const preload = function (toasts) { return function (i18n) { i18n.loadMessages('CopyCodeButton').then(function (i18no) {                           setTimeout(function  { init(i18no, toasts); }, 1000);                       });                    };                };                const toastHook = function (toast) { mw.hook('dev.i18n').add(preload(toast)); };               mw.hook('dev.toasts').add(toastHook); });           /**             * Make light-theme Discord widget use dark-theme             */            ;(function  { const handleWidget = function (rail) { const widget = rail.querySelector('.discord-widget-container .widget'); if (widget) widget.classList.replace('widget-theme-light', 'widget-theme-dark'); return widget; };               mw.hook('Discord.widget').add(handleWidget); });           /**             * Responsive Mobile             * dev.fandom.com/wiki/Responsive_Mobile             */            ;(function  { var meta = document.querySelector('meta[name="viewport"]'); if (!meta) { meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); }               meta.setAttribute('content', 'width=device-width, initial-scale=1, user-scalable=yes'); });           /**             * Code Buttons             */            ;(function  { const page = config.wgPageName; const getFlag = function { const p1 = ['MediaWiki', 'User'].includes(page.split(':').shift); const p2 = page.endsWith('.js') || page.endsWith('.css'); return p1 && p2; };               if (!getFlag) return console.log(page, getFlag); const root = document.documentElement; const container = DOMTools.parseHTML(                   ' '                ); const buttons = []; const themes = ['material', 'vs2015', 'dracula']; function getTheme (id) { return themes.includes(id) && id || 'material'; }               function applyTheme (button) { const id = button.getAttribute('id'); const theme = getTheme(id); return function { button.blur; root.setAttribute('id', theme); };               }                function generateButtons  { if (buttons.length) return buttons; const len = themes.length; for (var i = 0; i < len; i++) { const id = themes[i]; const btn = DOMTools.parseHTML([                           '',                            id,                            ' '                        ].join('')); DOMTools.on(btn, 'click.code-button', applyTheme(btn)); buttons.push(btn); }                   return buttons; }               mw.hook('wikipage.content').add(function ($content) {                    if ($content.attr('id') !== 'mw-content-text') $content = $('#mw-content-text');                    if (!$content) return;                    DOMTools.appendAll(container, generateButtons);                    const $target = $content.find('#mw-clearyourcache');                    if (!$target) return;                    $target.append(container);                }); });           /**             * Change ace editor theme.             * @returns {void}             */            ;(function  { var tries = 5, theme = 'ace/theme/tomorrow_night', pageType = window.location.href.split('?')[0].split('.').pop, isEditPage = config.wgIsEditPage || window.location.search === '?action=edit'; if (!isEditPage || !['css', 'js', 'json', 'javascript'].includes(pageType)) return; mw.hook('wikipage.content').add(function themeAceEditor {                    var editor = DOMTools.query('#editarea.ace_editor');                    if (!window.ace || !editor && --tries > 0) return setTimeout(themeAceEditor, 1000);                    editor = window.ace.edit(editor);                    editor.setTheme(theme);                }); });           fired.set('DOMTools', true);        }); fired.set('loaded', true); };   /**     * @type {hookFunct} */   window.addOnloadHook(loaded); });
 * (function {

/** * @typedef {Object} Cookies */

/** * Parses the document's cookies into a readable object. * @alias getCookies * @returns {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] = decodeURIComponent(cookie.split('=')[1]); return cookies; }, {});           }        });        return window.cookies; }   return window.cookies; }

/*@end@*/