Jump to content

User:DannyS712 test/commons.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.
// Install with:
// <code><nowiki>		{{subst:Iusc|User:DannyS712/View Commons}}																				</nowiki></code>
// or with
// <code><nowiki>		importScript( 'User:DannyS712/View Commons' ); // Backlink: [[User:DannyS712/View Commons]] 							</nowiki></code> 
//
// If forking this script, please note my contributions / give me credit
//<nowiki>
$(function (){
var View_Commons_config = {
	name: '[[User:DannyS712/View Commons|View Commons.js]]',
	version: 1.0,
	debug: false
};

mw.loader.using( 'mediawiki.util', function () {
    $(document).ready( function () { 
    	var page = mw.config.get('wgCanonicalNamespace');
    	if (page && page == "File") {
    		var current = window.location.href;
    		var target = current.replace(/en.wikipedia/i, 'commons.wikimedia');
    		if (View_Commons_config.debug) console.log ( target );
    		mw.util.addPortletLink ( 'p-cactions', target, 'View on commons', 'ca-commons-link', 'View this page on commons');
    	}
    } );
} );
});
//</nowiki>