User:Aude/nearby.js

( function ( mw, $ ) {

function setMessages { switch ( mw.config.get( 'wgUserLanguage' ) ) { default: case 'en': mw.messages.set( {				'gadget-nearby': 'Nearby'			} ); break; } }

function init { var action = mw.config.get( 'wgAction' ), $indicators, $nearbyEl; if ( action === 'view' ) { if ( mw.config.get( 'wgNamespaceNumber' ) != 0 ) { return; }		if ( document.getElementById( 'coordinates' ) == null ) { return; }		if ( mw.config.get( 'skin') == 'minerva' ) { $indicators = $( '#page-actions' ); $nearbyEl = $( '' ); } else { $indicators = $( '.mw-indicators' ).first; $nearbyEl = $( ' ' ); }

if ( $indicators.find( '#mw-indicator-nearby' ).length > 0 ) { return; }

setMessages;

var nearbyText = mw.msg( 'gadget-nearby' );

$nearbyEl .addClass( 'mw-indicator mw-indicator-nearby' ) .attr( {				id: 'mw-indicator-nearby',				title: nearbyText,				alt: nearbyText			} ) .appendTo( $indicators ) .click( function( e ) {				var url = window.location.origin + '/wiki/Special:Nearby#/page/' + mw.config.get( 'wgPageName' );				window.location.replace( url );			} ); } }

$( init );

}( mediaWiki, jQuery ) );