Technical_13

MW:Gadget-unWatch.js

Aug 16th, 2016
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.34 KB | None | 0 0
  1. $( '#ca-watch' ).click( function ( e ) {
  2.   e.preventDefault();
  3.     ( new mw.Api ).postWithToken( 'watch', {
  4.         action: 'watch',
  5.         titles: mw.config.get( 'wgTitle' )
  6.     } ).done( function( wlResult) {
  7.         if ( wlResult.watch[ 0 ].watched !== undefined ) {
  8.             $( '#ca-watch' ).find( 'a' ).parents( 'span' ).html( $( '#ca-watch' ).find( 'a' ).parents().html().replace( 'action=watch', 'action=unwatch' ) );
  9.             $( '#ca-watch' ).find( 'a' ).attr( 'title', $( '#ca-watch' ).find( 'a' ).attr( 'title' ).replace( 'Add this page to', 'Remove this page from' ) );
  10.             $( '#ca-watch' ).find( 'a' ).text( 'Unwatch' );
  11.             $( '#ca-watch' ).attr( 'id', 'ca-unwatch' );
  12.         }
  13.     } );
  14. } );
  15.  
  16. $( '#ca-unwatch' ).click( function ( e ) {
  17.   e.preventDefault();
  18.     ( new mw.Api ).postWithToken( 'watch', {
  19.         action: 'watch',
  20.     unwatch: true,
  21.         titles: mw.config.get( 'wgTitle' )
  22.     } ).done( function( wlResult ) {
  23.         if ( wlResult.watch[ 0 ].unwatched !== undefined ) {
  24.             $( '#ca-unwatch' ).find( 'a' ).attr( 'href', $( '#ca-unwatch' ).find( 'a' ).attr( 'href' ).replace( 'action=unwatch', 'action=watch' ) );
  25.             $( '#ca-unwatch' ).find( 'a' ).attr( 'title', $( '#ca-unwatch' ).find( 'a' ).attr( 'title' ).replace( 'Remove this page from', 'Add this page to' ) );
  26.             $( '#ca-unwatch' ).find( 'a' ).text( 'Watch' );
  27.             $( '#ca-unwatch' ).attr( 'id', 'ca-watch' );
  28.         }
  29.     } );
  30. } );
Add Comment
Please, Sign In to add comment