MediaWiki talk:Gadget-UTCLiveClock.js

Update February 2011
I've updated the script to be fully compatible with Vector and 1.17 while still being compatible with Monobook and 1.16. It has been tested in the following set-ups: See also 74740. Krinkle 14:57, 1 February 2011 (UTC)
 * 1.16wmf4 Vector (MediaWiki.org)
 * 1.16wmf4 Monobook (MediaWiki.org)
 * 1.17alpha Vector (prototype)
 * 1.17alpha Monobook (prototype)
 * trunk Vector (TranslateWiki)
 * trunk Monobook (TranslateWiki)
 * I already did it attranslatewiki:MediaWiki:Gadget-UTCLiveClock.jsMax Semenik 15:07, 1 February 2011 (UTC)
 * I didn't see that but now that I see it, I must say that it doesn't work (function showTime is not defined when the ready-statement fires early) and it still removes the tag, which was kindof the main bug. 15:21, 1 February 2011 (UTC)
 * Heh, someone broke it. Again. Max Semenik 18:55, 1 February 2011 (UTC)

Use on a Style-sheet
Would this code work, for all users on compatible skins, if simply placed on MediaWiki:Common.js? --George2001hi 09:48, 26 April 2011 (UTC)
 * Yes, it should work fine (its definition doesn't indicate any dependencies). Helder 11:42, 18 October 2012 (UTC)

Documentation for gadget authors
We're trying to start a library for gadget authors to use. Please check it out and post any questions or comments there. -- ☠ MarkAHershberger ☢ (talk) ☣ 01:40, 9 March 2012 (UTC)

Improvment of the clock gadget
This gadget and other clocks have the common problem of skipping some seconds : for example, the clock may display 11:20:35 just after 11:20:33 (skipping 11:20:34). It occurs because display function may be called at bad moment within the second (for the previous example at 11:20:33.995 then at 11:20:35.005).

I propose to improve the gadget by using the millisecond value to schedule next execution at hh:mm:ss.100 which give enough time (900ms) to execute the display function.

In the showTime function : --DavidL (talk) 11:04, 23 June 2012 (UTC)


 * Did this ever get incorporated? Sounds like a sound idea to me. — T13   ( C • M • Click to learn how to view this signature as intended ) 16:47, 27 March 2013 (UTC)


 * The above screenshot image shows another difference between the 2 versions of the gadget: the modified one (on the right side, displaying local time UTC+0200) always display time about 1 second before the former one.
 * --DavidL (talk) 09:57, 21 April 2013 (UTC)
 * (Hexmode asked me to leave a message) You could also use a fixed delay of  instead of   or instead of  . That should also fix the problem. Using   might also be useful – though the benefit (no overhead from inactive tabs, and saving browser redraws by letting the browser pick the time) might not be worth the cost since it'd be a no-op most of the time (up to 60 frames a second). Both the suggestion here  and a fixed   will work fine I think. Krinkle (talk) 17:58, 20 May 2013 (UTC)
 * Any fixed delay won't fix the problem. A variable delay is necessary to adjust time at each iteration according to client current CPU usage.
 * With a fixed delay of 900ms (your suggestion), you may have
 * (CPU is not busy):
 * 11:00:05.100
 * 11:00:06.000
 * 11:00:06.900
 * 11:00:07.800
 * (CPU is busy, script sleep for more than the specified 900ms):
 * 11:00:05.100
 * 11:00:06.001 (+1 ms)
 * 11:00:06.905 (+4 ms)
 * 11:00:07.811 (+6 ms)
 * -> 11:00:06 is displayed twice in both cases.
 * With a fixed delay of 1000ms (current version), you may have
 * (CPU is not busy):
 * 11:00:05.995
 * 11:00:06.995
 * 11:00:07.995
 * 11:00:08.995
 * (CPU is busy, script sleep for more than the specified 1000ms):
 * 11:00:05.995
 * 11:00:06.998 (+3 ms)
 * 11:00:08.001 (+3 ms)
 * 11:00:09.008 (+7 ms)
 * -> 11:00:07 is not displayed at all. Problem arise when CPU is a bit busy but also because displaying take a non-zero time which depends on client CPU speed.
 * With an adjusted time as I suggest, you may have
 * (CPU is not busy, script sleep for an adjusted delay):
 * 11:00:05.995 (sleep for 1100-ms = 105ms)
 * 11:00:06.100 (sleep for 1100-ms = 1000ms)
 * 11:00:07.100 (sleep for 1100-ms = 1000ms)
 * 11:00:08.100 (sleep for 1100-ms = 1000ms)
 * (CPU may be busy or not, script sleep for an adjusted delay):
 * 11:00:05.995 (sleep for 1100-ms = 105ms)
 * 11:00:06.109 (+9 ms) (sleep for 1100-ms = 991ms)
 * 11:00:07.111 (+11 ms) (sleep for 1100-ms = 989ms)
 * 11:00:08.105 (+5 ms)
 * -> The time is always displayed near the 100ms within the second. The timer have a maximum late delay of 899 ms to absorb CPU load effect.
 * --DavidL (talk) 13:35, 25 May 2013 (UTC)
 * Your sample code shows that a fixed delay of 900ms clearly does work. It doesn't skip any seconds (granted that the thread doesn't block for more than a second, in which case it'll skip no matter what we do). It does result in the same value for the second indicator twice (you suggested this only happens with a busy CPU but it will happen without that too, the 900 increment will naturally at some point end up going from 900 instead of rolling over to the next second). But it won't skip any and it fixes the problem.
 * However, from a user experience point of view the 900 increment introduces a different problem, namely that it will routinely cause the second to appear to "freeze" for 1800ms and then naturally catch up again through the 100ms negative overlaps. The dynamically calculated increments are as good as it gets within the unreliable nature of  (short of going full-on with   and joining the available redraw frames if available and only updating if the second has changed). Krinkle (talk) 10:09, 26 May 2013 (UTC)

MWDeprecationWarning: Use of "appendCSS" property is deprecated.
I'm getting the error above on Portuguese Wikipedia. Could someone update the gadget? ? –Helder 12:23, 9 November 2013 (UTC)
 * ✅, Thanks! Krinkle (talk) 20:27, 3 December 2013 (UTC)

Mediawiki Version 1.24.2
Is it correct, that this clock is supposed to display the server time, not the local time? Is there some parameter to adjust ist?--&#91;&#91;User:Bmrberlin&#124; Bernd M.&#93;&#93; (talk) 10:54, 22 April 2015 (UTC)
 * That is correct, no there isn't. Technical 13/Scripts/Gadget-LiveClock.js (doc) is a userscript version that displays your local time (UTC on mouseover).  I haven't used it in some time, so if it doesn't work, just let me know and I'll make any needed fixes.  To use the script:
 * needs to be added you Special:MyPage/common.js or meta:Special:MyPage/global.js depending on if you only want it to work on the current wiki or all WMF wikis. —  17:53, 22 April 2015 (UTC)

Thank you for this quick response.--&#91;&#91;User:Bmrberlin&#124; Bernd M.&#93;&#93; (talk) 18:27, 22 April 2015 (UTC)

causes unwanted log out clicks
I've been a longtime user of this gadget. One problem I've noticed many times is that the clock loads after the rest of the toolbar. This can causes the user to accidentally log out. Here's a typical scenario:


 * 1) editor visits Wikipedia
 * 2) page starts rendering
 * 3) editor quickly moves mouse to "Contributions" link and clicks on it
 * 4) editor realizes they forgot to let clock load
 * 5) finally load of clock, which pushes all the toolbar items to the left
 * 6) finally browser starts to process click, which is now over "Log out" instead of "Contribution".
 * 7) editor gets logged out.
 * 8) curses ensue

