User:Mr Pie 5/global.js

mw.loader.load('//internal-soap.fandom.com/index.php?title=User:Mr_Pie_5/scripts-ucp.js&action=raw&ctype=text/javascript');

// automatically follow "page already exists" when searching $(function {	$(".mw-search-exists a")[0].click; })

// Turn the page title into a link to the page $(function { var title = document.getElementById("firstHeading");  // MediaWiki doesn't support backticks so piecemeal this :/  link = document.createElement('a');  link.href = window.location.pathname;  link.style.color = "inherit";  link.textContent = title.textContent;  title.textContent = "";  title.append(link); });

// Creates links to automatically revert a page to a specific revision with summary $(function {	if(!(document.getElementById('pagehistory') || document.getElementsByClassName('diff-title')[0] || document.getElementsByClassName('mw-revision')[0])){		return;	}	mw.loader.using('mediawiki.api').then(function { var api = new mw.Api; function revert(id){ // get the information about the desired revision api.get({				"action": "query",				"format": "json",				"prop": "revisions",				"revids": id,				"formatversion": "2",				"rvprop": "timestamp|user|content"			}).then(function(data) {				// parse and format the desired revision				var revision = data.query.pages[0].revisions[0];	         	var revisionLink =  + id + ;				var user = (revision.anon) ?  + revision.user +  :  + revision.user + ;				var date = new Date(revision.timestamp);				var timestamp = '' + date.getUTCHours + ':' + date.getUTCMinutes + ', ' + date.getUTCDate + ' ' + date.toLocaleString('en-us', {month:'long', timeZone:'UTC'}) + ' ' + date.getUTCFullYear + ' (UTC)';				// post the edit reverting the page to the desired revision				api.post({ "action": "edit", "format": "json", "pageid": data.query.pages[0].pageid, "text": revision.content, "summary": 'Reverted to revision ' + revisionLink + ' by ' + user + ' at ' + timestamp + '.', "formatversion": "2", "token": mw.user.tokens.get('csrfToken'), }).then(function(data){ if(data.edit.result == "Success"){ location.reload; }					else { console.log("Something went wrong. Response follows:"); console.log(data); }				});			});		}		function appendRevertLink(element, id){ var revertLink = document.createElement('a'); revertLink.textContent = 'revert'; revertLink.setAttribute('href', 'javascript:;'); revertLink.addEventListener('click', function{revert(id)}); var revertContainer = document.createElement('span'); revertContainer.classList.add('pie-revert'); revertContainer.append(' (');			revertContainer.append(revertLink)			revertContainer.append(')'); element.append(revertContainer); }		// Adds the link on history pages if(document.getElementById('pagehistory')){ var nodes = document.getElementById('pagehistory').children; for(var i = 0; i < nodes.length; i++){ var id = nodes[i].getAttribute('data-mw-revid'); appendRevertLink(nodes[i], id); }		}		// Adds the link on diff pages if(document.getElementsByClassName('diff-title')[0]){ var nodes = document.getElementsByClassName('diff-title')[0].children; for(var i = 0; i < nodes.length; i++){ var id = nodes[i].querySelector('a[href*="oldid="]').href.match(/oldid=(\d+)/)[1]; appendRevertLink(nodes[i].getElementsByTagName('strong')[0], id); }		}		// Adds the link on revision pages if(document.getElementsByClassName('mw-revision')[0]){ var element = document.getElementsByClassName('mw-revision')[0]; var id = element.querySelector('a[href*="oldid="]').href.match(/oldid=(\d+)/)[1]; appendRevertLink(element, id); }	}); });