Vorlage:Uhr

Aus Shadowhelix
Zur Navigation springen Zur Suche springen

Its 16:47:31
Do You Know Where Your Meat Body Is?

Die volle Funktionsfähigkeit erreicht die Vorlage:Uhr durch Einfügen des folgenden Javascripts auf der monobook.js-Seite (Link: http://wiki.shadowhelix.de/Benutzer:Name_des_Benutzers/monobook.js):

/* Uhr */

function updateClock () {

    var Clock = document.getElementsByTagName( "div" );

    for ( var i = 0; i < Clock.length; i++ ) {

        // div mit class="clock" raussuchen
        if ( hasClass( Clock[i], "clock" ) ) {

            // div wird geleert
            while(Clock[i].hasChildNodes()){
                Clock[i].removeChild(Clock[i].lastChild);
            }

            var currentTime = new Date ();

            var currentHours = currentTime.getHours();
            var currentMinutes = currentTime.getMinutes();
            var currentSeconds = currentTime.getSeconds();

            // ergänzung einer null, wenn sec, min, std nur eine ziffer haben
            if (  currentHours < 10) {  currentHours = "0"+currentHours}
            if (currentMinutes < 10) {currentMinutes = "0"+currentMinutes}
            if (currentSeconds < 10) {currentSeconds = "0"+currentSeconds}

            // text + aktuelle uhrzeit
            var ClockText2 = document.createTextNode( "Do You Know Where Your "
                                                     +"Meat Body Is?" );
            var ClockText1 = document.createTextNode( "Its "+currentHours+":"
                                                            +currentMinutes+":"
                                                            +currentSeconds );
            var Brk = document.createElement( "br" );

            // einfügen in div
            Clock[i].insertBefore( ClockText2, Clock[i].childNodes[0] );
            Clock[i].insertBefore( Brk, Clock[i].childNodes[0] );
            Clock[i].insertBefore( ClockText1, Clock[i].childNodes[0] );

            // reset der lineHeight notwendig
            Clock[i].style.lineHeight = "1.5em";

            // nächster aufruf von updateClock() nach 1000ms
            setTimeout('updateClock();',1000);
        }
    }
}

addOnloadHook( updateClock );