User:Insertcleverphrasehere/unwatch.js

/** * Unwatch from watchlist * * Add an "unwatch" link near each entry on the watchlist view (424). * * @source https://www.mediawiki.org/wiki/Snippets/Unwatch_from_watchlist * @author Krinkle * @revision 2016-09-01 */ mw.hook( 'wikipage.content' ).add( function ( $content ) {	// Only on Watchlist and not in the /edit or /raw mode	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Watchlist' || location.href.indexOf( '/edit' ) > 0 || location.href.indexOf( '/raw' ) > 0 ) {		return;	}	mw.loader.using( ['mediawiki.util', 'mediawiki.api'] ).then( function { // Get the links var $wlHistLinks = $content.find( 'ul.special .mw-changeslist-line .mw-changeslist-history');

$wlHistLinks.each( function {			var $unwatch,				$el = $( this ),				title = mw.util.getParamValue( 'title', this.href );

$unwatch = $el.clone .text( 'unwatch' ) .attr( 'href', function ( i, val ) {					return val.replace( 'action=history', 'action=unwatch' );				} ) .on( 'click', function ( e ) {					new mw.Api.unwatch( title )						.done( function { $unwatch.css( { pointerEvents: 'none', opacity: 0.5 } ); } )						.fail( function { $unwatch.off( 'click' ).append( ' (try again?)' ); } );					e.preventDefault;				} ); $el.after( $unwatch ).after( ' | ' ); } );	} ); } );