User:Sean Fennel/monobook.js: Difference between revisions
Jump to navigation
Jump to search
Sean Fennel (talk | contribs) (test to see if this works anywhere besides Wikipedia) |
Sean Fennel (talk | contribs) No edit summary |
||
Line 11: | Line 11: | ||
{ | { | ||
var li = document.createElement( 'li' ); | 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 ) | if ( ! gsTimeInsertBefore ) // append to end (right) of list | ||
{ document.getElementById( 'pt-logout' ).parentNode.appendChild( li ); | |||
} | } | ||
else { | 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() | 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); | |||
} | } | ||
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);
}