Jump to content

User:Alfa Star/common.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.
// <syntaxhighlight lang="JavaScript">

function liveClock() {
	var link = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent( wgPageName ) + '&action=purge';
	if ( skin === 'monobook' ) {
		$( '#p-personal .pBody ul' ).append( '<li id="utcdate"><a href="' + link + '"></a></li>' );
	} else if ( skin === 'oasis' ) {
		$( '#WikiaPage #WikiHeader div.buttons' ).prepend( '<div id="utcdate"><a href="' + link + '"></a></div>' );
	}
	$( '#utcdate' ).css( { fontSize: 'larger', fontWeight: 'bolder', textTransform: 'none' } );

	showTime();
}
$( liveClock );

function showTime() {
	var	now = new Date(),
		hh = now.getUTCHours(),
		mm = now.getUTCMinutes(),
		ss = now.getUTCSeconds(),
		dd = now.getUTCDate(),
		months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
		month  = months[now.getUTCMonth()],
		year   = now.getUTCFullYear(),
		time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss ) + ', ' + ( dd < 10 ? '0' + dd : dd ) + ' ' + month + ' ' + year + ' (UTC)';
	$( '#utcdate a' ).text( time );

	window.setTimeout( showTime, 1000 );
}

// </syntaxhighlight>