MediaWiki:Gadget-UTCLiveClock.js

This is an old revision of this page, as edited by AzaToth (talk | contribs) at 23:47, 11 January 2008 (moved User:AzaToth/liveclock.js to MediaWiki:Gadget-UTCLiveClock.js: Gadgetfy). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
function liveClock()
{
	var query = {
		'title': wgPageName,
		'action': 'purge'
	};
	liveClock.node = addPortletLink( 'p-personal', wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), '', 'utcdate' );
	liveClock.node.style.fontSize = 'larger';
	liveClock.node.style.fontWeight = 'bolder';

	showTime();
}
addOnloadHook(liveClock)

function showTime()
{

	var dateNode = liveClock.node;
	if( !dateNode ) {
		return;
	}
    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.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );

    window.setTimeout(showTime, 1000);
}