MediaWiki:Common.js: Unterschied zwischen den Versionen
Die Seite wurde neu angelegt: „→Das folgende JavaScript wird für alle Benutzer geladen.: // == Goreanische runde Uhr == mw.loader.using(['mediawiki.util'], function () { 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; const IHN_PER_DAY = IHN_PER_AHN * AHN_PER_DAY; const SEC_PER_IHN = 86400 / IHN_PER_DAY; function getGoreanTime() { const now = new Date(); const mid…“ |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
// == Goreanische runde Uhr == | // == Goreanische runde Uhr == | ||
mw.loader.using(['mediawiki.util'], function () { | mw.loader.using(['mediawiki.util'], function () { | ||
| Zeile 29: | Zeile 28: | ||
return { ahnIndex, ahn, ehn, ihn }; | 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 radiusNumbers = 100; // Abstand der Zahlen vom Mittelpunkt | |||
// 20 Ahn: Markierungen und Zahlen | |||
for (let i = 0; i < AHN_PER_DAY; i++) { | |||
const angle = (360 / AHN_PER_DAY) * i; // 0..342° in 18°-Schritten | |||
// Tick (Strich) | |||
const tick = document.createElement("div"); | |||
tick.className = "gor-tick"; | |||
tick.style.transform = `translate(-50%, -100%) rotate(${angle}deg)`; | |||
clock.appendChild(tick); | |||
// Zahl 1–20 | |||
const num = document.createElement("div"); | |||
num.className = "gor-number"; | |||
const ahnNumber = i + 1; | |||
const rad = (angle - 90) * Math.PI / 180; // -90°, damit 1 oben ist | |||
const x = centerX + radiusNumbers * Math.cos(rad); | |||
const y = centerY + radiusNumbers * Math.sin(rad); | |||
num.style.left = x + "px"; | |||
num.style.top = y + "px"; | |||
num.textContent = ahnNumber; | |||
clock.appendChild(num); | |||
} | |||
} | } | ||
| Zeile 40: | Zeile 77: | ||
const time = getGoreanTime(); | const time = getGoreanTime(); | ||
const angleAhn = ((time.ahnIndex + time.ehn/40 + time.ihn/3200) / 20) * 360; | // Winkel berechnen | ||
const angleEhn = ((time.ehn + time.ihn/80) / 40) * 360; | const angleAhn = ((time.ahnIndex + time.ehn / 40 + time.ihn / 3200) / 20) * 360; | ||
const angleEhn = ((time.ehn + time.ihn / 80) / 40) * 360; | |||
const angleIhn = (time.ihn / 80) * 360; | const angleIhn = (time.ihn / 80) * 360; | ||
| Zeile 48: | Zeile 86: | ||
handIhn.style.transform = `translate(-50%, -100%) rotate(${angleIhn}deg)`; | handIhn.style.transform = `translate(-50%, -100%) rotate(${angleIhn}deg)`; | ||
document.getElementById("digitalAhn | const dAhn = document.getElementById("digitalAhn"); | ||
document.getElementById("digitalEhn") | const dEhn = document.getElementById("digitalEhn"); | ||
document.getElementById(" | 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 (time.ahn === 10) info.textContent = "10. 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() { | function initGoreanClock() { | ||
const clock = document.getElementById("gorClock"); | |||
if (!clock) return; | |||
buildDial(); | |||
updateGoreanClock(); | updateGoreanClock(); | ||
setInterval(updateGoreanClock, 150); | setInterval(updateGoreanClock, 150); | ||
Version vom 25. November 2025, 08:59 Uhr
// == Goreanische runde Uhr ==
mw.loader.using(['mediawiki.util'], function () {
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;
const IHN_PER_DAY = IHN_PER_AHN * AHN_PER_DAY;
const SEC_PER_IHN = 86400 / IHN_PER_DAY;
function getGoreanTime() {
const now = new Date();
const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const elapsed = (now - midnight) / 1000;
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);
const rest1 = dayIhn % IHN_PER_AHN;
const ehn = Math.floor(rest1 / IHN_PER_EHN);
const ihn = rest1 % IHN_PER_EHN;
const ahn = ahnIndex + 1;
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 radiusNumbers = 100; // Abstand der Zahlen vom Mittelpunkt
// 20 Ahn: Markierungen und Zahlen
for (let i = 0; i < AHN_PER_DAY; i++) {
const angle = (360 / AHN_PER_DAY) * i; // 0..342° in 18°-Schritten
// Tick (Strich)
const tick = document.createElement("div");
tick.className = "gor-tick";
tick.style.transform = `translate(-50%, -100%) rotate(${angle}deg)`;
clock.appendChild(tick);
// Zahl 1–20
const num = document.createElement("div");
num.className = "gor-number";
const ahnNumber = i + 1;
const rad = (angle - 90) * Math.PI / 180; // -90°, damit 1 oben ist
const x = centerX + radiusNumbers * Math.cos(rad);
const y = centerY + radiusNumbers * Math.sin(rad);
num.style.left = x + "px";
num.style.top = y + "px";
num.textContent = ahnNumber;
clock.appendChild(num);
}
}
function updateGoreanClock() {
const handAhn = document.getElementById("handAhn");
const handEhn = document.getElementById("handEhn");
const handIhn = document.getElementById("handIhn");
if (!handAhn) return;
const time = getGoreanTime();
// Winkel berechnen
const angleAhn = ((time.ahnIndex + time.ehn / 40 + time.ihn / 3200) / 20) * 360;
const angleEhn = ((time.ehn + time.ihn / 80) / 40) * 360;
const angleIhn = (time.ihn / 80) * 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)`;
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);
}
mw.hook('wikipage.content').add(initGoreanClock);
});