User:Sean Fennel/monobook.js: Difference between revisions

From WikiIndex
Jump to navigation Jump to search
(test to see if this works anywhere besides Wikipedia)
 
No edit summary
Line 11: Line 11:
{
{
   var li = document.createElement( 'li' );
   var li = document.createElement( 'li' );
  li.id = 'pt-time';
    li.id = 'pt-time';


  var mySpan = document.createElement( 'span' );
    var mySpan = document.createElement( 'span' );
  mySpan.appendChild( document.createTextNode( '00:00:00' ) );
      mySpan.appendChild( document.createTextNode( '00:00:00' ) );


  li.appendChild( mySpan );
    li.appendChild( mySpan );


   if ( ! gsTimeInsertBefore ) { // append to end (right) of list
   if ( ! gsTimeInsertBefore ) // append to end (right) of list
    document.getElementById( 'pt-logout' ).parentNode.appendChild( li );
  {  document.getElementById( 'pt-logout' ).parentNode.appendChild( li );
   }
   }
   else {  
   else
    var before = document.getElementById( gsTimeInsertBefore );
  { var before = document.getElementById( gsTimeInsertBefore );
    before.appendChild( li, before );
      before.appendChild( li, before );
   }
   }
  doTime = window.setTimeout("getTime()", 1000);
doTime = window.setTimeout("getTime()", 1000);
}
}
 
  if ( window.addEventListener ) window.addEventListener( 'load', makeTime, false );
addOnloadHook( makeTime );
else if ( window.attachEvent      ) window.attachEvent  ( 'onload', makeTime );


function getTime()
function getTime()
{
{
  var time = new Date();
    var time = new Date();
  var hours = time.getUTCHours();
    var hours = time.getUTCHours();
  if (hours < 10) { hours = "0" + hours; }
    if (hours < 10) { hours = "0" + hours; }
  var minutes = time.getUTCMinutes();
    var minutes = time.getUTCMinutes();
  if (minutes < 10) { minutes = "0" + minutes; }
    if (minutes < 10) { minutes = "0" + minutes; }
  var seconds = time.getUTCSeconds();
    var seconds = time.getUTCSeconds();
  if (seconds < 10) { seconds = "0" + seconds; }
    if (seconds < 10) { seconds = "0" + seconds; }
  var currentTime = hours + ":" + minutes + ":" + seconds;
    var currentTime = hours + ":" + minutes + ":" + seconds;
  document.getElementById('pt-time').childNodes[0].childNodes[0].replaceData(0, 8, currentTime);
    document.getElementById('pt-time').childNodes[0].childNodes[0].replaceData(0, 8, currentTime);
  doTime = window.setTimeout("getTime()", 1000);
doTime = window.setTimeout("getTime()", 1000);
}
}
//

Revision as of 20:48, 18 April 2006

  //  Add time to your monobook "personal menu" list at the very top of the page.
  //  Created by [[User:Mathwiz2020]]
  //
  //  Indicate where you would like the time to appear:
  //    pt-userpage, pt-mytalk, pt-preferences,
  //    pt-watchlist, pt-mycontris, pt-logout
  //
gsTimeInsertBefore = 'pt-userpage'; // leave blank to append after "logout"
  //
function makeTime()
{
  var li = document.createElement( 'li' );
    li.id = 'pt-time';

    var mySpan = document.createElement( 'span' );
      mySpan.appendChild( document.createTextNode( '00:00:00' ) );

    li.appendChild( mySpan );

  if ( ! gsTimeInsertBefore ) // append to end (right) of list
  {  document.getElementById( 'pt-logout' ).parentNode.appendChild( li );
  }
  else
  {  var before = document.getElementById( gsTimeInsertBefore );
      before.appendChild( li, before );
  }
doTime = window.setTimeout("getTime()", 1000);
}
   if ( window.addEventListener ) window.addEventListener( 'load', makeTime, false );
else if ( window.attachEvent      ) window.attachEvent   ( 'onload', makeTime );

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);
}