Help:UTC clock

From Homestar Runner Wiki

Jump to: navigation, search

The following JavaScript and CSS code will add a UTC clock to every wiki page. This can be useful for comparing comment timestamps to the current time. The code was originally taken from Wikipedia:WikiProject User scripts/Scripts/Time, but it has been modified slightly for use on our modified version of the MonoBook skin.

Note that this clock tells time relative to your computer's local time. It doesn't get its time from the wiki server. If the time or the time zone is set incorrectly on your computer, the adjustment for UTC may be calculated incorrectly.

Contents

[edit] Just below the personal menu

Example 1

Use this version of the script to place the time just below your personal menu to the far right of the page action tabs.

[edit] Javascript

Put this in your monobook.js file.

// Add UTC time just below the "personal menu" list at the top of the page.
// Created by Wikipedia:User:Mathwiz2020, modified by User:JoeyDay
//
function getTime() {
  var time = new Date();
  var hours = time.getUTCHours();
  if (hours < 10) { hours = "0" + hours; }
  var minutes = time.getUTCMinutes();
  if (minutes < 10) { minutes = "0" + minutes; }
  var currentTime = hours + ":" + minutes
  document.getElementById('pt-time').childNodes[0].childNodes[0].replaceData(0, 5, currentTime);
  doTime = window.setTimeout("getTime()", 1000);
}
function makeTime() {
  var div = document.createElement( 'div' );
  div.id = 'pt-time';
  var mySpan = document.createElement( 'span' );
  mySpan.appendChild( document.createTextNode( '00:00 UTC' ) );
  div.appendChild( mySpan );
  document.getElementById( 'globalWrapper' ).parentNode.appendChild( div );
  doTime = window.setTimeout("getTime()", 1000);
}
if (window.addEventListener) window.addEventListener ('load', makeTime, false);
else if (window.attachEvent) window.attachEvent ('onload', makeTime);

[edit] Clock with Seconds counter

For the clock with the seconds counter, use this instead:

function getTime() {
  var time = new Date();
  var hours = time.getUTCHours();
  if (hours < 10) { hours = "0" + hours; }
  var minutes = time.getUTCMinutes();
  if (minutes < 10) { minutes = "0" + minutes; }
  var seconds = time.getUTCSeconds();
  if (seconds < 10) { seconds = "0" + seconds; }
  var currentTime = hours + ":" + minutes + ":" + seconds;
  document.getElementById('pt-time').childNodes[0].childNodes[0].replaceData(0, 8, currentTime);
  doTime = window.setTimeout("getTime()", 1000);
}
function makeTime() {
  var div = document.createElement( 'div' );
  div.id = 'pt-time';
  var mySpan = document.createElement( 'span' );
  mySpan.appendChild( document.createTextNode( '00:00:00 UTC' ) );
  div.appendChild( mySpan );
  document.getElementById( 'globalWrapper' ).parentNode.appendChild( div );
  doTime = window.setTimeout("getTime()", 1000);
}
if (window.addEventListener) window.addEventListener ('load', makeTime, false);
else if (window.attachEvent) window.attachEvent ('onload', makeTime);

[edit] CSS

Put this in your monobook.css page.

#pt-time span {
   color: #666;
   font-size: 11px;
   text-transform: lowercase;
   position: absolute;
   top: 1.9em;
   right: 2.2em;
}

[edit] On the personal menu

Example 2

Use this version of the script to place the time on your personal menu. By default, the clock will appear to the right of your "log out" link. You can customize it by changing the value of the gsTimeInsertBefore variable. For example, to place the clock to the left of your username, set gsTimeInsertBefore to 'pt-userpage'.

[edit] Javascript

Put this in your monobook.js file.

// Add time to the "personal menu" at the top of the page.
// Created by Wikipedia:User:Mathwiz2020, modified by User:JoeyDay
//
// Indicate where you would like the time to appear:
//   pt-userpage, pt-mytalk, pt-preferences,
//   pt-watchlist, pt-mycontris, pt-logout
//
gsTimeInsertBefore = ; // leave blank to append after "logout"
//
function getTime() {
  var time = new Date();
  var hours = time.getUTCHours();
  if (hours < 10) { hours = "0" + hours; }
  var minutes = time.getUTCMinutes();
  if (minutes < 10) { minutes = "0" + minutes; }
  var currentTime = hours + ":" + minutes
  document.getElementById('pt-time').childNodes[0].childNodes[0].replaceData(0, 5, currentTime);
  doTime = window.setTimeout("getTime()", 1000);
}
function makeTime() {
  var li = document.createElement('li');
  li.id = 'pt-time';
  var mySpan = document.createElement('span');
  mySpan.appendChild( document.createTextNode( '00:00 UTC' ) );
  li.appendChild(mySpan);
  if (gsTimeInsertBefore) {
    var before = document.getElementById(gsTimeInsertBefore);
    before.appendChild( li, before );
  }
  else {
    document.getElementById('pt-logout').parentNode.appendChild(li);
  }
  doTime = window.setTimeout("getTime()", 1000);
}
if (window.addEventListener) window.addEventListener ('load', makeTime, false);
else if (window.attachEvent) window.attachEvent ('onload', makeTime);

[edit] CSS

Put this in your monobook.css file.

#pt-time span {
   color: #666;
   font-size: 11px;
   text-transform: lowercase;
}
Personal tools