User:Arashiryuu0/wikia.js

/** * @namespace Personal_JS */ 'use strict';

/** * Prepares a callback for when fandom is ready. * @param {function} hookFunct callback function to execute when everything is ready. * @returns {void} */ window.addOnloadHook(function {    const $ = window.jQuery;    const mw = window.mw;    const slice = Array.prototype.slice;    const has = Object.prototype.hasOwnProperty;    const toString = Object.prototype.toString;    const isObject = function (item) {        return toString.call(item) === '[object Object]';    };    const levels = ['log', 'info', 'warn', 'debug', 'error'];    const getLevel = function (level) {        return levels.includes(level)            ? level            : 'log';    };    const _log = function (level, name) {        const lvl = getLevel(level);        return function  {            const args = slice.call(arguments);            const time = new Date.toUTCString;            args.unshift('%c[' + name + '] %c%s\n\u2014', 'color: #82AAFF;', 'color: #C792EA;', time);            return console[lvl].apply(null, args);        };    };    const config = mw.config.get([ 'wgTitle', 'wgPageName', 'wgNamespaceNumber' ]);   const imports = [        {            type: 'script',            articles: [                'u:dev:Toasts.js',                'u:dev:UI-js/code.js',                'u:dev:I18n-js/code.js',                'u:dev:HeaderLinks/code.js',                'u:dev:GlobalEditcount/code.js',                'u:bloodborne:DOMTools.js',                'u:bloodborne:Tooltips.js',                'u:bloodborne:JSHighlightFixes.js'            ]        },        {            type: 'style',            articles: [                'u:dev:MediaWiki:FontAwesome.css',                'u:dev:MediaWiki:ModernWikiActivity.css',                'u:dev:MediaWiki:ModernProfile/Masthead.css',                'u:dev:MediaWiki:ModernProfile/Wall.css',                'u:dev:MediaWiki:ModernCommentsSection.css',                'u:dev:MediaWiki:ModernWikiActivity.css',                'u:dev:MediaWiki:FandomizedRailModules/code.css' ]       }    ];    const logT = _log('log', 'Arashiryuu0/wikia.js'); const errT = _log('error', 'Arashiryuu0/wikia.js'); window.tagList = { 'Elkian': '16th Ranked Exceed', 'Old Deus': 'Wiki Administration', 'Staff': 'Fandom Staff', 'Tet': 'The One True God', '『　』': 'Blank' };   window.importArticles.apply(this, imports); mw.hook('DOMTools').add(function (DOMTools) {       /**         * Utility         */        function isNil (anything) {            return typeof anything === 'undefined' || anything === null;        }        function createElement (type, properties) {            const nodeTypes = [1, 3];            if (typeof type !== 'string' || !isObject(properties)) return;            function addStyle (element, _, styles) {                const keys = Object.keys(styles);                const len = keys.length;                for (var i = 0; i < len; i++) {                    const style = keys[i];                    if (typeof style !== 'string') continue;                    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) { for (const i in data) element[_][i] = data[i]; return element; }           function addChildren (element, _, children) { for (var i = 0, len = children.length; i < len; i++) { if (!nodeTypes.includes(children[i].nodeType)) continue; $a(element, children[i]); }               return element; }           function processProps (element, props) { const keys = Object.keys(props); const len = keys.length; const actions = { 'text': setText, 'style': addStyle, 'class': addAttribute, 'dataset': addData, 'childNodes': addChildren };               for (var i = 0; i < len; i++) { const prop = keys[i]; const val = props[prop]; if (isNil(val)) continue; const name = prop.split('.')[0]; const ns = prop.split('.')[1]; if (!isNil(actions[name])) { actions[name](element, prop, val); continue; } else if (!isNil(ns)) { addEvent(element, prop, val); continue; }                   element[prop] = val; }               Object.defineProperty(element, 'props', {                    value: props,                    configurable: false                }); return element; }           const element = document.createElement(type); return processProps(element, properties); }       function $$ (selector) { return document.querySelectorAll(selector); }       function $_ (selector) { return document.querySelector(selector); }       function $a (target, element) { return target.appendChild(element); }       function $every (targets) { if (!targets || !Array.isArray(targets)) return; function append (list) { if (!list || !Array.isArray(list)) return; $all(list.shift, list); }           const len = targets.length; for (var i = 0; i < len; i++) append(targets[i]); }       function $all (target, elements) { if (!target) return; if (!elements || !Array.isArray(elements)) return; const len = elements.length; for (var i = 0; i < len; i++) $a(target, elements[i]); }       /**         * Editcount */       ;(function {            const profile = $_('.UserProfileMasthead');            if (!profile) return;            const username = config.wgTitle.indexOf('Contributions/') !== -1                ? config.wgTitle.replace('Contributions/', '')                : config.wgTitle;            const element = createElement('li', { dataset: { id: 'editcount' }, childNodes: [ createElement('a', {                       text: 'Editcount',                        href: '/wiki/Special:Editcount/' + username,                        title: 'Special:Editcount/' + username                    }) ]           });            const tabs = $_('.tabs-container > ul.tabs');            $a(tabs, element);        }); /**        * 0         */        ;(function {            if (!$_('.UserProfileMasthead')) return;            const o = {                target: $_('.masthead-info hgroup'),                tags: DOMTools.queryAll('.masthead-info .tag'),                rights: {                    'Arashiryuu0': ['Elkian', '『　』'],                    'Robyn Grayson': ['Old Deus']                },                name: function {                    return DOMTools.text(DOMTools.getProp(this.target, 'children.0'));                },                remove: function(item) {                    return item.parentElement.removeChild(item);                },                addTags: function(text) {                    const tag = createElement('span', { className: 'tag', textContent: text });                   return DOMTools.appendTo(o.target, tag);                }            };            if (!has.call(o.rights, o.name)) return;            if (o.tags.length) o.tags.forEach(o.remove);            o.rights[o.name].forEach(o.addTags);        }); /**        * 1         */        ;(function {            if (!config.wgPageName.includes('WikiActivity')) return;            const log = _log('log', 'WallConversations');            const article = $_('.WikiaArticle');            const options = { childList: true, subtree: true };            var counter = 0;            function iterate(node) {                var sel = DOMTools.queryAll([ '.activity-ns-1201 > table,', '.activity-ns-2001 > table' ].join(''), node || document);               function handleClass(element, index) {                    if (element.nodeType !== 1) return;                    if (DOMTools.hasClass(element, 'wallfeed')) return;                    DOMTools.addClass(element, 'wallfeed');                    log('iteration complete: ' + counter, element);                    counter++;                }                sel.forEach(handleClass);            }            function filterUpper(upper) {                if (!upper.addedNodes) return;                const len = upper.addedNodes.length;                for (var i = 0; i < len; i++) filterNode(upper.addedNodes[i]);            }            function filterNode(node) {                if (node.nodeType !== 1) return;                if (!DOMTools.hasClass(node, 'activityfeed')) return;                iterate(node);            }            function processMutation(change) { filterUpper(change); }           function handleMutation(changes) { for (const change in changes) processMutation(changes[change]); }           const e = new MutationObserver(handleMutation); log('iterating...'); iterate; e.observe(article, options); });       /**         * 2         */        ;(function { const headTarget = $_('.wds-community-header__wiki-buttons.wds-button-group'); if (!headTarget) return; $all(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: '20px', fontWeight: 400 },                   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' })           ]);        });        ;(function { if (config.wgNamespaceNumber !== 0) return; const element = { target: $_('.wds-community-header'), wrapper: $_('.WikiaPageContentWrapper'), $wrapper: $('.WikiaPageContentWrapper'), 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'; }           };            function onClick (e) { element.toggle(e.target); }           const toggle = createElement('a', {                 id: 'toggle-page',                 textContent: element.getText,                style: {                    position: 'relative',                    left: '2px',                    bottom: '1.2vh',                    color: 'whitesmoke',                    cursor: 'pointer',                    textTransform: 'uppercase'                },                'click.toggle-page': onClick            }); $a(element.target, toggle); });       /**         * 3         */        ;(function { const lang = document.documentElement.lang; const date = { obj: new Date, target: $_('.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 })           });            const 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') })           });            const 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: $_(els.selectors[1].join(' '))                }            }); function ellipse (me) { const root = me.parentElement; const content = root.querySelector('.wds-dropdown__content'); return function { $(content).toggle('fast'); DOMTools.toggleClass(root, 'is-open'); };           }            function chevron (me) { const rotation = 'rotateX(180deg)'; const root = me.parentElement.parentElement; const content = root.querySelector('.wds-dropdown__content'); return function { $(content).toggle('fast'); DOMTools.toggleClass(root, 'is-open'); const ts = me.style.transform; DOMTools.css(me, 'transform', ts !== rotation ? rotation : 'none'); };           }            function addChevronListener (element) { if (!element) return; DOMTools.on(element, 'click.toggle', chevron(element)); }           $a(date.target, date.day); DOMTools.appendAll(css.target, [               css.ellipse.stylesheet,                css.toggle.stylesheet            ]); if (els.headerButton) { els.headerButton.setAttribute('title', 'Options'); DOMTools.css(els.headerButton, 'padding', '11px 3px'); DOMTools.on(els.headerButton, 'click.toggle', ellipse(els.headerButton)); }           els.toggles.forEach(addChevronListener); });       ;(function { const base = DOMTools.query('#UserProfileMasthead'); if (!base) return; const onError = _log('error', 'GlobalEditCount'); function getData(user) { const url = [ mw.util.wikiScript('api'), '?action=query&list=users&usprop=registration', '&ususers=' + user + '&format=json' ].join(''); function cb(resolve, reject) { const xhr = new XMLHttpRequest; function load { resolve(JSON.parse(xhr.responseText)); }                   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) { const d = DOMTools.getProp(data, 'query.users.0.registration'); const date = new Date(d).toLocaleDateString('en-us', {                   day: '2-digit',                    month: 'long',                    year: 'numeric'                }); const target = DOMTools.query('.globaledit-label', base); if (!target) return Promise.reject(new Error('Unable to find label.')); const 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 { const links = DOMTools.queryAll('link[type="text/css"][rel="stylesheet"]'); function filterLinks(l) { return l.href && l.href.includes('GlobalEditcount'); }               const link = links.find(filterLinks); try { link.parentElement.removeChild(link); return Promise.resolve(true); } catch(e) { return Promise.reject(e); }           }            function done(toasts) { return function { toasts.success('Appended account creation date to global editcount.'); return Promise.resolve(window.dev.toasts); };           }            function init(values) { const GEC = values[0]; const toasts = values[1]; const ui = values[2]; return getData(GEC.user) .then(appendToGlobalCount, onError) .then(removeLinkedCSS, onError) .then(done(toasts), onError); }           function isUiLoaded { return new Promise(function(resolve, reject) {                   mw.hook('dev.ui').add(function(ui) { if (!ui) return reject(ui); resolve(ui); });               });            }            function isToastsLoaded { return new Promise(function(resolve, reject) {                   mw.hook('dev.toasts').add(function(toasts) { if (!toasts) return reject(toasts); resolve(toasts); });               });            }            function isGlobalEditcountLoaded { return new Promise(function(resolve, reject) {                   mw.hook('GlobalEditcount.loaded').add(function(GEC) { if (!GEC) return reject(GEC); resolve(GEC); });               });            }            function allLoaded { return Promise.all([                   isGlobalEditcountLoaded,                    isToastsLoaded,                    isUiLoaded                ]); }           allLoaded.then(init, onError); });       ;(function { if (!document.getElementById('WallThreadHistory')) return; const fixDimensions = function(avatar) { const src = avatar.getAttribute('src'); avatar.setAttribute('height', '50'); avatar.setAttribute('width', '50'); avatar.setAttribute('src', src.slice(0, -2) + 50); };           const avatars = DOMTools.queryAll('.WallHistory #WallThreadHistory .avatar'); avatars.forEach(fixDimensions); });   }); });

/*@end@*/