Jump to content

User:Awesome Aasim/rollbacknoleave.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
//<div class="mw-spinner mw-spinner-small mw-spinner-inline" title="..." id="mw-spinner-rollback-spinner"><div class="mw-spinner-container"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>
if (!RBNL) {
	var RBNL = function() {
		$(".mw-rollback-link").each(function() {
			if ($(this).data("rbnl-loaded") != "1") {
				$(this).data("rbnl-loaded", "1");
				$(this).click(function(e) {
					e.preventDefault();
					var link = $(this).find("a").attr("href");
					//stack overflow: https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript
					var getUrl = window.location;
					var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
					var urlparams = (new URL(baseUrl + link)).searchParams;
					var rollbackuser = urlparams.get('from');
					var rollbacktoken = urlparams.get('token');
					var rollbacktitle = urlparams.get('title');
					$(this).html('<div class="mw-spinner mw-spinner-small mw-spinner-inline" title="..."><div class="mw-spinner-container"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>');
					var that = this;
					$.post(mw.config.get("wgScriptPath") + "/api.php", {
						"action": "rollback",
						"user": rollbackuser,
						"token": rollbacktoken,
						"title": rollbacktitle,
						"format": "json"
					}).done(function(result) {
						console.log(result);
						if (result.error) {
							location.href = link;
						} else {
							$(that).html("Rollback complete");
							$(that).off("click");
						}
					}).fail(function(result) {
						location.href = link;
					});
				});
			}
		});
	};
	$(document).ready(function() {
		window.setInterval(RBNL, 300);
	});
}