User:Simulo/common.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 2014-12-17 */ 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.api.watch' ).done( function  { // Get the links var $wlHistLinks = $content.find( 'ul.special > li > a[href$="action=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( ' | ' ); } );   } ); } );