Jump to content

User:Arichnad/utc clock.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Jon (WMF) (talk | contribs) at 17:42, 16 February 2021 (maintenance: more info Uncaught ReferenceError: hookEvent is not defined). The present address (URL) is a permanent link to this version.
(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.
 function zero(num) {return num<10 ? "0"+num : num;}
 var textNode;
 function putDateInHeading() {
 	textNode = document.createTextNode("");
 	
 	var element = document.createElement('li');
 	element.appendChild(textNode);
 	element.id = "pt-datetime";
 	
 	var list = document.getElementById('p-personal').getElementsByTagName('ul')[0];
 	list.appendChild(element);
 }
 function updateTime() {
 	var date = new Date();
 	var str = date.getUTCDate() + " " + zero(date.getUTCHours()) + ":" + zero(date.getUTCMinutes());
 	textNode.nodeValue = str;
 	var waitSeconds = 60-date.getUTCSeconds()+1;
 	window.setTimeout(updateTime, waitSeconds*1000);
 }
 function setup() {
 	putDateInHeading();
 	updateTime();
 }

$(setup);