User:Mikevoir/global.js

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:AjaxBatchDelete.js',        'u:dev:MediaWiki:Bang.js',        'u:dev:MediaWiki:FileUsageAuto-update/code.js',        'u:dev:MediaWiki:LastEdited/code.js',        'u:dev:MediaWiki:MassRename/code.js',        'u:dev:MediaWiki:MassNullEdit/code.js',        'u:dev:MediaWiki:PurgeButton.js',        'u:dev:MediaWiki:Wikimarks/code.js',    ] });

// Load functions upon page load if (/comp|inter|loaded/.test(document.readyState)) { toRun; } else { document.addEventListener('DOMContentLoaded', function {		toRun;	}); } // Load functions upon RC refresh document.addEventListener('click', function(event) {   if (event.target && event.target.closest('.mw-rcfilters-ui-filterWrapperWidget-bottom > .mw-rcfilters-ui-filterWrapperWidget-showNewChanges > a.oo-ui-buttonElement-button')) {		toRun;    } });

// Group functions to simplify usage and maintenance function toRun { setTimeout(		function{			// Functions to run			noThank;			properLink;		}, 		1000 //wait one second just in case	); }

// No thanks function noThank { document.querySelectorAll('.mw-thanks-thank-link').forEach(function(el) {		if (el.parentNode.nodeName === 'SPAN'){			el.parentNode.remove;		}else{			if ( el.previousSibling.data === '( ' && el.nextSibling.data === ' )' ) {				el.nextSibling.remove;				el.previousSibling.remove;			}			el.remove;		}	}); }

// Make RC properly give links on diffs that include page creations function properLink { var api = new mw.Api; document.querySelectorAll('.mw-changeslist-links > span:first-child').forEach(	  	function(el) {			if (el.childNodes.length === 1 && el.childElementCount === 0){				var pageName = el.parentNode.parentNode.parentNode.getElementsByClassName('mw-changeslist-title')[0].attributes.title.nodeValue;				while (el.firstChild) {				  el.removeChild(el.firstChild);				}				api.get({ action: 'query', titles: pageName, meta: 'tokens', prop: 'revisions', rvprop: 'ids|timestamp|user|userid|size|parsedcomment|flags', rvlimit: 1000, formatversion: 2 }).then(function(data) { var link = document.createElement('a'); var page = data.query.pages[0].title;

var revisions = data.query.pages[0].revisions; var from = revisions[revisions.length-1].revid; var to = revisions[0].revid; if (from === to) { from = 0; }

var label = 'diff'; if (revisions.length>1) { label = revisions.length + ' changes'; link.classList.add('mw-changeslist-diff'); } else { link.classList.add('mw-changeslist-groupdiff'); }

link.href = '/wiki/'+page+'?diff='+ to +'&oldid='+from; link.title = page; link.appendChild(document.createTextNode(label)); el.appendChild(link); });			}		}	); }