MediaWiki:Gadget-unWatch.js

$( '#ca-watch' ).click( function ( ew ) { ew.preventDefault;  ( new mw.Api ).postWithToken( 'watch', { action: 'watch', titles: mw.config.get( 'wgPageName' ) } ).done( function( wResult ) { if ( wResult.watch[ 0 ].watched !== undefined ) { $( '#ca-watch' ).find( 'a' ).parents( 'span' ).html( $( '#ca-watch' ).find( 'a' ).parents.html.replace( 'action=watch', 'action=unwatch' ) ); $( '#ca-watch' ).find( 'a' ).attr( 'title', $( '#ca-watch' ).find( 'a' ).attr( 'title' ).replace( 'Add this page to', 'Remove this page from' ) ); $( '#ca-watch' ).find( 'a' ).text( 'Unwatch' ); $( '#ca-watch' ).attr( 'id', 'ca-unwatch' ); } } ); } );

$( '#ca-unwatch' ).click( function ( euw ) { euw.preventDefault;  ( new mw.Api ).postWithToken( 'watch', { action: 'watch', unwatch: true, titles: mw.config.get( 'wgPageName' ) } ).done( function( uwResult ) { if ( uwResult.watch[ 0 ].unwatched !== undefined ) { $( '#ca-unwatch' ).find( 'a' ).attr( 'href', $( '#ca-unwatch' ).find( 'a' ).attr( 'href' ).replace( 'action=unwatch', 'action=watch' ) ); $( '#ca-unwatch' ).find( 'a' ).attr( 'title', $( '#ca-unwatch' ).find( 'a' ).attr( 'title' ).replace( 'Remove this page from', 'Add this page to' ) ); $( '#ca-unwatch' ).find( 'a' ).text( 'Watch' ); $( '#ca-unwatch' ).attr( 'id', 'ca-watch' ); } } ); } );