User:Writ Keeper/Scripts/watchlistToggle.js

function removeWatchlistItem(element) {	mw.loader.using("mediawiki.api").done(function	{		var pageTitle = $(element).siblings.find(".mw-changeslist-history").prop("title");		var mwApi = new mw.Api;		mwApi.unwatch(pageTitle).done(function {			$(element).unbind("click"); $(element).click(function 			{				return addWatchlistItem(this);			}); $(element).text("add"); $(element).attr("title","Re-add this item to your watchlist"); });	});	return false; } function addWatchlistItem(element) {	var pageTitle = $(element).siblings.find(".mw-changeslist-history").prop("title"); var mwApi = new mw.Api; mwApi.watch(pageTitle).done(function 	{		$(element).unbind("click");		$(element).click(function {			return addWatchlistItem(this); });		$(element).text("rem");		$(element).attr("title","Remove this item from your watchlist");	}); return false; }

$(document).ready( function {	if(mw.config.get("wgCanonicalSpecialPageName") === "Watchlist")	{		$("li.mw-changeslist-edit .mw-changeslist-links").not(".mw-usertoollinks").each(function(ind, el){$(el).append(" | rem")});		$("a.watchlistToggle").click(function {			return removeWatchlistItem(this); });	} });