Bureaucrats, editor, Interface administrators, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Editors (Semantic MediaWiki), Administrators
47,390
edits
No edit summary Tag: Manual revert |
No edit summary |
||
Line 1:
"use strict";
/**
* Adapted from https://www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js
*/
(
function padWithZeroes(num) {
// Pad a number with zeroes. The number must be an integer where
// 0 <= num < 100.
return num < 10 ? '0' + num.toString() : num.toString();
}
function showTime($target) {
var now = new Date();
var hh = now.getUTCHours();
var mm = now.getUTCMinutes();
var time = padWithZeroes(hh) + ':' + padWithZeroes(mm);
$target.text(time);
// Schedule the next time change.
//
// We schedule the change for 100 ms _after_ the next clock tick. The delay
// from setTimeout is not precise, and if we aim exactly for the tick, there
// is a chance that the function will run slightly before it. If this
// happens, we will display the same time for two seconds in a row - not
// good. By scheduling 100 ms after the tick, we will always be about 100 ms
// late, but we are also very likely to display a new time every second.
var ms = now.getUTCMilliseconds();
setTimeout(function () {
showTime($target);
}, 1100 - ms);
}
function liveClock() {
// Add the portlet link.
var node = mw.util.addPortletLink('p-personal',
// portletId
'#',
// href
'',
// text
'utcdate',
// id
'The current UTC time',
// tooltip
'',
// accesskey
'#pt-theme-toggles' // nextnode
);
if (!node) {
return;
}
/* We got a purge link in the More menu dropdown - this isn't needed
// Purge the page when the clock is clicked. We have to do this through the
// API, as purge URLs now make people click through a confirmation screen.
$( node ).on( 'click', function ( e ) {
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () {
location.reload();
}, function () {
mw.notify( 'Purge failed', { type: 'error' } );
} );
e.preventDefault();
} );
*/
// Show the clock.
showTime($(node).find('a:first'));
}
$(liveClock);
})();
|