User:Sean Fennel/monobook.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// 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);
}
addOnloadHook( 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);
}
//