Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
// == Goreanische runde Uhr ==
// === Goreanische runde Uhr für MediaWiki ===
mw.loader.using(['mediawiki.util'], function () {
mw.loader.using(['mediawiki.util'], function () {


    // Goreanische Konstanten
     const IHN_PER_EHN = 80;
     const IHN_PER_EHN = 80;
     const EHN_PER_AHN = 40;
     const EHN_PER_AHN = 40;
     const AHN_PER_DAY = 20;
     const AHN_PER_DAY = 20;


     const IHN_PER_AHN = IHN_PER_EHN * EHN_PER_AHN;
     const IHN_PER_AHN = IHN_PER_EHN * EHN_PER_AHN;   // 80 * 40 = 3200
     const IHN_PER_DAY = IHN_PER_AHN * AHN_PER_DAY;
     const IHN_PER_DAY = IHN_PER_AHN * AHN_PER_DAY;   // 3200 * 20 = 64000


     const SEC_PER_IHN = 86400 / IHN_PER_DAY;
    // Erdtag (24h) → goreanischer Tag (64000 Ihn)
     const SEC_PER_IHN = 86400 / IHN_PER_DAY;         // ≈ 1,35 s pro Ihn


     function getGoreanTime() {
     function getGoreanTime() {
         const now = new Date();
         const now = new Date();
         const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
         const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
         const elapsed = (now - midnight) / 1000;
         const elapsed = (now - midnight) / 1000; // Sekunden seit Mitternacht


         const totalIhn = elapsed / SEC_PER_IHN;
         const totalIhn = elapsed / SEC_PER_IHN;
         const dayIhn = ((totalIhn % IHN_PER_DAY) + IHN_PER_DAY) % IHN_PER_DAY;
         const dayIhn = ((totalIhn % IHN_PER_DAY) + IHN_PER_DAY) % IHN_PER_DAY;


         const ahnIndex = Math.floor(dayIhn / IHN_PER_AHN);
         const ahnIndex = Math.floor(dayIhn / IHN_PER_AHN); // 0–19
         const rest1 = dayIhn % IHN_PER_AHN;
         const rest1 = dayIhn % IHN_PER_AHN;


         const ehn = Math.floor(rest1 / IHN_PER_EHN);
         const ehn = Math.floor(rest1 / IHN_PER_EHN);       // 0–39
         const ihn = rest1 % IHN_PER_EHN;
         const ihn = rest1 % IHN_PER_EHN;                   // 0–79 (inkl. Nachkomma)


         const ahn = ahnIndex + 1;
         const ahn = ahnIndex + 1; // Anzeige 1–20


         return { ahnIndex, ahn, ehn, ihn };
         return { ahnIndex, ahn, ehn, ihn };
Zeile 34: Zeile 36:
         if (!clock) return;
         if (!clock) return;


         // doppelte Erzeugung verhindern, falls Hook mehrfach feuert
         // Doppelte Erzeugung verhindern, falls Hook mehrfach feuert
         if (clock.dataset.gorDialBuilt === "1") return;
         if (clock.dataset.gorDialBuilt === "1") return;
         clock.dataset.gorDialBuilt = "1";
         clock.dataset.gorDialBuilt = "1";
Zeile 40: Zeile 42:
         const centerX = clock.clientWidth / 2;
         const centerX = clock.clientWidth / 2;
         const centerY = clock.clientHeight / 2;
         const centerY = clock.clientHeight / 2;
        const radiusNumbers = 100; // Abstand der Zahlen vom Mittelpunkt


         // 20 Ahn: Markierungen und Zahlen
         const radiusOuter = 100;  // äußere Zahlen (1–10)
        for (let i = 0; i < AHN_PER_DAY; i++) {
        const radiusInner = 78;   // innere Zahlen (11–20)
            const angle = (360 / AHN_PER_DAY) * i; // 0..342° in 18°-Schritten


             // Tick (Strich)
        // 10-Stunden-Ziffernblatt: 1–10 außen, 11–20 innen
        for (let i = 0; i < 10; i++) {
            const angle = (360 / 10) * i; // 0..324° in 36°-Schritten
 
             // Tick (Strich am Rand)
             const tick = document.createElement("div");
             const tick = document.createElement("div");
             tick.className = "gor-tick";
             tick.className = "gor-tick";
Zeile 52: Zeile 56:
             clock.appendChild(tick);
             clock.appendChild(tick);


             // Zahl 1–20
             // Äußere Zahl: 1–10
             const num = document.createElement("div");
             const numOuter = document.createElement("div");
             num.className = "gor-number";
             numOuter.className = "gor-number";
             const ahnNumber = i + 1;
             const ahnOuter = i + 1; // 1..10
             const rad = (angle - 90) * Math.PI / 180; // -90°, damit 1 oben ist
             const radOuter = (angle - 90) * Math.PI / 180; // -90°, damit 1 oben ist
 
            numOuter.style.left = (centerX + radiusOuter * Math.cos(radOuter)) + "px";
            numOuter.style.top  = (centerY + radiusOuter * Math.sin(radOuter)) + "px";
            numOuter.textContent = ahnOuter;
            clock.appendChild(numOuter);


             const x = centerX + radiusNumbers * Math.cos(rad);
            // Innere Zahl: 11–20
             const y = centerY + radiusNumbers * Math.sin(rad);
             const numInner = document.createElement("div");
            numInner.className = "gor-number gor-number-inner";
             const ahnInner = i + 11; // 11..20
            const radInner = (angle - 90) * Math.PI / 180;


             num.style.left = x + "px";
             numInner.style.left = (centerX + radiusInner * Math.cos(radInner)) + "px";
             num.style.top = y + "px";
             numInner.style.top = (centerY + radiusInner * Math.sin(radInner)) + "px";
             num.textContent = ahnNumber;
             numInner.textContent = ahnInner;
             clock.appendChild(num);
             clock.appendChild(numInner);
         }
         }
     }
     }
Zeile 73: Zeile 85:
         const handIhn = document.getElementById("handIhn");
         const handIhn = document.getElementById("handIhn");


         if (!handAhn) return;
         if (!handAhn || !handEhn || !handIhn) return;


         const time = getGoreanTime();
         const time = getGoreanTime();


         // Winkel berechnen
         // Ahn-Zeiger: 10er-Ziffernblatt, 2 Umdrehungen pro Tag
         const angleAhn = ((time.ahnIndex + time.ehn / 40 + time.ihn / 3200) / 20) * 360;
        // (1–10 & 11–20 teilen sich die gleiche Skala)
         const angleEhn = ((time.ehn + time.ihn / 80) / 40) * 360;
        const ahnCycle = (time.ahn - 1) % 10; // 0..9
         const angleIhn = (time.ihn / 80) * 360;
         const angleAhn = ((ahnCycle + time.ehn / EHN_PER_AHN + time.ihn / (EHN_PER_AHN * IHN_PER_EHN)) / 10) * 360;
 
        // Ehn-Zeiger: 40 Ehn pro Umdrehung
         const angleEhn = ((time.ehn + time.ihn / IHN_PER_EHN) / EHN_PER_AHN) * 360;
 
        // Ihn-Zeiger: 80 Ihn pro Umdrehung
         const angleIhn = (time.ihn / IHN_PER_EHN) * 360;


         handAhn.style.transform = `translate(-50%, -100%) rotate(${angleAhn}deg)`;
         handAhn.style.transform = `translate(-50%, -100%) rotate(${angleAhn}deg)`;
Zeile 86: Zeile 104:
         handIhn.style.transform = `translate(-50%, -100%) rotate(${angleIhn}deg)`;
         handIhn.style.transform = `translate(-50%, -100%) rotate(${angleIhn}deg)`;


        // Digitale Anzeige
         const dAhn = document.getElementById("digitalAhn");
         const dAhn = document.getElementById("digitalAhn");
         const dEhn = document.getElementById("digitalEhn");
         const dEhn = document.getElementById("digitalEhn");
Zeile 98: Zeile 117:


         if (info) {
         if (info) {
             if (time.ahn === 10) info.textContent = "10. Ahn – goreanischer Mittag";
             if (time.ahn === 10) {
             else if (time.ahn === 20) info.textContent = "20. Ahn – goreanische Mitternacht";
                info.textContent = "10. Ahn – goreanischer Mittag";
             else info.textContent = time.ahn + ". Ahn des goreanischen Tages";
             } else if (time.ahn === 20) {
                info.textContent = "20. Ahn – goreanische Mitternacht";
             } else {
                info.textContent = time.ahn + ". Ahn des goreanischen Tages";
            }
         }
         }
     }
     }
Zeile 113: Zeile 136:
     }
     }


    // Initialisierung, wenn Seiteninhalt geladen ist
     mw.hook('wikipage.content').add(initGoreanClock);
     mw.hook('wikipage.content').add(initGoreanClock);
});
});

