initial commit

This commit is contained in:
MLH
2024-11-26 02:33:36 +01:00
parent ef33f47966
commit af3ec8c7b4
3 changed files with 136 additions and 0 deletions

89
fireworks.js Normal file
View File

@@ -0,0 +1,89 @@
const fireworks = true; // enable/disable fireworks
const particlesPerFirework = 30; // count of particles per firework
let msgPrinted = false; // flag to prevent multiple console messages
// function to check and control fireworks
function toggleSnowflakes() {
const fireworksContainer = document.querySelector('.fireworks');
if (!fireworksContainer) return;
const videoPlayer = document.querySelector('.videoPlayerContainer');
const trailerPlayer = document.querySelector('.youtubePlayerContainer');
const isDashboard = document.body.classList.contains('dashboardDocument');
const hasUserMenu = document.querySelector('#app-user-menu');
// hide fireworks if video/trailer player is active or dashboard is visible
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
fireworksContainer.style.display = 'none'; // hide fireworks
if (!msgPrinted) {
console.log('Fireworks hidden');
msgPrinted = true;
}
} else {
fireworksContainer.style.display = 'block'; // show fireworks
if (msgPrinted) {
console.log('Fireworks visible');
msgPrinted = false;
}
}
}
// observe changes in the DOM
const observer = new MutationObserver(toggleSnowflakes);
// start observation
observer.observe(document.body, {
childList: true, // observe adding/removing of child elements
subtree: true, // observe all levels of the DOM tree
attributes: true // observe changes to attributes (e.g. class changes)
});
// function to add random fireworks
function launchFirework() {
const fireworkContainer = document.querySelector('.fireworks');
if (!fireworkContainer) return;
// random position on the screen
const x = Math.random() * window.innerWidth;
const y = Math.random() * window.innerHeight;
// create particles for the firework
for (let i = 0; i < particlesPerFirework; i++) {
const particle = document.createElement('div');
particle.classList.add('firework');
// random angle and distance
const angle = Math.random() * 2 * Math.PI; // 0 to 360 degrees
const distance = Math.random() * 100 + 50; // 50 to 150 pixels
const xOffset = Math.cos(angle) * distance;
const yOffset = Math.sin(angle) * distance;
// set particle properties
particle.style.left = `${x}px`;
particle.style.top = `${y}px`;
particle.style.setProperty('--x', `${xOffset}px`);
particle.style.setProperty('--y', `${yOffset}px`);
// add particle to the container
fireworkContainer.appendChild(particle);
// remove particle after animation ends
particle.addEventListener('animationend', () => {
particle.remove();
});
}
}
// automaticly start fireworks
function startFireworks() {
setInterval(() => {
launchFirework();
}, 1000); // firework every second
}
// initialize snowflakes and add random snowflakes after the DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
if (!fireworks) return; // exit if fireworks are disabled
startFireworks();
});