User:Arashiryuu0/wikia.js

/** * @namespace Personal_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 */ /** * Properties to attach to the element. * @typedef {Object} ElementProperties */

/** * The main controller for a hook. * @typedef {Object} remote * @property {Function} add * @property {Function} fire * @property {Function} remove */

/** * Initialization IIFE. * @returns {void} */   'use strict'; var version = mw.config.get('wgVersion'); if (version === '1.33.3' && window.UCP && window.UCP.localJS) return; var slice = Array.prototype.slice, toString = Object.prototype.toString, has = Object.prototype.hasOwnProperty, config = mw.config.get([           'wgPageName',            'wgNamespaceNumber'        ]), imports = [ {               type: 'script', articles: [ 'u:dev:MediaWiki:GlobalEditcount/code.js', 'u:dev:MediaWiki:UI-js/code.js', 'u:dev:MediaWiki:Toasts.js', 'u:bloodborne:MediaWiki:DOMTools.js', 'u:bloodborne:MediaWiki:Tooltips.js' ]           },            {                type: 'style', articles: [ 'u:dev:MediaWiki:FontAwesome.css', 'u:bloodborne:MediaWiki:Codeblocks.css', 'u:dev:MediaWiki:ModernWikiActivity.css', 'u:dev:MediaWiki:ModernProfile/Wall.css', 'u:dev:MediaWiki:ModernWikiActivity.css', 'u:dev:MediaWiki:ModernCommentsSection.css', 'u:dev:MediaWiki:ModernProfile/Masthead.css', 'u:dev:MediaWiki:FandomizedRailModules/code.css' ]           }        ],        fired = new mw.Map, Logger = Object.create(null); function typeOf (any) { return toString .call(any) .match(/\[object (\w+)\]/)[1] .toLowerCase; }   /**     * Callback to be ran once page is ready. * @alias ready */   function ready  { if (fired.exists('ready')) return; window.importArticles.apply(null, imports); /**        * Loading scripts through the mediawiki ResourceLoader. * @returns {void} */       ;(function  {            var base = 'https://reds-test.fandom.com/wiki/User:Arashiryuu0/sandbox';            var query = '?action=raw&ctype=text/javascript';            var queries = [                base + query,                base + '.javascript' + query            ];            function load (url) {                if (typeof url !== 'string') return;                mw.loader.load(url);            }            queries.forEach(load);        }); /**        * DOMTools module hook * @returns {remote} */       mw.hook('DOMTools').add(function (DOMTools) {            if (fired.exists('DOMTools')) return;            /**             * @namespace Utility             */            function getLevel (level) {                return ['log', 'info', 'warn', 'debug', 'error'].includes(level)                    ? level                    : 'log';            }            function _log (name, level) {                var type = getLevel(level);                return function  {                    var args = slice.call(arguments);                    var parts = [                        '%c[' + name + ']%c \u2014 %s',                        'color: #82AAFF;',                        'color: #F78C6A;',                        new Date.toUTCString                    ];                    console.group.apply(null, parts);                    console[type].apply(null, args);                    console.groupEnd; };           }            ['log', 'info', 'warn', 'debug', 'error'].forEach(function (level) {                Logger[level] = _log('User:Arashiryuu0/wikia.js', level);            }); function isObject (item) { return typeOf(item) === 'object'; }           /**             * createElement utility function * @param {string} type - The element tag to create. * @param {ElementProperties} properties * @returns {HTMLElement} */           function createElement (type, properties) { var nodeTypes = [1, 3]; if (typeof type !== 'string' || !isObject(properties)) return; function addStyle (element, _, styles) { var keys = Object.keys(styles); var len = keys.length; for (var i = 0; i < len; i++) { var style = keys[i]; DOMTools.css(element, style, styles[style]); }                   return element; }               function setText (element, _, value) { element.textContent = value; return element; }               function addAttribute (element, attribute, value) { if (attribute === 'text') return setText(element, attribute, value); element.setAttribute(attribute, value); return element; }               function addEvent (element, event, callback) { DOMTools.on(element, event, callback); return element; }               function addData (element, _, data) { var keys = Object.keys(data); for (var i = 0, len = keys.length; i < len; i++) { var key = keys[i]; element[_][key] = data[key]; }                   return element; }               function addChildren (element, _, children) { for (var i = 0, len = children.length; i < len; i++) { if (!nodeTypes.includes(children[i].nodeType)) continue; element.appendChild(children[i]); }                   return element; }               function processProps (element, props) { var keys = Object.keys(props); var len = keys.length; var actions = { 'text': setText, 'style': addStyle, 'class': addAttribute, 'dataset': addData, 'childNodes': addChildren };                   for (var i = 0; i < len; i++) { var prop = keys[i]; var val = props[prop]; if (DOMTools.isNil(val)) continue; var name = prop.split('.')[0]; var ns = prop.split('.')[1]; if (!DOMTools.isNil(actions[name])) { actions[name](element, prop, val); continue; } else if (!DOMTools.isNil(ns)) { addEvent(element, prop, val); continue; }                       element[prop] = val; }                   Object.defineProperty(element, 'props', {                        value: props,                        configurable: false                    }); return element; }               var element = document.createElement(type); return processProps(element, properties); }           /**             * Fixes wall conversations on Special:WikiActivity */           ;(function  {                if (!config.wgPageName.includes('WikiActivity')) return;                var article = DOMTools.query('.WikiaArticle');                var options = { childList: true, subtree: true };                var log = _log('WallConversations', 'log');                var counter = 0;                function iterate (node) {                    var sel = DOMTools.queryAll([ '.activity-ns-1201 > table,', '.activity-ns-2001 > table' ].join(''), node || document);                   function handleClass (element) {                        if (element.nodeType !== Node.ELEMENT_NODE) return;                        if (DOMTools.hasClass(element, 'wallfeed')) return;                        DOMTools.addClass(element, 'wallfeed');                        log('iteration complete: ' + counter, element);                        counter++;                    }                    sel.forEach(handleClass);                }                function filterNode (node) {                    if (node.nodeType !== Node.ELEMENT_NODE) return;                    if (!DOMTools.hasClass(node, 'activityfeed')) return;                    iterate(node);                }                function filterUpper (upper) {                    if (!upper.addedNodes) return;                    var len = upper.addedNodes.length;                    for (var i = 0; i < len; i++) filterNode(upper.addedNodes[i]); }               function processMutation (change) { filterUpper(change); }               function handleMutation (changes) { var len = changes.length; for (var i = 0; i < len; i++) processMutation(changes[i]); }               var e = new MutationObserver(handleMutation); iterate; e.observe(article, options); });           /**             * Appends utility buttons to the buttons in the header             */            ;(function { var selectors = [ '.wds-community-header__wiki-buttons', '.wds-button-group' ];               var headTarget = DOMTools.query(selectors.join(''), document); if (!headTarget) return; DOMTools.appendAll(headTarget, [                   createElement('a', { className: 'wds-button wds-is-squished wds-is-secondary', id: 'jsReturn', childNodes: [ createElement('span', {                               className: 'jsReturn',                                textContent: '\u2111',                            }) ],                       style: { fontSize: '20px', fontWeight: 400 },                       href: '/wiki/User:Arashiryuu0/wikia.js', title: 'Return to Personal JS' }),                   createElement('a', { className: 'wds-button wds-is-squished wds-is-secondary', id: 'cssReturn', childNodes: [ createElement('span', {                               className: 'cssReturn',                                textContent: '\u212D',                            }) ],                       style: { fontSize: '20px', fontWeight: 400 },                       href: '/wiki/User:Arashiryuu0/wikia.css', title: 'Return to Personal CSS' }),                   createElement('a', { className: 'wds-button wds-is-squished wds-is-secondary', id: 'purgePageButton', childNodes: [ createElement('span', {                               className: 'purgeButton',                                textContent: '\u262F',                            }) ],                       style: { fontSize: '20px', fontWeight: 400 },                       href: '?action=purge', title: 'Purge Page' }),                   createElement('a', { className: 'wds-button wds-is-squished wds-is-secondary', childNodes: [ createElement('span', {                               className: 'userReturn',                                textContent: '↩'                            }) ],                       style: { fontSize: '18px', fontWeight: 600 },                       href: '/wiki/User:Arashiryuu0', title: 'Return to User Page' }),                   createElement('a', { className: 'wds-button wds-is-squished wds-is-secondary', childNodes: [ createElement('span', {                               className: 'randomPage',                                textContent: '?'                            }) ],                        style: { fontSize: '18px', },                        dataset: { tracking: 'Special:Random' }, href: '/wiki/Special:Random', title: 'Random Page' })               ]);            });            /**             * Add custom profile tags             */            ;(function  { var profileHead = DOMTools.query('.UserProfileMasthead .masthead-info hgroup'); if (!profileHead) return; var tags = { 'Arashiryuu0': ['Valkyrie'] };               var tipText = { 'Valkyrie': 'Chooser of the Slain' };               var tagContainer = createElement('span', {                    className: 'custom-profile-tags'                }); var hasTags = function (name) { return has.call(tags, name); };               var removeTags = function (tagList) { for (var i = tagList.length - 1, len = 0; i >= len; i--) { var tag = tagList[i]; tag.parentElement.removeChild(tag); }               };                var addTags = function (tagList) { var delayedTooltip = function (tag, index) { window.TooltipModule.Tooltip(tag, tipText[tagList[index]], 'top', {}); };                   for (var i = 0, len = tagList.length; i < len; i++) { var tag = createElement('span', {                           className: 'tag ' + tagList[i],                            textContent: tagList[i]                        }); if (window.TooltipModule) { window.TooltipModule.Tooltip(tag, tipText[tagList[i]], 'top', {}); } else { setTimeout(delayedTooltip.bind(null, tag, i), 1000); }                       tagContainer.appendChild(tag); }               };                var h1 = profileHead.querySelector('h1'); var oldTags = profileHead.querySelectorAll('.tag'); if (!hasTags(h1.textContent)) return; if (oldTags.length) removeTags(oldTags); var newTags = tags[h1.textContent]; addTags(newTags); profileHead.appendChild(tagContainer); });           /**             * Adds a "hide" button toggle to article pages             */            ;(function  { if (config.wgNamespaceNumber !== 0) return; var element = { wrapper: DOMTools.query('.WikiaPageContentWrapper'), $wrapper: $('.WikiaPageContentWrapper'), target: DOMTools.query('.wds-community-header'), toggle: function (t) { element.$wrapper.toggle(200); DOMTools.toggleClass(element.wrapper, 'hidden'); DOMTools.text(t, this.getText); },                   getText: function  { return DOMTools.hasClass(element.wrapper, 'hidden') ? 'show' : 'hide'; }               };                var toggle = createElement('a', {                    id: 'togglePage',                    style: {                        position: 'relative',                        left: '2px',                        bottom: '2.2vh',                        color: 'whitesmoke',                        cursor: 'pointer',                        textTransform: 'uppercase'                    },                    textContent: element.getText,                    'click.pageToggle': function (e) {                        element.toggle(e.target);                    }                }); DOMTools.appendTo(element.target, toggle); });           /**             * Fixes buttons on Thread and Message Wall pages             */            ;(function  { var pages = ['Thread', 'Message_Wall']; if (!pages.includes(config.wgPageName.split(':')[0])) return; var sec = DOMTools.queryAll('.wikia-menu-button.secondary'); var len = sec.length; for (var i = 0; i < len; i++) DOMTools.removeClass(sec[i], 'secondary'); });           /**             * Adds the current day into the header             * Changes dropdowns to work on click and not hover             */            ;(function  { var lang = document.documentElement.lang; var date = { obj: new Date, target: DOMTools.query('.wds-community-header__local-navigation'), };               Object.defineProperty(date, 'current_day', {                    writable: false,                    configurable: false,                    value: date.obj.toLocaleDateString(lang, { weekday: 'long' })                }); Object.defineProperty(date, 'day', {                   configurable: false,                    value: createElement('a', { id: 'current-day', title: 'Today', target: '_blank', textContent: date.current_day })               });                var css = { ellipse: { id: 'EllipseFixCSS', type: 'text/css', selectors: [ [                               '.WikiaSiteWrapper', '.wds-community-header', '.wds-community-header__wiki-buttons', '>',                               '.wds-dropdown', '>',                               '.wds-dropdown__content,', '.wds-dropdown.wds-is-active::after,', '.wds-dropdown.wds-is-active::before,', '.wds-dropdown:hover::after,', '.wds-dropdown:hover::before' ],                           [                                '.wds-community-header__wiki-buttons', '>',                               '.wds-dropdown', '>',                               '.wds-button:hover' ],                           [                                '.WikiaSiteWrapper', '.wds-community-header', '.wds-community-header__wiki-buttons', '>',                               '.wds-dropdown.is-open', '>',                               '.wds-dropdown__content,', '.wds-dropdown.wds-is-active.is-open::after,', '.wds-dropdown.wds-is-active.is-open::before,', '.wds-dropdown.is-open:hover::after,', '.wds-dropdown.is-open:hover::before,', '.wds-dropdown.is-open::after,', '.wds-dropdown.is-open::before' ]                       ]                    },                    toggle: { id: 'ToggleCSS', type: 'text/css', selectors: [ [                               '.wds-dropdown.wds-is-active:not(.wds-no-chevron)::after,', '.wds-dropdown.wds-is-active:not(.wds-no-chevron)::before,', '.wds-dropdown' + ':not(.wds-is-touch-device):not(.wds-is-not-hoverable)' + ':hover:not(.wds-no-chevron)::after,', '.wds-dropdown' + ':not(.wds-is-touch-device):not(.wds-is-not-hoverable)' + ':hover:not(.wds-no-chevron)::before,', '.wds-community-header__local-navigation', '.wds-dropdown.wds-is-active', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown.wds-is-active', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown' + ':not(.wds-is-touch-device):not(.wds-is-not-hoverable):hover', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown:hover::after' ],                           [                                '.wds-community-header__local-navigation', '.wds-dropdown:hover', '.wds-dropdown__toggle-chevron' ],                           [                                '.wds-community-header__local-navigation', '.wds-dropdown:hover', '.wds-dropdown__toggle' ],                           [                                '.wds-dropdown.wds-is-active.is-open:not(.wds-no-chevron)::after,', '.wds-dropdown.wds-is-active.is-open:not(.wds-no-chevron)::before,', '.wds-dropdown.is-open' + ':not(.wds-is-touch-device):not(.wds-is-not-hoverable)' + ':hover:not(.wds-no-chevron)::after,', '.wds-dropdown.is-open' + ':not(.wds-is-touch-device):not(.wds-is-not-hoverable)' + ':hover:not(.wds-no-chevron)::before,', '.wds-community-header__local-navigation', '.wds-dropdown.wds-is-active.is-open', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown.wds-is-active.is-open', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown.is-open::before,', '.wds-community-header__local-navigation', '.wds-dropdown.is-open::after,', '.wds-community-header__local-navigation', '.wds-dropdown.is-open', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown.is-open' + ':not(.wds-is-touch-device):not(.wds-is-not-hoverable):hover', '.wds-dropdown__content,', '.wds-community-header__local-navigation', '.wds-dropdown.is-open:hover::after' ]                       ]                    },                    target: document.head };               Object.defineProperty(css.ellipse, 'rules', {                    configurable: false,                    value: [                        css.ellipse.selectors[0].join(' ') + ' { display: none; }',                        css.ellipse.selectors[1].join(' ') + ' { cursor: pointer; }',                        css.ellipse.selectors[2].join(' ') + ' { display: block !important; }'                    ]                }); Object.defineProperty(css.ellipse, 'stylesheet', {                   configurable: false,                    value: createElement('style', { id: css.ellipse.id, type: css.ellipse.type, textContent: css.ellipse.rules.join('\n') })               });                Object.defineProperty(css.toggle, 'rules', {                    configurable: false,                    value: [                        css.toggle.selectors[0].join(' ') + ' { display: none; }',                        css.toggle.selectors[1].join(' ') + ' { transform: none; '                        + 'transition: transform 200ms '                        + 'cubic-bezier(0.6, -0.28, 0.74, 0.05); }',                        css.toggle.selectors[2].join(' ') + ' { transform: none; }',                        css.toggle.selectors[3].join(' ') + ' { display: block !important; }'                    ]                }); Object.defineProperty(css.toggle, 'stylesheet', {                   configurable: false,                    value: createElement('style', { id: css.toggle.id, type: css.toggle.type, textContent: css.toggle.rules.join('\n') })               });                var els = { selectors: [ [                           '.wds-community-header__local-navigation', '.wds-dropdown', '.wds-dropdown__toggle-chevron' ],                       [                            '.wds-community-header__wiki-buttons', '>',                           '.wds-dropdown', '>',                           '.wds-button' ]                   ]                };                Object.defineProperties(els, {                    toggles: {                        configurable: false,                        value: DOMTools.queryAll(els.selectors[0].join(' '))                    },                    headerButton: {                        configurable: false,                        value: DOMTools.query(els.selectors[1].join(' '))                    }                }); function ellipse (me) { var root = me.parentElement, content; content = root.querySelector('.wds-dropdown__content'); return function { $(content).toggle('fast'); DOMTools.toggleClass(root, 'is-open'); };               }                function chevron (me) { var rotation = 'rotateX(180deg)', root = me.parentElement.parentElement, content, ro, ts; content = root.querySelector('.wds-dropdown__content'); return function { $(content).toggle('fast'); DOMTools.toggleClass(root, 'is-open'); ts = me.style.transform; ro = ts !== rotation ? rotation : 'none'; DOMTools.css(me, 'transform', ro); };               }                function addChevronListener (element) { if (!element) return; DOMTools.on(element, 'click.toggle', chevron(element)); }               date.target.appendChild(date.day); DOMTools.appendAll(css.target, [                   css.ellipse.stylesheet,                    css.toggle.stylesheet                ]); if (els.headerButton) { var btn = els.headerButton; btn.setAttribute('title', 'Options'); DOMTools.css(btn, 'padding', '11px 3px'); DOMTools.on(btn, 'click.toggle', ellipse(btn)); }               els.toggles.forEach(addChevronListener); });           /**             * Add account creation dates to the global edit count on user profiles.             */            ;(function  { var base = DOMTools.query('#UserProfileMasthead'); if (!base) return; function getData (user) { var url = mw.util.wikiScript('api'); url += '?action=query&list=users&usprop=registration'; url += '&ususers=' + user + '&format=json'; function cb (resolve, reject) { var xhr = new XMLHttpRequest; function load { var parsed = JSON.parse(xhr.responseText); resolve(parsed); }                       function error (e) { reject(e, xhr); }                       xhr.addEventListener('load', load); xhr.addEventListener('error', error); xhr.open('GET', url, true); xhr.send; }                   return new Promise(cb); }               function appendToGlobalCount (data) { var d = DOMTools.getProp(data, 'query.users.0.registration'), date = new Date(d).toLocaleDateString('en-us', {                           day: '2-digit',                            month: 'long',                            year: 'numeric'                        }), target = DOMTools.query('.globaledit-label', base), clone; if (!target) return Promise.reject('Unable to find label.'); clone = target.cloneNode(true); DOMTools.text(clone, 'global edits since account creation'); DOMTools.appendAll(clone, [                       document.createElement('br'),                        document.createTextNode(date)                    ]); target.replaceWith(clone); return Promise.resolve(clone); }               function removeLinkedCSS  { function filter (l) { var ref = l.href; return ref && ref.includes('GlobalEditcount'); }                   var links = DOMTools.queryAll('link[type="text/css"][rel="stylesheet"]'), link = links.find(filter); try { link.parentElement.removeChild(link); return Promise.resolve(true); } catch(e) { return Promise.reject(e); }               }                /**                 * @type {hookCallback} */               function init (GlobalEditcount) { getData(GlobalEditcount.user) .then(appendToGlobalCount, Logger.error) .then(removeLinkedCSS, Logger.error); }               mw.hook('GlobalEditcount.loaded').add(init); });           /**             * Fix avatars in Thread History pages.             */            ;(function  { var fixDimensions, avatars; if (!document.getElementById('WallThreadHistory')) return; fixDimensions = function (avatar) { var src = avatar.getAttribute('src'); avatar.setAttribute('height', '50'); avatar.setAttribute('width', '50'); avatar.setAttribute('src', src.slice(0, -2) + 50); };               avatars = DOMTools.queryAll('.WallHistory #WallThreadHistory .avatar'); avatars.forEach(fixDimensions); });           fired.set('DOMTools', true);        }); fired.set('ready', true); }   function wait  { if (document.readyState !== 'complete') return setTimeout(wait, 1000); setTimeout(ready, 0); }   if (version === '1.19.24') { window.addOnloadHook(ready); } else { window.UCP = window.UCP || {}; window.UCP.localJS = { cache: fired, mwVer: version };       wait; } });
 * (function {

/*@end@*/