User:Writ Keeper/Scripts/rollbackWatchlister.js

$(document).ready(watchlister);

function watchlister {	var i;	var array = $(".mw-rollback-link"); for(i = 0; i < array.length; i++) {		var anchor = (array[i].getElementsByTagName("a"))[0]; anchor.setAttribute("onclick", "watchlistOnClick('" + anchor.href + "'); return false;"); anchor.setAttribute("href", "#"); } } function watchlistOnClick(url) {	var regex = /title=.+(?=&action)/

var targetPage = regex.exec(url); var data = { format : 'json', action : 'query', meta : 'tokens', type : 'watch' }	$.ajax({		url : mw.util.wikiScript('api'),		type : "POST", 		dataType : 'json',		data : data,

success : function(data) { var token = data.responseJSON.query.tokens.watchtoken; alert(url.replace(/action=rollback.+/, "action=watch") + "&token=" + token); window.location = url; },		error : function { alert('Ajax error.'); }		}); }