The speed of the computer plays an important role here but it can happen even on fast computers for reckless mouse clickers like me.

Is it technically feasible to have this gadget load before the toolbar items? Jason Quinn (talk) 23:12, 20 August 2015 (UTC)
 * I would prefer if the link were moved just a little bit below the portlet menu. E.g. by creating a second inside the  That way, the default links would not be moved at all. Helder 18:16, 29 August 2015 (UTC)
 * This happened to me once, recently. I think I am more used to the page scrolling up and down than those links moving, making Helder's idea look better. PC-XT (talk) 06:56, 15 February 2016 (UTC)

Please merge with MediaWiki:Gadget-LocalLiveClock.js
Can we made this gadget obsolete per option? The variable can be read also from the user-settings #Time-offset.  → User: Perhelion 23:12, 12 May 2016 (UTC)

New version, prevents menu from jumping
Hello all. I've drafted a new version of this gadget at User:Mr. Stradivarius/UTCLiveClock.js that, when coupled with the CSS in my common.css, prevents the clock from making the personal toolbar jump to the left when it loads. I've already copied the CSS to these files: All that needs to be done to deploy it on this wiki is to copy the JS over, and add the new CSS pages to MediaWiki:Gadgets-definition. For other wikis, the CSS files will need to be copied, and MediaWiki:Gadgets-definition updated as well.
 * MediaWiki:Gadget-UTCLiveClock.css - sets an explicit width for the clock; loaded as part of the clock gadget
 * MediaWiki:Gadget-UTCLiveClock-pagestyles.css - reserves whitespace for the clock; loaded as a CSS-only peer gadget

