User:Asteroid pirate/global.js

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:PageCreator/code2.js',    	'u:dev:MediaWiki:LastEdited/code.js',        'u:dev:MediaWiki:CodeQuickLinks/code.js',    	'u:dev:MediaWiki:MinimalTemplateClassification.js',        'u:dev:MediaWiki:TemplatesUsedModule.js',        'u:dev:MediaWiki:MobileEdittools.js',        'u:dev:MediaWiki:UCXSearchBar.js',        'u:dev:MediaWiki:DataTables.js',        'u:dev:MediaWiki:BlockSummary.js',        'u:dev:MediaWiki:InterwikisOnSpecialPages.js',        'u:dev:MediaWiki:ListFiles/code.js',        'u:dev:MediaWiki:MassNullEdit/code.js',    ] });

/*	Appends two buttons to the edit tools to copy the title with/without namespace Author: Caburum & Thundercraft5 Based on code by: RheingoldRiver See also: w:c:dev:CopyTitle (the original script this was from before being modified)

$(function {	if (window.CopyTitleLoaded) {return;}	window.CopyTitleLoaded = true;

function init(i18n) { function getSVG(id, ns) { return '' + ' ' + i18n.msg(id).escape + ' ' + '<path d="M1280 384L1280 384c-40 0-82.7 13.3-128 40V96l0 0c0-26.7-9.3-49.3-28-68s-41.3-28-68-28H640l0 0c-26.7 0-56 6.7-88 20 s-57.3 29.3-76 48L68 476l0 0c-18.7 18.7-34.7 44-48 76S0 613.3 0 640v672l0 0c0 26.7 9.3 49.3 28 68s41.3 28 68 28h544v288l0 0 c0 26.7 9.3 49.3 28 68s41.3 28 68 28h960l0 0c26.7 0 49.3-9.3 68-28s28-41.3 28-68V480l0 0c0-26.7-9.3-49.3-28-68s-41.3-28-68-28 H1280z M1152 896H853l299-299V896z M512 512H213l299-299V512z M708 860c-18.7 18.7-34.7 44-48 76s-20 61.3-20 88v256H128V640h416 l0 0c26.7 0 49.3-9.3 68-28s28-41.3 28-68V128h384v416L708 860L708 860z M768 1664v-640h416l0 0c26.7 0 49.3-9.3 68-28 s28-41.3 28-68V512h384v1152H768z" />' + (ns ? 'NS ' : '') + // i18n could be possible but would need to fit the text properly ' ';		}

mw.util.addCSS('\n'+			'#title-copy-container svg:hover { filter: brightness(1.75); }\n'+			'#title-copy-container svg {\n'+				'flex-basis: 50%;\n'+				'transition: fill 250ms;\n'+				'fill: currentColor;\n'+			'}\n'+			'body:is(.action-edit, .action-submit) #title-copy-container { flex-direction: row; }\n'+			'.lightboxContainer .LightboxHeader h1 #title-copy-container {\n'+				'flex-direction: row;\n'+				'display: inline-flex;\n'+				'margin-left: 4px;\n'+				'height: 28px;\n'+				'width: 28px;\n'+			'}\n'+			'body:is(.action-edit, .action-submit) #title-copy-container > :first-of-type { margin-right: 5px; }\n'+			'body:is(.action-edit, .action-submit) #title-copy-container svg { height: 1em; }\n'+			'.LightboxModal .LightboxHeader h1 { overflow: visible; white-space: normal; max-width: auto; }'		);

$(' ', { id: 'title-copy-container', 'class': 'page-side-tool' }) .append(getSVG('title-copy-content', false)) .appendTo($('.page-side-tools')); if (mw.config.get('wgNamespaceNumber') !== 0) { $(' ', { id: 'title-copy-container', 'class': 'page-side-tool' }) .append(getSVG('title-copy-all', true)) .appendTo($('.page-side-tools')); }		$('.page-side-tools #title-copy-content').click(function {			copy(mw.config.get('wgTitle'), this);		});

$('.page-side-tools #title-copy-all').click(function {			copy(mw.config.get('wgPageName').replace(/_/g, ' '), this);		}); var fileBox = new MutationObserver(function (mutations, me) {			mutations.forEach(function(mutation){ if ( mutation && mutation.removedNodes ) { mutation.removedNodes.forEach(function(removedNode){						if (removedNode.id && removedNode.id == 'LightboxPreload'){							var fileName = document.querySelector('.lightboxContainer .LightboxHeader h1 a').href.replace(/^.*?\/wiki\/File:/, '').replace(/_/g, ' ');							$(' ', { id: 'title-copy-container', 'class': 'page-side-tool' })								.append(getSVG('title-copy-content', false))								.appendTo($('.lightboxContainer .LightboxHeader h1'));							$(' ', { id: 'title-copy-container' , 'class': 'page-side-tool' })								.append(getSVG('title-copy-all', true))								.appendTo($('.lightboxContainer .LightboxHeader h1'));							$('.lightboxContainer .LightboxHeader h1 #title-copy-content').click(function { copy(decodeURIComponent(fileName), this); });							$('.lightboxContainer .LightboxHeader h1 #title-copy-all').click(function { copy('File:'+decodeURIComponent(fileName), this); });						}					});				}			});		});		fileBox.observe(document.body, { childList: true }); }

function copy(text, element) { var copyEl = document.createElement('textarea'); copyEl.value = text; document.body.appendChild(copyEl); copyEl.select; document.execCommand('copy'); document.body.removeChild(copyEl); document.execCommand('copy');

$(element).css('fill', 'var(--theme-success-color)'); setTimeout(function {			$(element).css('fill', '');		}, 1000); }

mw.hook('dev.i18n').add(function {		window.dev.i18n.loadMessages('CopyTitle').then(init);	});

importArticles({		type: 'script',		article: 'u:dev:MediaWiki:I18n-js/code.js'	}); });

/* wanted categories */ (function{	// Double load protection	if (document.querySelector('a#tu-wc')) {return;}

// Dependencies var api; var RUNNING = 0; var list = document.createElement('ul'); var label = document.createElement('div'); label.innerHTML = 'Loading wanted categories...'; var start; var categories = []; var __DONE = 0; importArticle({	   type: 'script',	    article: 'u:dev:MediaWiki:Placement.js'	});

// Main object var wantedCategories = { init: function { api = new mw.Api; mw.hook('dev.placement').add(function(placement) {   			placement.script('WantedCategories');    			$(placement.element('tools'))[placement.type('prepend')]( $('').append($('').attr({ href: '#', id: 't-wc' }).text('Wanted Categories').click(wantedCategories.loadUI)) );			});		},		loadUI: function(event) { event.preventDefault; list.append(label); document.querySelector('div#content.page-content').insertBefore(list, document.querySelector('div#mw-content-text.mw-body-content')); document.querySelector('div#content.page-content').insertBefore(label, list); if (RUNNING==0){ start = new Date; } wantedCategories.renderCategories; },		renderCategories: function { var namespaces = [0, 6, 14, 828]; // [Main, File, Category, Module] namespaces.forEach(function(namespace){				wantedCategories.getCategories(null, namespace);			}); function waitForApi { if(__DONE < namespaces.length) { window.setTimeout(waitForApi, 100); /* this checks the flag every 100 milliseconds*/ } else { __DONE = 0; wantedCategories.parseCategories; }			}			waitForApi; },		getCategories: function(continueFrom, namespace){ // console.log('continueFrom:', continueFrom); RUNNING++; var params = { action: 'query', generator: 'allpages', gaplimit: 'max', prop: 'categories', cllimit: 'max', clshow: '!hidden', gapnamespace: namespace };			if (!!continueFrom) {Object.assign(params, continueFrom);} api.get(params) .then(function(data){				// console.log('then', data);				if (!data.error && data.query && data.query.pages) {					Object.keys(data.query.pages).forEach(function(ID){ var item = data.query.pages[ID]; if (item.categories && item.categories.length>0) { var newC = item.categories.reduce(function(a, o){								if (categories.indexOf(o.title) == -1) {a.push(o.title);}								return a;							}, []); if (newC.length>0) {categories = categories.concat(newC);} }					});					//console.log('data', data);					if (data.continue) {						// continueName - get value by the key that isn't just "continue" - could be "fucontinue", "aicontinue", "gaicontinue"						var continueName = data.continue[Object.keys(data.continue).filter(function(k) { return k !== 'continue'; })[0]].replace(/\|\d+$/, ).replace(/^\d+\|/, );						wantedCategories.getCategories(data.continue, namespace);					} else {						__DONE++;					}				} else {					console.log('early stop, something went wrong:', data);					label.innerHTML = 'Early stop, either there\'s no wanted categories or something went wrong.';					return;				}			}); },		parseCategories: function { var count = document.createElement('span'); count.append(0); var parseDONE = false; if (categories.length>0) { categories.sort; for (var i = 0; i<categories.length; i = i+49) { var _cats = categories.slice(i, i+49); //console.log('_cats', _cats); api.get({action:'query', titles: _cats, prop: 'info'}).then(function(data){						console.log('cats:', data);						if (data && data.query && data.query.pages && data.query.pages['-1']) {							var a = -1;							while (data.query.pages[a]) {								var cat = data.query.pages[a];								var link = document.createElement('a');								link.href = '/wiki/' + cat.title;								link.innerHTML = cat.title;								var bullet = document.createElement('li');								bullet.append(link);								list.append(bullet);								a--;								count.innerHTML++;							}						} else {categories.splice;}					}); }			}			label.innerHTML = 'Done loading! Took '+(((new Date)-start)/1000)+' seconds.'; // Override the "loading" text label.append(' Loaded ', count, ' wanted categories.'); // "append" needed due to count being an element }	};

mw.loader.using('mediawiki.api').then(wantedCategories.init); });