Remove unnecessary comments and streamline DOM observation in seasonal scripts

This commit is contained in:
CodeDevMLH
2026-02-27 21:57:24 +01:00
parent f3ea84cc80
commit 0b7b506b8d
7 changed files with 20 additions and 35 deletions

View File

@@ -14,7 +14,7 @@ const images = [
"../Seasonals/Resources/halloween_images/pumpkin_20x20.png",
];
let msgPrinted = false; // flag to prevent multiple console messages
let msgPrinted = false;
// function to check and control the halloween
function toggleHalloween() {
@@ -42,7 +42,6 @@ function toggleHalloween() {
}
}
// observe changes in the DOM
const observer = new MutationObserver(toggleHalloween);
observer.observe(document.body, {
childList: true,
@@ -52,26 +51,22 @@ observer.observe(document.body, {
function addRandomSymbols(count) {
const halloweenContainer = document.querySelector('.halloween-container'); // get the halloween container
if (!halloweenContainer) return; // exit if halloween container is not found
const halloweenContainer = document.querySelector('.halloween-container');
if (!halloweenContainer) return;
console.log('Adding random halloween symbols');
for (let i = 0; i < count; i++) {
// create a new halloween elements
const halloweenDiv = document.createElement("div");
halloweenDiv.className = "halloween";
// pick a random halloween symbol
const imageSrc = images[Math.floor(Math.random() * images.length)];
const img = document.createElement("img");
img.src = imageSrc;
halloweenDiv.appendChild(img);
// set random horizontal position, animation delay and size(uncomment lines to enable)
const randomLeft = Math.random() * 100; // position (0% to 100%)
const randomAnimationDelay = Math.random() * 10; // delay (0s to 10s)
const randomAnimationDelay2 = -(Math.random() * 3); // delay (-3s to 0s)
@@ -87,13 +82,11 @@ function addRandomSymbols(count) {
halloweenDiv.style.animationDuration = `${randomAnimationDuration}s, ${randomAnimationDuration2}s`;
}
// add the halloween to the container
halloweenContainer.appendChild(halloweenDiv);
}
console.log('Random halloween symbols added');
}
// create halloween objects
function createHalloween() {
const container = document.querySelector('.halloween-container') || document.createElement("div");
@@ -235,9 +228,8 @@ function createMouse(container) {
container.appendChild(mouse);
}
// initialize halloween
function initializeHalloween() {
if (!halloween) return; // exit if halloween is disabled
if (!halloween) return;
createHalloween();
toggleHalloween();
@@ -262,7 +254,7 @@ function initializeHalloween() {
}
const screenWidth = window.innerWidth; // get the screen width to detect mobile devices
if (randomSymbols && (screenWidth > 768 || randomSymbolsMobile)) { // add random halloweens only on larger screens, unless enabled for mobile devices
if (randomSymbols && (screenWidth > 768 || randomSymbolsMobile)) {
addRandomSymbols(halloweenCount);
}
}