משתמש:קיפודנחש/aggressive-refresh.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
if ( mw.config.get( 'wgNamespaceNumber' ) === 14 )
mw.loader.using( 'mediawiki.util' ).done( function() {
$( mw.util.addPortletLink('p-cactions','#', 'רענון אגרסיבי' ) ).click( function() {
mw.loader.using( ['mediawiki.api', 'mediawiki.user'] ).done( function() {
	var api = new mw.Api();
	var res = api.get( { list: 'categorymembers', cmtitle: mw.config.get( 'wgPageName' ), cmprop: 'title', cmtype: 'page|file', cmlimit: 500 } );
	res.fail( function() { mw.notify( 'something went wrong' ); } );
	res.done( function( data ) { 
		var titles = data.query.categorymembers.map(m => m.title),
			token = mw.user.tokens.get( 'csrfToken' ),
			message = $( '<span class="message-for-bora" id="bora-message">' ).appendTo( '#contentSub' );
		if ( titles.length ) 
			dobatch();
		function dobatch() {
			var batch = titles.splice( 0, 100 );
			if (batch.length) {
				var start = new Date();
				message.text( 'about to send ' +  batch.length + ' null edits. on ' + start );
				var promisses = batch.map( function(title) {
					console.log( 'executing null edit in page: ' + title );
					return api.post( { 
						action: 'edit',
						appendtext: '',
						watchlist: 'nochange',
						title: title,	// modern js just says title...
						token: token	// ditto
					} );
				} );
				$.when( ... promisses ).then( function() {
					var failed = promisses.filter( promise => promise.state() != "resolved" );
					if ( failed.length ) throw "some of the save operation failed. breaking execution.";
					if ( titles.length ) {
						message.text( 'null edits completed within ' + ( new Date() - start ) + ' milliseconds. ' + titles.length + ' pages left. next batch on ' + new Date( new Date().getTime() + 62000 ) );
						setTimeout( dobatch, 0 );
					} else {
						mw.notify( 'finished refresing all. please refresh category page' );
						message.remove();
					}
				} );
			} // if batch.length
		}
	} );// res.done
} );	// load api and user
} ); 	// click
} ); 	// load util