User:Davidgothberg/clock.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Davidgothberg/clock. |
/***** DavidClock **************************************************
Puts an UTC clock in the upper right corner of all pages.
It also has a link to purge the current page. (Click the clock
to purge the page.) If both the ticking and static clock is used,
then the static clock has a link to edit section 0.
To use this script put this code in your
[[User:Yourname/monobook.js]] page:
importScript( "User:Davidgothberg/clock.js" );
Default is a clock that ticks once a minute and a static clock
that shows when the page was loaded. This can be changed
by adding one of the lines below to your "/monobook.js" page.
Don't set below 60 seconds on slow computers.
window.davidClock = -60; //Only ticking clock, every minute.
window.davidClock = -5; //Only ticking clock, every 5 seconds.
window.davidClock = 0; //Only static clock
window.davidClock = 5; //Static + ticking clock, every 5 seconds.
window.davidClock = 60; //Static + ticking clock, every minute.
window.davidClock = 120; //Static + ticking clock, every 2 minutes.
Technical details:
Only thing that runs on each tick is the inner function
updateTimeMinutes() or updateTimeSeconds().
Works in the follow Wikipedia skins: MonoBook, Chick, Modern,
MySkin, Simple. Has no effect in the other skins.
Tested and works in Firefox 2.0, Opera 9.02 and Internet Explorer 5.5.
Based on code from [[User:AzaToth]], [[User:Ilmari Karonen]] and
[[User:Voice of All]].
Maintainer: [[User:Davidgothberg]]
*/
/* DavidClock */
addOnloadHook( function() {
var static = true;
var tick = 60;
/* If the user has not declared "window.davidClock = x;"
then none of these if-cases become true, and the defaults
above will be used. */
if( window.davidClock >= 0 ) {
tick = window.davidClock;
}
else if( window.davidClock < 0 ) {
static = false;
tick = 0 - window.davidClock;
}
/* Optimised ticker for 60 seconds or longer tick intervals. */
function updateTimeMinutes() {
var now = new Date();
linkNode.innerHTML = now.toUTCString().substring(17,22);
setTimeout( updateTimeMinutes, tick * 1000 );
};
/* Optimised ticker for 1-59 seconds tick intervals. */
function updateTimeSeconds() {
var now = new Date();
linkNode.innerHTML = now.toUTCString().substring(17,25);
setTimeout( updateTimeSeconds, tick * 1000 );
};
/* Start the ticking clock. */
if( tick ) {
var tabNode = addPortletLink( 'p-personal', wgScriptPath
+ '/index.php?title=' + encodeURIComponent(wgPageName)
+ '&action=purge', '', 'pt-utcticker', 'Purge the page' );
tabNode.style.fontWeight = 'bolder';
var linkNode = tabNode.getElementsByTagName("a")[0];
if( tick >= 60 ) {
updateTimeMinutes();
}
else {
updateTimeSeconds();
}
}
/* Create the static clock. */
if( static ) {
if( tick ) { /* Make it an edit section 0 link. */
var link = wgScriptPath + '/index.php?title='
+ encodeURIComponent(wgPageName) + '&action=edit§ion=0';
var linkTooltip = 'Edit section 0';
}
else { /* Make it a purge link. */
var link = wgScriptPath + '/index.php?title='
+ encodeURIComponent(wgPageName) + '&action=purge';
var linkTooltip = 'Purge the page';
}
var now = new Date();
var linkText = now.toUTCString().substring(17,22);
addPortletLink( 'p-personal', link, linkText, 'pt-utcstatic', linkTooltip );
}
} ); /* End DavidClock */