User:WhitePhosphorus/js/fakerollback.js

/* * d:User:Ricordisamoa/Rollback.js * Rollback.js by User:Ricordisamoa * experimental * provides the 'rollback' link to non-rollbackers * !!! not intended for use by vandals !!! $(document).ready(function{	if (window.FakeRollbackOptoutWikis instanceof Array && window.FakeRollbackOptoutWikis.includes(mw.config.get('wgDBname'))) {		return ;	}	mw.loader.using("jquery.jStorage",function{ $.get(			mw.util.wikiScript("api"),			{				action:"query",				format:"json",				meta:"allmessages",				amlang:wgContentLanguage,				ammessages:"revertpage|rollback-success|rollbacklink|action-rollback|tooltip-rollback|cantrollback|rollbackfailed"			},			function(data){				if($.jStorage.get("fake_rollback-action")==="done"){					$.jStorage.set("fake_rollback-action","");					$.jStorage.set("fake_rollback-summary","");					$.jStorage.set("fake_rollback-success","");				}				else if($.jStorage.get("fake_rollback-action")==="todo"&&$("#wpSummary").size===1&&wgAction==="edit"&&mw.util.getParamValue("restore")!=null){					$.jStorage.set("fake_rollback-action","done");					$("#wpSummary").val($.jStorage.get("fake_rollback-summary"));				}				var prevUser=$("ul#pagehistory li:first-child span.history-user a.mw-userlink,#mw-diff-ntitle2 a.mw-userlink").first.text;				var messages={};				$.each(data.query.allmessages,function(i,e){ messages[e.name]=e["*"]; });				var rbLink=$("")				.attr({ href:mw.util.wikiScript+"?"+$.param({						title:wgPageName,						action:"rollback",						user:prevUser,						token:mw.user.tokens.get("editToken")					}), title:messages["tooltip-rollback"] })				.text(messages.rollbacklink)				.click(function(event){ event.preventDefault; $.get(						mw.util.wikiScript("api"),						{							action:"query",							format:"json",							prop:"revisions",							rvlimit:1,							titles:wgPageName,							rvexcludeuser:prevUser,							rvprop:"timestamp|user|content|ids"						},						function(data){							var page=data.query.pages[Object.keys(data.query.pages)[0]];							if(typeof page.revisions!="undefined"){								var revision=page.revisions[0];								var rbSummary=prompt("Summary: (optional)");								if (rbSummary === null) return;								rbSummary = rbSummary || messages.revertpage.replace(/\$1/g,revision.user).replace(/\$2/g,prevUser);								var rbSuccess=messages["rollback-success"].replace(/\$2/g,revision.user).replace(/\$1/g,prevUser);								/*if(wgServer==="//zh.wikipedia.org"){									$.jStorage.set("fake_rollback-summary",rbSummary);									$.jStorage.set("fake_rollback-success",rbSuccess);									$.jStorage.set("fake_rollback-action","todo"); window.location.href="//zh.wikipedia.org/wiki/"+wgPageName+"?action=edit&restore="+revision.revid; }								else{*/ console.groupCollapsed(revision.user+"@"+revision.timestamp); var rbContent=revision["*"]; console.groupEnd; $.post(										mw.util.wikiScript("api"),										{											action:"edit",											text:rbContent,											//undo:$("#pagehistory li:first-child .mw-history-undo a").attr("href").match(/undo=([0-9]+)($|[^0-9])/)[1],											restore:revision.revid,											title:wgPageName,											summary:rbSummary,											minor:true,											format:"json",											token:mw.user.tokens.get("editToken")										}									) .done(function(data){										if (data && data.error) {											console.log("Error " + (data.error.code || '') + ":" + (data.error.info || 'No info provided.') + '.');										} else {											setTimeout(function{document.location.reload;},3000);										}									}) .fail(function{										console.log(messages.rollbackfailed);									}); //}							}							else console.log(messages.cantrollback); }					);				});				if($("ul#pagehistory").size>0) rbLink .insertAfter("ul#pagehistory li:first-child span.mw-history-undo") .last .before(" | "); else if($("#differences-nextlink").size===0) rbLink.appendTo("#mw-diff-ntitle4").before("[").after("]"); }		);	}); }); //