MediaWiki:Gadget-purgeindex.js

From Wikisource
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
(function($){
    $.fn.regex = function(pattern, fn, fn_a){
        fn = fn || $.fn.text;
        return this.filter(function() {
            return pattern.test(fn.apply($(this), fn_a));
        });
    };
})(jQuery);

$( function ()  {
	if (
		mw.config.get( 'wgPageContentModel' ) !== 'proofread-index' ||
		mw.config.get( 'wgAction' ) !== 'view' 
	)
	{
		return;
	}
	var pagensname = encodeURI(mw.config.get( 'wgFormattedNamespaces' )[mw.config.get( 'wgNamespaceIds' ).page]);
	var patt1;
	if ( pagensname == 'Page' )
	{
		patt1 = new RegExp("^\/wiki\/Page:.*");
	}
	else
	{
		patt1 = new RegExp("^\/wiki\/(Page|" + pagensname + "):.*");
	}
	if ( $('#mw-content-text a:not(a[class])').regex(patt1, $.fn.attr, ['href']).length === 0 )
	{
		return;
	}
	mw.notify( 'Refreshing', { type: 'info' } );
	new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then(function () {
			location.reload();
	}, function () {
			mw.notify( 'Refresh failed', { type: 'error' } );
	});
} );