User:Thundercraft5/common.js

/* jshint esversion: 5, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, undef: true, undef: true, unused: true, browser: true, jquery: true, onevar: true, eqeqeq: true, multistr: true, maxerr: 999999, -W082, -W084 /* global mw, ignoreModules */

//Global variables var pagePathname = mw.config.get('wgArticlePath').replace('$1', ''), sitename = mw.config.get('wgSiteName'), userGroups = mw.config.get('wgUserGroups'), namespace = mw.config.get("wgNamespaceNumber"), pagename = mw.config.get('wgPageName'), wikiUrl = mw.config.get('wgServer').replace(/https?:\/\//g, ''), server = mw.config.get('wgServer'), sep = ' | ', sep2 = ' &bull; ';

// AF log filtering $(function {	if (mw.config.get('wgPageName') !== 'Special:AbuseLog') return;	var checked;	addFilter;	mw.util.addCSS('.hidden { display: none !important; }');	function addFilter {		$('.mw-specialpage-summary').after($(' ', {			html: [				$(' ', { text: "Filters" }),				$(' ', { html: [ $(' ', {							type: "checkbox",							name: "toggleSpamFilters",							id: "AF-filter-checkbox-toggleSpamFilters",							checked: !['undefined', 'null'].includes(typeof(checked)) ? checked : false,							on: {								change: function {									checked = this.checked;									mw.util.$content.children('ul')[0].querySelectorAll('li').forEach(function(el) { if (!el.textContent.match(/spam/i)) el.classList.toggle('hidden'); });								},							},							css: {								cursor: "pointer",							},						}), $(' ', {							type: "checkbox",							for: "AF-filter-checkbox-toggleSpamFilters",							id: "AF-filter-label-toggleSpamFilters",							text: "Show only possible spam hits",							css: {								cursor: "pointer",							},						}), ],				}),			],		}));	}	window.ajaxCallAgain = window.ajaxCallAgain || [];	window.ajaxCallAgain.push(addFilter, function { mw.util.$content.children('ul')[0].querySelectorAll('li').forEach(function(el) {			if (!el.textContent.match(/spam/i)) el.classList.toggle('hidden');		}); }); }); function makeLink(link, text, query, id) { query = query ? new mw.Uri.extend(query).getQueryString : undefined; return $('', {		id: id,		href: pagePathname + link + (query ? "?" + query : ""),		title: link,		html: text || link,	}); } // Global JS files list if (pagename.match(/^User:Thundercraft5\/(global|common)\.(js|css)\/?/)) { var isCSS = /\.css$/.test(pagename), prefix = isCSS ? 'css' : 'js', isLocal = /^User:Thundercraft5\/common\.(js|css)/.test(pagename), target = isLocal ? 'global' : 'common', upperCaseTarget = target.replace(/^(.)(.+)/, function(_, $1, $2) { 			return $1.toUpperCase + $2;		}), invertedPrefix = !isCSS ? 'css' : 'js'; $.get('https://ucp.fandom.com/wiki/Special:PrefixIndex/User:Thundercraft5/global.' + prefix + '/').then(function(data) {	   var arr = [];	    $(data).find('.mw-prefixindex-list > li > a').each(function { var title = $(this).attr('title'); if (!ignoreModules.some(function(v) { return title.match(v); })) arr.push(title); });	   return arr;	}).then(function(arr) {		var $list = $('', { css: { 'list-style': 'square', 'margin': '0.4em 0px 0.5em 2.5em', }		});		$('#firstHeading').html($('#firstHeading').html.replace(/^User:Thundercraft5\//g, 'JS: ').replace('global.js/', ''));

arr.forEach(function(v) {			$list.append( $('', {					css: {						'line-height': '20px',						'font-size': '14px',					},					html: [						makeLink(v, v.replace(/User:Thundercraft5\/(global|common)\.(js|css)\//i, '')),						$(' ', { html: [ ' (',								makeLink(v, 'edit', { action: 'edit' }),								sep2,								makeLink(v, 'latest diff', { diff: 'cur' }),								sep2,								makeLink(v, 'hist', { action: "history" }),								sep2,								makeLink(v, 'purge', { action: "purge" }),								')', ]						}),					],				})			);		});		$('#mw-clearyourcache') .after(				$(' ', { id: prefix.toUpperCase + "Interface", html: [ $(' ', {							id: prefix.toUpperCase + "Interface__header",							html: [								"Global " + prefix.toUpperCase + " Interface",								$(' ', { css: { 'font-size': '20px', },									html: [ ' (',										makeLink('User:Thundercraft5/global.' + prefix, 'Return to main page'),										sep2,										makeLink('User:Thundercraft5/global.' + invertedPrefix, 'Switch to ' + invertedPrefix.toUpperCase),										')', ],								}),								$(' ', {									css: { 'font-size': '16px', },									html: [ ' (',										makeLink('User:Thundercraft5/global.' + prefix, 'edit', { action: 'edit' }),										sep2,										makeLink('User:Thundercraft5/global.' + prefix, 'latest diff', { diff: 'cur' }),										sep2,										makeLink('User:Thundercraft5/global.' + prefix, 'hist', { action: "history" }),										sep2,										makeLink('User:Thundercraft5/global.' + prefix, 'purge', { action: "purge" }),										')', ]								})							]						}),						$list, "(",						makeLink('User:Thundercraft5/' + target + '.js', upperCaseTarget + ' JS'),						sep2,						makeLink('User:Thundercraft5/' + target + '.css', upperCaseTarget + ' CSS'),						")", $(' ', {							css: {								'margin-top': "15px",							},							html: [								"Page Code",								$(' ', { html: [ ' (',										makeLink(pagename, 'edit', { action: 'edit' }),										sep2,										makeLink(pagename, 'latest diff', { diff: 'cur' }),										sep2,										makeLink(pagename, 'hist', { action: "history" }),										sep2,										makeLink(pagename, 'purge', { action: "purge" }),										')', ]								})							]						})					],				})			);		$('#mw-clearyourcache').remove; }); }