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(5000);    } });

// Group functions to simplify usage and maintenance function toRun(delay) { if (!delay) {delay = 1000;} setTimeout(		function{			// Functions to run			noThank;			properLink;		}, 		delay //wait 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 row = el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;				var pageName = row.getElementsByClassName('mw-changeslist-title')[0].attributes.title.nodeValue;				el.removeChild(el.firstChild); // delete plain text				var row_revid = row.getAttributeNode('data-mw-revid');				if (row_revid && row_revid.value) {					// single edit diff without use of api					el.appendChild(buildLink([						{revid: row_revid.value},						{revid: 0}					], pageName));				}else{					// multiple edit diff with use of api					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 day = Date.parse(row.previousElementSibling.innerHTML); day = [day, day+86400]; console.log(day); var revisions = []; // select only relevant revisions data.query.pages[0].revisions.forEach(function(revision) {							console.log(revision.timestamp);							var ts = Date.parse(revision.timestamp);							console.log(ts);							if ( ts>=day[0] && ts2) { label = (revisions.length-1) + ' 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.innerHTML = label; return link; } }