Jump to content

User:Writ Keeper/Scripts/massRollback.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Writ Keeper (talk | contribs) at 04:34, 29 July 2015 (fx). 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.
//Mass rollback function
//Written by John254 and modified/rewritten by Writ Keeper; original is at https://en.wikipedia.org/wiki/User:John254/mass_rollback.js
//Adapted from User:Mr.Z-man/rollbackSummary.js
//Instructions: Selecting the "rollback all" tab when viewing a user's contributions history
//will open all rollback links displayed there. (Use with caution)
  
function rollbackEverythingWKMR() {
	var userName = /Contributions\/(.+)/.exec(mw.config.get("wgTitle"))[1]
	$("a[href*='action=rollback']").each(function(ind, el)
	{
		var regexResults = /token=([^&]+)/.exec(this.href)
		if(typeof regexResults[1] == "undefined")
		{
			//if we didn't find the token, something is wrong
			return false;
		}
		rollbackToken = decodeURIComponent(regexResults[1])
		
		var postInfo = {action:"rollback",title:/title=([^&]+)/.exec(this.href)[1],token:rollbackToken,user:userName}
		$.post("/w/api.php", postInfo, function()
		{
			$(el).after("reverted");
			$(el).remove();
		})
	});
}
$(document).ready(function()
	{
		if(mw.config.get("wgCanonicalSpecialPageName") === "Contributions" && $("span.mw-rollback-link").length > 0)
		{
			addPortletLink('p-cactions', 'javascript:rollbackEverythingWKMR()', "rollback all", "ca-rollbackeverything", "rollback all edits displayed here");
			$("#ca-rollbackeverything").click(function(){if(confirm("Really rollback *everything*?")){return true;}return false;});
  		}
	});