User:Arashiryuu0/wikia.js

/** * @namespace Personal_JS */   var has = Object.prototype.has, slice = Array.prototype.slice, config = mw.config.get([           'wgPageName',            'wgNamespaceNumber'        ]); importArticles({       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'        ]    }); importArticles({       type: 'script',        articles: [            'u:dev:GlobalEditcount/code.js',            'u:bloodborne:DOMTools.js',            'u:bloodborne:Tooltips.js'        ]    }); function log { var args = slice.call(arguments), time = new Date.toUTCString; args.unshift('%c[Log] %s\n\u2014', 'color: #82AAFF; text-shadow: 0 2px 3px black;', time); return console.log.apply(this, args); }   function err  { var args = slice.call(arguments), time = new Date.toUTCString; args.unshift('%c[Error] %s\n\u2014', 'color: #89DDF3; text-shadow: 0 2px 3px black;', time); return console.error.apply(this, args); }   function isNil (anything) { return typeof anything === 'undefined' || anything === null; }   function createElement (type, properties) { var nodeTypes = [1, 3], element; if (typeof type !== 'string') return; if (typeof properties !== 'object') return; if (properties.constructor.name !== 'Object') return; function addStyle (element, _, styles) { var keys = Object.keys(styles), len = keys.length, style, i;           for (i = 0; i < len; i++) { 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, value); element.setAttribute(attribute, value); return element; }       function addEvent (element, event, callback) { DOMTools.on(element, event, callback); return element; }       function addData (element, _, data) { for (var 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; DOMTools.appendTo(element, children[i]); }           return element; }       function processProps (element, props) { var keys = Object.keys(props), len = keys.length, prop, name, val, ns, i;           var actions = { 'text': setText, 'style': addStyle, 'class': addAttribute, 'dataset': addData, 'childNodes': addChildren };           for (i = 0; i < len; i++) { prop = keys[i]; val = props[prop]; if (isNil(val)) continue; name = prop.split('.')[0]; 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; }       element = document.createElement(type); return processProps(element, properties); }   function wait  { if (!has.call(window, 'DOMTools')) return setTimeout(wait, 1000); init; }   function init  { /**        * Fixes wall conversations on Special:WikiActivity */       ;(function  {            if (!config.wgPageName.includes('WikiActivity')) return;            var article = DOMTools.query('.WikiaArticle'),                options = { childList: true, subtree: true };            function iterate  {                var sel = DOMTools.queryAll([ '.activity-ns-1201 > table,', '.activity-ns-2001 > table' ].join(''));               function handleClass (element, index) {                    if (element.nodeType !== 1) return;                    if (DOMTools.hasClass(element), 'wallfeed') return;                    DOMTools.addClass(element, 'wallfeed');                    log('iteration complete: ' + index, element);                }                sel.forEach(handleClass);            }            function filterUpper (upper) {                var i, len;                if (!upper.addedNodes) return;                len = upper.addedNodes.length;                for (i = 0; i < len; i++) filterNode(upper.addedNodes[i]);            }            function filterNode (node) {                if (node.nodeType !== 1) return;                if (!DOMTools.hasClass(node, 'activityfeed')) return;                iterate;            }            function processMutation (change) {                filterUpper(change); }           function handleMutation (changes) { for (var change in changes) processMutation(changes[change]); }           var e = new MutationObserver(handleMutation); log('iterating...'); iterate; e.observe(article, options); });       /**         * Adds utility buttons.         */        ;(function  { var selectors = [ '.wds-community-header__wiki-buttons', '.wds-button-group' ];           var headTarget = DOMTools.query(selectors.join('')); 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' })           ]);        });        /**         * Adds account creation date to global edit count.         */        ;(function  { var base = DOMTools.query('#UserProfileMasthead'), user, url; if (!base) return; user = DOMTools.text(DOMTools.query('hgroup h1', base)); url = mw.util.wikiScript('api'); url += '?action=query&list=users&usprop=registration'; url += '&ususers=' + user + '&format=json'; function getData { function cb (resolve, reject) { var 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) { 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(new Error('Couldn\'t 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  { var links = DOMTools.queryAll('link[type="text/css"][rel="stylesheet"]'), link; function filterLinks (linkElement) { return linkElement.href && linkElement.href.includes('GlobalEditcount'); }               link = links.find(filterLinks); try { link.parentElement.removeChild(link); return Promise.resolve(true); } catch(e) { return Promise.reject(e); }           }            getData .then(appendToGlobalCount, err) .then(removeLinkedCSS, err); });       /**         * Append current day to header.         */        ;(function  { var lang = document.documentElement.lang, date = { obj: new Date, target: DOMTools.query('.wds-community-header__local-navigation') };           DOMTools.appendTo(date.target, DOMTools.parseHTML( '' + date.obj.toLocaleDateString(lang, { weekday: 'long' }) + '' ));       });    }    addOnloadHook(wait); }); /*@end@*/
 * (function {