User:Wuzur/clock.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at User:Wuzur/clock. |
- Report page listing warnings and errors.
// UTC Live Clock
// Created by [[w:User:AzaToth]]
//
// Adds a clock in the personal toolbar that shows the current time in UTC, and provides a purge link.
function liveClock()
{
liveClock.node = mw.util.addPortletLink( 'p-personal', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wgPageName + '&action=purge', '', 'utcdate' );
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 time = 'UTC: ' + ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm );
if (dateNode.firstChild && dateNode.firstChild.firstChild) {
dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );
}
window.setTimeout(showTime, 1000);
}