Version vom 25. November 2025, 09:25 Uhr

// === Goreanische runde Uhr für MediaWiki ===
mw.loader.using(['mediawiki.util'], function () {

    // Goreanische Konstanten
    const IHN_PER_EHN = 80;
    const EHN_PER_AHN = 40;
    const AHN_PER_DAY = 20;

    const IHN_PER_AHN = IHN_PER_EHN * EHN_PER_AHN;   // 80 * 40 = 3200
    const IHN_PER_DAY = IHN_PER_AHN * AHN_PER_DAY;   // 3200 * 20 = 64000

    // Erdtag (24h) → goreanischer Tag (64000 Ihn)
    const SEC_PER_IHN = 86400 / IHN_PER_DAY;         // ≈ 1,35 s pro Ihn

    function getGoreanTime() {
        const now = new Date();
        const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        const elapsed = (now - midnight) / 1000; // Sekunden seit Mitternacht

        const totalIhn = elapsed / SEC_PER_IHN;
        const dayIhn = ((totalIhn % IHN_PER_DAY) + IHN_PER_DAY) % IHN_PER_DAY;

        const ahnIndex = Math.floor(dayIhn / IHN_PER_AHN); // 0–19
        const rest1 = dayIhn % IHN_PER_AHN;

        const ehn = Math.floor(rest1 / IHN_PER_EHN);       // 0–39
        const ihn = rest1 % IHN_PER_EHN;                   // 0–79 (inkl. Nachkomma)

        const ahn = ahnIndex + 1; // Anzeige 1–20

        return { ahnIndex, ahn, ehn, ihn };
    }

    function buildDial() {
        const clock = document.getElementById("gorClock");
        if (!clock) return;

        // Doppelte Erzeugung verhindern, falls Hook mehrfach feuert
        if (clock.dataset.gorDialBuilt === "1") return;
        clock.dataset.gorDialBuilt = "1";

        const centerX = clock.clientWidth / 2;
        const centerY = clock.clientHeight / 2;

        const radiusOuter = 100;  // äußere Zahlen (1–10)
        const radiusInner = 78;   // innere Zahlen (11–20)

        // 10-Stunden-Ziffernblatt: 1–10 außen, 11–20 innen
        for (let i = 0; i < 10; i++) {
            const angle = (360 / 10) * i; // 0..324° in 36°-Schritten

            // Tick (Strich am Rand)
            const tick = document.createElement("div");
            tick.className = "gor-tick";
            tick.style.transform = `translate(-50%, -100%) rotate(${angle}deg)`;
            clock.appendChild(tick);

            // Äußere Zahl: 1–10
            const numOuter = document.createElement("div");
            numOuter.className = "gor-number";
            const ahnOuter = i + 1; // 1..10
            const radOuter = (angle - 90) * Math.PI / 180; // -90°, damit 1 oben ist

            numOuter.style.left = (centerX + radiusOuter * Math.cos(radOuter)) + "px";
            numOuter.style.top  = (centerY + radiusOuter * Math.sin(radOuter)) + "px";
            numOuter.textContent = ahnOuter;
            clock.appendChild(numOuter);

            // Innere Zahl: 11–20
            const numInner = document.createElement("div");
            numInner.className = "gor-number gor-number-inner";
            const ahnInner = i + 11; // 11..20
            const radInner = (angle - 90) * Math.PI / 180;

            numInner.style.left = (centerX + radiusInner * Math.cos(radInner)) + "px";
            numInner.style.top  = (centerY + radiusInner * Math.sin(radInner)) + "px";
            numInner.textContent = ahnInner;
            clock.appendChild(numInner);
        }
    }

    function updateGoreanClock() {
        const handAhn = document.getElementById("handAhn");
        const handEhn = document.getElementById("handEhn");
        const handIhn = document.getElementById("handIhn");

        if (!handAhn || !handEhn || !handIhn) return;

        const time = getGoreanTime();

        // Ahn-Zeiger: 10er-Ziffernblatt, 2 Umdrehungen pro Tag
        // (1–10 & 11–20 teilen sich die gleiche Skala)
        const ahnCycle = (time.ahn - 1) % 10; // 0..9
        const angleAhn = ((ahnCycle + time.ehn / EHN_PER_AHN + time.ihn / (EHN_PER_AHN * IHN_PER_EHN)) / 10) * 360;

        // Ehn-Zeiger: 40 Ehn pro Umdrehung
        const angleEhn = ((time.ehn + time.ihn / IHN_PER_EHN) / EHN_PER_AHN) * 360;

        // Ihn-Zeiger: 80 Ihn pro Umdrehung
        const angleIhn = (time.ihn / IHN_PER_EHN) * 360;

        handAhn.style.transform = `translate(-50%, -100%) rotate(${angleAhn}deg)`;
        handEhn.style.transform = `translate(-50%, -100%) rotate(${angleEhn}deg)`;
        handIhn.style.transform = `translate(-50%, -100%) rotate(${angleIhn}deg)`;

        // Digitale Anzeige
        const dAhn = document.getElementById("digitalAhn");
        const dEhn = document.getElementById("digitalEhn");
        const dIhn = document.getElementById("digitalIhn");
        const info = document.getElementById("ahnInfo");

        const pad2 = n => String(Math.floor(n)).padStart(2, "0");

        if (dAhn) dAhn.textContent = "Ahn " + pad2(time.ahn);
        if (dEhn) dEhn.textContent = "Ehn " + pad2(time.ehn);
        if (dIhn) dIhn.textContent = "Ihn " + pad2(time.ihn);

        if (info) {
            if (time.ahn === 10) {
                info.textContent = "10. Ahn – goreanischer Mittag";
            } else if (time.ahn === 20) {
                info.textContent = "20. Ahn – goreanische Mitternacht";
            } else {
                info.textContent = time.ahn + ". Ahn des goreanischen Tages";
            }
        }
    }

    function initGoreanClock() {
        const clock = document.getElementById("gorClock");
        if (!clock) return;

        buildDial();
        updateGoreanClock();
        setInterval(updateGoreanClock, 150);
    }

    // Initialisierung, wenn Seiteninhalt geladen ist
    mw.hook('wikipage.content').add(initGoreanClock);
});