Jump to content

User:FunIsOptional/RestoreButton.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by FunIsOptional (talk | contribs) at 08:32, 3 August 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(document).ready( function () {
	if (mw.config.get('wgAction') === 'history') {
   		var links = document.getElementsByClassName('mw-changeslist-links');
   		for (var i = 0; i < links.length; i++) {
   			if (i % 3 != 0) {
   				continue;
   			}
   			
			var restoreSpan = document.createElement('span');
			var restoreA = document.createElement('a');

			var revisionId = links[i].parentNode.getAttribute('data-mw-revid');
			var pageTitle = mw.config.get('wgPageName');

			restoreA.setAttribute('href', '//en.wikipedia.org/w/index.php?title=' + pageTitle + '&oldid=' + revisionId + '&action=edit');
			restoreA.textContent = 'restore';

			restoreSpan.appendChild(restoreA);
       		links[i].appendChild(restoreSpan);
   		}
	}	
});