User:Arashiryuu0/common.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 // jshint esversion: 6 /* globals mw */ /** * The callback to be fired when ready. * @callback hookFunct * @param {...any} * @returns {void} */ /** * A Logger method. * @callback logMethod * @param {...any} * @returns {void} */ /** * Properties to attach to the element. * @typedef {Object} ElementProperties */ /** * Initialization IIFE. * @returns {void} */   'use strict'; if (window.UCP && window.UCP.localJS) return; /**    * Cache of fired hooks. */   const fired = new mw.Map; /**    * @type {hookFunct} * @returns {void} */   const loaded = function  { if (fired.exists('loaded')) return; const slice = Array.prototype.slice; const toString = Object.prototype.toString; const levels = ['log', 'dir', 'info', 'warn', 'debug', 'error']; window.importArticles.apply(null, [			{				type: 'style',				articles: [					'u:bloodborne:User:Arashiryuu0/common.css'				]			},			{				type: 'script',				articles: [					'u:dev:MediaWiki:Preact.js'				]			}		]); /**        * Fetches levels to be used for logging. * @name getLevel * @param {string|number} level * @returns {string} */       const getLevel = function (level) { const base = 'log'; if (typeof level !== 'string' && typeof level !== 'number') return base; if (typeof level === 'number') return levels[level] || base; return levels.includes(level) ? level : base; };       /**         * Creates log methods. * @name makeLog * @param {string|number} level * @param {string} name * @returns {logMethod} */       const makeLog = function (level, name) { const lvl = getLevel(level); return function { const args = slice.call(arguments); const time = new Date.toUTCString; const parts = [ '%c[' + name + ']%c \u2014 %s', 'color: #82AAFF;', 'color: #F78C6A;', time ];               console.group.apply(null, parts); console[lvl].apply(null, args); console.groupEnd; };       };        const Logger = {}; levels.forEach(function (level) {       	Logger[level] = makeLog(level, 'User:Arashiryuu0/common.js');        }); Object.defineProperty(Logger, Symbol.toStringTag, {       	value: 'Logger'        }); /**        * Determines if something is undefined or null. */       const isNil = function (anything) { return anything === undefined || anything === null; };       /**         * Simple polyfill for the nullish coalescing operator (??) */       const nullishCoalesce = function (expected, fallback) { return isNil(expected) ? fallback : expected; };       /**         * Safely traverses an object, returns undefined if a property does not exist. */       const getProp = function (obj, path) { return path.split(/\s?\.\s?/).reduce(function (o, prop) {       		return o && o[prop];        	}, obj); };       /**		 * Gets a more accurate description of an object than `typeof`. * @name typeOf * @param {*} item * @returns {string} */		const typeOf = function (item) { return toString .call(item) .match(/\[object (\w+)\]/i)[1] .toLowerCase; };       /**         * Checks whether something is a Node instance. * @name isNode * @param {*} tester * @returns {boolean} */       function isNode (tester) { return tester instanceof Node; }       /**         * Loading scripts through the ResourceLoader via mw.loader * @returns {void} */       ;(function  {            const sUri = 'https://reds-test.fandom.com/wiki/User:Arashiryuu0/sandbox';            const sQuery = '?ctype=text/javascript&action=raw';			const queries = [				sUri + sQuery,				sUri + '.javascript' + sQuery			];            const load = function (url) {                if (typeof url !== 'string') return;                mw.loader.load(url);            };            queries.forEach(load);        }); ;(function {	    	const bannerItems = [	    		document.querySelector('.wds-global-navigation__logo')	    	].concat(slice.call(document.querySelectorAll('.wds-global-navigation__link')));	    	bannerItems.forEach(function (item) { if (!item) return; item.setAttribute('tabindex', '-1'); });	   });	    ;(function  {	    	if (fired.exists('buttons')) return;	    	const wdsButtons = document.querySelectorAll('.wiki-tools.wds-button-group');	    	if (!wdsButtons.length) return;	    	const firstChild = wdsButtons[0].firstElementChild;	    	const createElement = function (type, props) {	    		if (typeof type !== 'string' || typeOf(props) !== 'object') return;	    		const element = document.createElement(type);	    		Object.assign(element, props);	    		return element;	    	};	    	const buttons = [	    		createElement('a', { className: firstChild.className.replace('wiki-tools__search', 'wiki-tools__user-js'), textContent: 'JS', href: '/wiki/User:Arashiryuu0/common.js' }),	   		createElement('a', { className: firstChild.className.replace('wiki-tools__search', 'wiki-tools__user-css'), textContent: 'CSS', href: '/wiki/User:Arashiryuu0/common.css' }),	   		createElement('a', { className: firstChild.className.replace('wiki-tools__search', 'wiki-tools__random'), textContent: '?', href: '/wiki/Special:Random' })	   	];	    	wdsButtons.forEach(function (wds) { buttons.map(function (button) {		   		return button.cloneNode(true);		    	}).forEach(function (button) {		    		if (!button) return;		    		wds.appendChild(button);		    	}); // fix button positioning // layout should be: // search, discussions, recent changes, theme, my buttons, dropdown wds.appendChild(wds.querySelector('.wds-dropdown')); });	   	fired.set('buttons', true);	    }); window.UCP.Logger = Logger; window.UCP.Utils = { type: typeOf, isNil: isNil, isNode: isNode, getProp: getProp, nullishCoalesce: nullishCoalesce };       fired.set('loaded', true); };	/**	 * Waits for the document to finish loading and defers callback execution. * @returns {void} */	function wait { if (document.readyState !== 'complete') return setTimeout(wait, 1000); mw.hook('window.ready').add(loaded); }	window.UCP = window.UCP || {}; window.UCP.localJS = { cache: fired }; wait; }); /*@end@*/
 * (function {