User:Dixtosa/unwatch.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

// adds unwatch button between "diff" and "hist"
// Dependency: ES6
// DEPRECATED. superseded by mediawiki's own option here - Preferences/Watchlist -> Advanced options

function unwatchjs_u(Title)
{
	let title = decodeURIComponent(Title);
	new mw.Api().unwatch(title).done (function( data ) {
		if ( data && data.title == title) {
			$(`.mw-changeslist li .mw-title:contains('${title.replace("'", "\\'")}')`).parent().hide("slow");
		} else {
			mw.notify( 'The edit query returned an error.' + JSON.stringify(data) );
		}
	})
	.fail ( function() {
		mw.notify( 'The ajax request failed.' );
	});
}

if (mw.config.values.wgCanonicalSpecialPageName == 'Watchlist' && mw.config.values.wgAction == 'view' ) 
{
	mw.loader.using(['mediawiki.api'], function () {
		$(() => {
			$("a:contains('diff')").after(function(index) {
				//I'm vegetarian
				let escapedTitle = this.title.replace("'", "%27");
				return ` | <a href='javascript: unwatchjs_u("${escapedTitle}")'>unwatch</a>`;
			});
		});
	});
}