User:Crtke/js/fastpassToJa.js

$( function {	'use strict';	var title = mw.config.get( 'wgTitle' );	var namespace = mw.config.get( 'wgCanonicalNamespace' );	var specialPagename = mw.config.get( 'wgCanonicalSpecialPageName' );	var uploadAutoFill = mw.config.get( 'wgUploadAutoFill' );	var filledFilename = $( '#wpDestFile' ).val;	var urlParams = location.search;

// Only run on pages that pagename is only alphanumeric characters if ( !/^[\x01-\x7E]+$/.test( title ) && !specialPagename ) return;

var resultPagename = uploadAutoFill === false && /^[\x01-\x7E]+$/.test( filledFilename ) ? 'File:' + filledFilename : specialPagename ? namespace + ':' + specialPagename : ( namespace ? namespace + ':' : '' ) + title;

var html = genLinkHtml( resultPagename, '対応する日本語版ページに移動', '日本語版' );

if ( urlParams ) { var prefix = ''; var suffix = paramsList( urlParams ) || urlParams || ''; var resultPagenameWithParams = prefix + resultPagename + suffix; html += genLinkHtml( resultPagenameWithParams, '正確に対応する日本語版ページに移動', '日本語版 (A)' ); }

$( '#left-navigation ul' ).append( html );

function paramsList( urlParams ) { var paramsPos = urlParams.indexOf( '&' ); var params = urlParams.slice( paramsPos );

if ( paramsPos === -1 ) { return; } else { return params; }	}

function genLinkHtml( pagename, title, label ) { return [ '', ' ',					'', label, '', ' ',			'' ].join( '' ); } } );