User:Sonicwave/common.js

// Courtesy of https://terraria.gamepedia.com/MediaWiki:Gadget-utcClock.js

var lang = function ( message ) { return "Click to purge cache for current page"; }

var linkPurge = mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&action=purge';

var clockStyle = 'font-weight:bolder; color:#fff; font-size:150%;';

window.showTime = function { var now = new Date; var hh = now.getUTCHours; var mm = now.getUTCMinutes; var ss = now.getUTCSeconds; var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss ); $('.dateNode').text( time ); var ms = now.getUTCMilliseconds; setTimeout( function {		showTime;	}, 1100 - ms ); }

$(function {	$('.netbar-box.right:first').before('  ');	showTime; });

// https://terraria.gamepedia.com/MediaWiki:Gadget-ImageForeignUseCheck.js - should list file usage from other wikis

var wgNamespaceNumber = mw.config.get( 'wgNamespaceNumber' ); var wgPageName = mw.config.get( 'wgPageName' ); var wgTitle = mw.config.get( 'wgTitle' );

if (wgNamespaceNumber == 6) { $('#filetoc').append(		$('').append( $('', {'class':'foreignLink', 'href':'#foreign', 'text':'List foreign uses'}) )	);	$('#mw-imagepage-nolinkstoimage').append(		$('', {'class':'foreignLink', 'href':'#foreign', 'text':' (List foreign uses)'})	); $('.foreignLink').click(function{		$('.interUses').remove;		$('div[id$="linkstoimage"]').append($('', {'class':'interUses'}));		var $interUses = $('.interUses');		var URLprefix = 'https://', 			URLsuffix = '.gamepedia.com/api.php?format=json&callback=?';		var msgForeignUses = 'Foreign uses',			msgImageLink = 'file page',			msgNoUses = 'No foreign uses of this file were detected.';		$interUses.append( $(' ', {'text':msgForeignUses, 'style':'margin-left:-22px;'}) );		var langs = {			"Russian":"minecraft-ru",			"French":"minecraft-fr",			"Polish":"minecraft-pl",			"Chinese":"minecraft-zh",			"Dutch":"minecraft-nl",			"German":"minecraft-de",			"Japanese":"minecraft-ja",			"Ukrainian":"minecraft-uk",			"Czech":"minecraft-cs",			"Hungarian":"minecraft-hu",			"Portuguese":"minecraft-pt",			"Greek":"minecraft-el",			"Italian":"minecraft-it",			"Korean":"minecraft-ko",			"Spanish":"minecraft-es", "Thai":"minecraft-th", "Turkish":"minecraft-tr" };		$interUses.append( $(' ', {'text': msgNoUses, 'class':'no_foreign_uses'}) ); $.each(langs, function(key, value) {			var currentLangCode = value;			var request2 = { action:'query', list:'allimages', ailimit:'1',	aifrom:wgTitle }			$.getJSON(URLprefix + currentLangCode + URLsuffix, request2, function(response2) { $.each(response2.query.allimages, function(index, value){					if (value.name != wgTitle.replace(/ /g,'_')){						var request1 = { action:'query', list:'imageusage', iutitle:wgPageName };						$.getJSON(URLprefix + currentLangCode + URLsuffix, request1, function(response1) { var currentLangName = key; if (response1.query.imageusage.length > 0) { var urlImage = URLprefix + currentLangCode + '.gamepedia.com/' + wgPageName; $('.no_foreign_uses').remove; $interUses.append(									$(' ', {'style':'margin-left:-20px;', 'text':currentLangName}).append( $(' ', {'style':'font-size:85%;'}).append(											' (', $('', {'href':urlImage, 'text':msgImageLink}), ')'										) )								);								$.each(response1.query.imageusage, function(index, value) {									var urlUse = URLprefix + currentLangCode + '.gamepedia.com/' + value.title;									$interUses.append( $('').append(											$('', {'href': urlUse, 'text':value.title})										) );								});							}						});					}				});			});		});	setTimeout(function{$interUses[0].scrollIntoView(true)}, 1000); }); }

// https://terraria.gamepedia.com/MediaWiki:Gadget-redirect-modifier.js

$(function {	$("a,a *").click(function(event) { if (!event.altKey) return; h = $(event.target).attr("href"); if (h.indexOf("?")==-1) h+="?redirect=no"; else h+= "&redirect=no"; $(event.target).attr("href", h); location.href = h;	}); });