MediaWiki:Gadget-newpageswatched.js

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Internet Explorer / Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
  • Opera: Nyomj Ctrl–F5-öt
( function ( mw, $ ) {
	if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Newpages' ) { return; }
	
	var watchlist = [];
	
	function markLines( $content ) {
		var $li = $content.children( 'ul' ).children( 'li' );
		if ( !$li.length ) { return; }
		var wlObj = {};
		/* make a plain object instead of an array, so that we can use wlObj[ page ] */
		for ( var i = 0; i < watchlist.length; i++ ) {
			wlObj[ watchlist[ i ].title ] = true;
		}
		$li.each( function () {
			var pagename = $( this ).children( '.mw-newpages-pagename' ).text();
			if ( !pagename ) { return; }
			if ( wlObj[ pagename ] ) {
				$( this ).addClass( 'mw-newpages-watched' );
			}
		} );
	}
	
	function getWatchlist() {
		var api = new mw.Api();
		var config = {
			action: 'query',
			list: 'watchlistraw',
			wrlimit: 500
		};
		function done( data ) {
			var list, cont, wrcont;
			try {
				list = data.watchlistraw;
				cont = data['continue']['continue'];
				wrcont = data['continue'].wrcontinue;
			} catch ( ignore ) {
				/* we have no watchlist, got the end of the list etc. */
			}
			if ( list ) {
				watchlist = watchlist.concat( list );
			}
			if ( cont && wrcont ) { /* repeat queries until we get the whole watchlist */
				config['continue'] = cont;
				config.wrcontinue = wrcont;
				api.get( config ).done( done );
			} else if ( watchlist.length ) { // we have the whole list
				/* mark lines when the list's DOM is ready */
				mw.hook( 'wikipage.content' ).add( markLines );
			}
		}
		api.get( config ).done( done );
	}
	
	getWatchlist();
}( mediaWiki, jQuery ) );