Welcome to the newly independent BOXBOY WIKI!

Learn more about our fork at BOXBOY WIKI!:2025 Fork. If you have edited the Fandom wiki and would like to claim your account here, you can do so via Special:MigrateUserAccount. To ensure you only visit the independent wiki going forward, install the Indie Wiki Buddy browser extension.

MediaWiki:Gadget-RCThanks.js

From BOXBOY WIKI!
Revision as of 18:42, 14 January 2025 by SuperHamster (talk | contribs) (Creating)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Inserts thank links (Extension:Thanks) on recent changes and watchlist pages.
 * Created by SuperHamster on Nookipedia (https://nookipedia.com/wiki/User:SuperHamster)
 * Licensed under CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/)
 **/

function confirmThank(revid) {
	document.getElementById("rc-thank-" + revid).style.display = "none";
	document.getElementById("rc-thank-confirm-" + revid).style.display = "inline";
	document.getElementById("rc-thank-cancel-" + revid).style.display = "inline";
}

function cancelThank(revid) {
	document.getElementById("rc-thank-" + revid).style.display = "inline";
	document.getElementById("rc-thank-confirm-" + revid).style.display = "none";
	document.getElementById("rc-thank-cancel-" + revid).style.display = "none";
}

function sendThank(revid) {
	document.getElementById("rc-thank-confirm-" + revid).style.display = "none";
	document.getElementById("rc-thank-cancel-" + revid).style.display = "none";
	var thankSpan = document.getElementById("rc-thank-span-" + revid);
	thankSpan.innerHTML = "\u00A0[thanking...]";
	new mw.Api().postWithToken( 'csrf', {
	 	action: "thank",
		rev: revid
	}).done(function(response) {
		if (response.result.success == 1) {
			thankSpan.innerHTML = "\u00A0[thanked]";
		} else {
			thankSpan.innerHTML = "\u00A0[thank failed]";
		}
	 	console.log("Thank sent for revision ID " + revid);
	});
}

if (mw.config.get("wgPageName") === "Special:RecentChanges" || mw.config.get("wgPageName") === "Special:Watchlist") {
	// Grab page content to narrow down queried body:
	var content = document.getElementById("mw-content-text");

	// Select elements containing edits from registered users:
	var edits = content.querySelectorAll(".mw-changeslist-user-registered[data-mw-revid]");

	// Loop through edits:
	for (var i = 0; i < edits.length; i++) (function(i) {
		// Extract revid:
	    var revid = edits[i].getAttribute("data-mw-revid");

	    // Grab inner td element that contains edit details:
	    var edit = edits[i].querySelectorAll("td.mw-enhanced-rc-nested, td.mw-changeslist-line-inner")[0];

	    // Check if edit is from self and ignore if so:
	    if (edit.getElementsByClassName("mw-userlink")[0].title.substring(5) !== mw.user.getName()) {
		    // Create thank HTML elements:
		    var thankLink = document.createElement("a");
		    thankLink.className = "mw-thanks-thank-link";
		    thankLink.id = "rc-thank-" + revid;
		    thankLink.href = "#0";
		    thankLink.title = "Send a thank you notification to this user";
		    thankLink.innerHTML = "thank";
			thankLink.onclick = function() {
				confirmThank(revid);
			};

			var confirmThankLink = document.createElement("a");
			confirmThankLink.id = "rc-thank-confirm-" + revid;
			confirmThankLink.href = "#0";
			confirmThankLink.style.display = "none";
			confirmThankLink.title = "Confirm to send thank you notification to this user";
			confirmThankLink.innerHTML = "confirm";
			confirmThankLink.onclick = function() {
				sendThank(revid);
			};
	
			var cancelThankLink = document.createElement("a");
			cancelThankLink.id = "rc-thank-cancel-" + revid;
			cancelThankLink.href = "#0";
			cancelThankLink.style.display = "none";
			cancelThankLink.style.marginLeft = "1ex";
			cancelThankLink.title = "Cancel sending thank you notification to this user";
			cancelThankLink.innerHTML = "cancel";
			cancelThankLink.onclick = function() {
				cancelThank(revid);
			};

			var thankSpan = document.createElement("span");
			thankSpan.id = "rc-thank-span-" + revid;
		    thankSpan.appendChild(document.createTextNode("\u00A0["));
			thankSpan.appendChild(thankLink);
			thankSpan.appendChild(confirmThankLink);
			thankSpan.appendChild(cancelThankLink);
			thankSpan.appendChild(document.createTextNode("]"));
	
			// Append thanks to edit
			edit.appendChild(thankSpan);
	    }
	})(i);
}