Jump to content

User:Chieftain Alex/vector clock.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.
/** Clock **
 *  Time bit salvaged from [[mediawikiwiki:MediaWiki:Gadget-UTCLiveClock.js]] by [[User:AzaToth]]
 *  Portlet bit from [[mediawikiwiki:ResourceLoader/Default_modules#addPortletLink]]
 *  For use with the Vector skin.
 */

var clockLink = mw.util.addPortletLink( 'p-personal', '/wiki/' + wgPageName + '?action=purge', 'UTC time', 'ca-clock',
                                        'Purge the server cache and update the contents of this page.', '', '#pt-userpage' );
clockLink.style.textTransform = 'uppercase';
clockLink.style.fontWeight = 'bold';

function showTime ()
{
  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) + ' (UTC)';
  clockLink.firstChild.replaceChild (document.createTextNode (time), clockLink.firstChild.firstChild);
  window.setTimeout (showTime, 1000);
}
showTime();