Getting rid of the jumping effect would be a huge plus in my opinion, but there are downsides too. Currently, you can change the location of the clock by adding a  object to your personal .js file, but this won't be possible with my new version. This is because we need to reserve space for the gadget using CSS only, and I can't think of a way to make this work if the location of the clock isn't guaranteed to be the same every time.

I made a search of all Wikimedia wikis using a script that I made, and I found three users who use UTCLiveClockConfig to change the location of the clock. David Levy, Gamren, and HarJIT: would it be OK to make the change? If you really want to have the clock in a non-default location, let me know - if I make some adjustments to the JavaScript, and if you load the script directly from your personal .js, it is possible.

Also, I would be grateful if people could review my code. If there's something I could do better - or something I've done wrong - then it would be better to find out now, rather than after the code has been deployed, as this gadget is widely used. Best — Mr. Stradivarius  ♪ talk ♪ 14:31, 28 September 2017 (UTC)
 * If all you've done with your JS is add those two  lines of code, it all looks good to me. Thanks for doing this, and finding the people who would be adversely affected. Perhaps they only moved the positioning because they were sick of it jumping around, too? &mdash;  MusikAnimal  talk  15:24, 28 September 2017 (UTC)


 * I don't really care where the clock is, as long as its loading doesn't cause jumping.__Gamren (talk) 15:56, 28 September 2017 (UTC)


 * I'm not actually moving the clock as far as Wikimedia wikis are concerned (I'm placing it before a non-existent ID, which just appends it). I specify it because I import my Wikimedia MetaWiki global.js in my Wikia global.js, and Wikia's notifications code on their version of Monobook will fold the clock into the notification area (which breaks it) unless it is placed before rather than after the . But I'm loading the gadget with   specifying an , so that wouldn't be affected by the changes. So by all means, go ahead. -- HarJIT (talk) 18:11, 28 September 2017 (UTC)


 * Thank you all for your feedback. I've gone ahead and rolled the gadget out here and at enwiki. I would do it at other wikis too, but I only have admin rights here and at enwiki (well, and testwiki too). Maybe we could put together a mass message for wikis that have this gadget installed? — Mr. Stradivarius  ♪ talk ♪ 15:25, 29 September 2017 (UTC)