Jump to content

User:Alexis Jazz/RedirectCommonsRedirects.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//small script that redirects from file pages that show a Commons redirect to what you'd see if the Commons redirect didn't exist. Also un-redirects you from followed redirects. See description page for reference.<nowiki>
if ( mw.config.get('wgDBname') != 'commonswiki' ) {
	var filename = window.location.href.replace( /.*title=/, '').replace( /\?.*/, '' ).replace( /\&.*/g, '').replace( /.*\//g, '').replace( /:/g, '%3A');
	if ( mw.config.get('wgNamespaceNumber') == 6 && mw.config.get('wgArticleId') == 0 && mw.config.get('wgAction') == 'view' && encodeURIComponent(mw.config.get('wgPageName')) != filename && window.location.href.search( 'redirect=no') == -1 ) {
		var redirecturl = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace( '$1', filename) + '?redirect=no';
		window.setTimeout(function() { window.location = redirecturl }, 1000 );
	}
	if ( $('.mw-redirectedfrom')[0] && mw.config.get('wgNamespaceNumber') == 6 ) {
		window.setTimeout(function() { window.location = $('.mw-redirectedfrom a')[0].href }, 1000 );
	}
}//</nowiki>