User talk:Ilmari Karonen/liveclock.js

Latest comment: 5 years ago by MZMcBride in topic Legacy JavaScript

Legacy JavaScript edit

Hello! This script has been detected as using deprecated parameters that need to be replaced with the updated version. Examples include addOnloadHook( ... ) needs to be replaced with $( ... ) or $( function() { ... } ) (depending on use); all wgGlobalVariables need to be properly gotten with mw.config.get( 'wgGlobalVariable' ); and addPortletLink needs to be called with mw.util.addPortletLink. Please see MW:ResourceLoader/Legacy JavaScript for details. Thank you. — {{U|Technical 13}} (etc) 21:30, 19 January 2015 (UTC)Reply

I'm finally trying to clean up my browser developer console warnings and I happen to use this script. :-) --MZMcBride (talk) 03:38, 10 March 2016 (UTC)Reply

Technical 13 and MZMcBride how about moving to a page that isn't a subpage of a basically retired user? — xaosflux Talk 03:49, 10 March 2016 (UTC)Reply
I think Ilmari is still around-ish. Digging up the old discussion, my guess is that mw:MediaWiki:Gadget-UTCLiveClock.js is probably fine to use these days. Maybe I should just switch to that. --MZMcBride (talk) 04:07, 10 March 2016 (UTC)Reply

The gadget kind of sucks. It unconditionally includes the seconds and it has dumb default formatting that requires more code to override. I don't really want to move this script in case people are relying on its current location. Can an admin please update the page contents with what's below? It should resolve most of the console warnings. (addOnloadHook still needs to be addressed, but we can do that later.) Thanks! --MZMcBride (talk) 20:47, 12 March 2016 (UTC)Reply

/* To turn on seconds display, add the following line to your monobook.js:
window.liveClockShowSeconds = true;
*/

addOnloadHook(function () {
  var tabNode = mw.util.addPortletLink(
      "p-personal",
      mw.config.get( 'wgScript' ) + "?title=" + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + "&action=purge",
      "",
      "utcdate"
  );
  var linkNode = tabNode.getElementsByTagName("a")[0];

  var updateTimeSeconds = function () {
    var now = new Date ();
    var h = now.getUTCHours();
    var m = now.getUTCMinutes();
    var s = now.getUTCSeconds() + (now.getUTCMilliseconds() >= 500 ? 1 : 0);
    linkNode.innerHTML = (h<10?"0":"") + h + (m<10?":0":":") + m + (s<10?":0":":") + s;
    setTimeout(updateTimeSeconds, 1500 - ((now.getTime() + 500) % 1000));
  };

  var updateTimeMinutes = function () {
    var now = new Date ();
    var h = now.getUTCHours();
    var m = now.getUTCMinutes() + (now.getUTCSeconds() >= 30 ? 1 : 0);
    linkNode.innerHTML = (h<10?"0":"") + h + (m<10?":0":":") + m;
    setTimeout(updateTimeMinutes, 90000 - ((now.getTime() + 30000) % 60000));
  };

  if (window.liveClockShowSeconds) updateTimeSeconds();
  else updateTimeMinutes();
});
  Done HOWEVER, MZMcBride I strongly recommend forking this to a gadget, or to somewhere it is not dependent on an inactive editor's userpage. — xaosflux Talk 15:19, 13 March 2016 (UTC)Reply
Now forked to User:MZMcBride/liveclock.js. --MZMcBride (talk) 03:05, 9 August 2018 (UTC)Reply