MediaWiki:Gadget-UTCLiveClock.js

Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  • Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
  • Opera : appuyez sur Ctrl + F5.
 // 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()
{

        var personal = 'p-personal';
        if (mw.config.get('skin') === "vector") {
        personal = "personal";
        }
	liveClock.node = mw.util.addPortletLink( personal, mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName') + '&action=purge', '', 'utcdate' );
        if (mw.config.get('skin') !== "vector") { //large font looks like crap on vector
	        liveClock.node.style.fontSize = 'larger';
        }
	liveClock.node.style.fontWeight = 'bolder';

	showTime();
}
$(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);
}