====== Snippets: JavaScript ======
[[:snippets:start|← Zurück zu :snippets:start]]
===== Countdown =====
> **TODO:** Snippet überarbeiten! Vor allem so klein wie möglich machen, es get hier schließlich primär um den JavaScript-Code!
Silvester-Countdown
Silvester-Countdown
/**
* main.js:
* Main JavaScript code for the countdown
* Initializes the Countdown library from countdown.js
*
*/
/**
* Hide
if URL query parameter is "?hideHeader=yes"
*/
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('hideHeader');
if (myParam == null || myParam.toLowerCase() == "yes" || myParam.toLowerCase() == "true") {
const h1 = document.querySelector("h1");
h1.innerHTML = "";
h1.style.display = "none";
} else if (myParam.toLowerCase() == "no" || myParam.toLowerCase() == "false") {
const h1 = document.querySelector("h1");
// Nothing to do
}
/**
* Deadlines and messages shown after countdown
*/
// Weihnachten:
//const deadline = (new Date()).getFullYear()+'-12-24T00:00+0100';
//const message = "Frohe Weihnachten! \n🎅"
// Neujahr:
const deadline = '2026-01-01T00:00+0100';
const message = "🎉 \n" + "Frohes neues Jahr!";
/**
* Initialize countdown
*/
Countdown.init(
"countdown", // ID of countdown container
deadline, // Deadline as ISO 8601 timestamp
message, // Message to display after countdown finished
1 // Style (0=long, 1=short)
);