Jump to content

User:X!/friendlyclock.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by X! (talk | contribs) at 03:38, 12 March 2010 (modification). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
// If FriendlyConfig aint exist.
if( typeof( FriendlyConfig ) == 'undefined' ) {
	FriendlyConfig = {};
}

/**
 FriendlyConfig.enableClock ( boolean )
 */
if( typeof( FriendlyConfig.enableClock ) == 'undefined' ) {
	FriendlyConfig.enableClock = true;
}

/**
 FriendlyConfig.clockStyle ( String )
 */
if( typeof( FriendlyConfig.clockStyle ) == 'undefined' ) {
	FriendlyConfig.clockStyle = 'dynamic';
}

friendlyclock = {
	showClock: function() {
		var query = {
			'action': 'purge',
			'title': wgPageName
		};
		friendlyclock.clockNode = addPortletLink( 'p-personal', wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), '--:--:-- UTC', 'friendly-clock', 'Purge this page', '' );
		friendlyclock.clockNode.style.fontSize = 'normal';
		friendlyclock.clockNode.style.fontWeight = 'bold';
		friendlyclock.clockNode.style.textTransform = 'uppercase';
		
		friendlyclock.updateTime();
		if( FriendlyConfig.clockStyle != 'static' ) {
			friendlyclock.intervalId = window.setInterval(friendlyclock.updateTime, 1000);
		}
	},
	updateTime: function() {
		if( !friendlyclock.clockNode ) {
			return;
		}
		var now = new Date();
		var yy = now.getUTCFullYear();
		var mo = now.getUTCMonth();
		var dd = now.getUTCDate();
		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) + ', ' + ( mo < 10 ? '0' + mo : mo ) + '/' + ( dd < 10 ? '0' + dd : dd ) + '/' + yy + ' UTC';
		friendlyclock.clockNode.firstChild.innerHTML = time;
	}
}

addOnloadHook( function() {
		if( FriendlyConfig.enableClock ) {
			friendlyclock.showClock();
		}
	}
);