Refactor snowflake symbol definitions: move symbol arrays to the top for better organization and remove redundant declarations
This commit is contained in:
@@ -7,6 +7,8 @@ const enableColoredSnowflakes = config.EnableColoredSnowflakes !== undefined ? c
|
|||||||
const enableDiffrentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different animation duration
|
const enableDiffrentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different animation duration
|
||||||
const snowflakeCount = config.SnowflakeCount || 25; // count of random extra snowflakes
|
const snowflakeCount = config.SnowflakeCount || 25; // count of random extra snowflakes
|
||||||
|
|
||||||
|
const snowflakeSymbols = ['❅', '❆']; // some snowflake symbols
|
||||||
|
const snowflakeSymbolsMobile = ['❅', '❆', '❄']; // some snowflake symbols mobile version
|
||||||
|
|
||||||
let msgPrinted = false; // flag to prevent multiple console messages
|
let msgPrinted = false; // flag to prevent multiple console messages
|
||||||
|
|
||||||
@@ -19,7 +21,7 @@ function toggleSnowflakes() {
|
|||||||
const trailerPlayer = document.querySelector('.youtubePlayerContainer');
|
const trailerPlayer = document.querySelector('.youtubePlayerContainer');
|
||||||
const isDashboard = document.body.classList.contains('dashboardDocument');
|
const isDashboard = document.body.classList.contains('dashboardDocument');
|
||||||
const hasUserMenu = document.querySelector('#app-user-menu');
|
const hasUserMenu = document.querySelector('#app-user-menu');
|
||||||
|
|
||||||
// hide snowflakes if video/trailer player is active or dashboard is visible
|
// hide snowflakes if video/trailer player is active or dashboard is visible
|
||||||
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
|
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
|
||||||
snowflakeContainer.style.display = 'none'; // hide snowflakes
|
snowflakeContainer.style.display = 'none'; // hide snowflakes
|
||||||
@@ -38,12 +40,10 @@ function toggleSnowflakes() {
|
|||||||
|
|
||||||
// observe changes in the DOM
|
// observe changes in the DOM
|
||||||
const observer = new MutationObserver(toggleSnowflakes);
|
const observer = new MutationObserver(toggleSnowflakes);
|
||||||
|
|
||||||
// start observation
|
|
||||||
observer.observe(document.body, {
|
observer.observe(document.body, {
|
||||||
childList: true, // observe adding/removing of child elements
|
childList: true,
|
||||||
subtree: true, // observe all levels of the DOM tree
|
subtree: true,
|
||||||
attributes: true // observe changes to attributes (e.g. class changes)
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
function addRandomSnowflakes(count) {
|
function addRandomSnowflakes(count) {
|
||||||
@@ -52,9 +52,6 @@ function addRandomSnowflakes(count) {
|
|||||||
|
|
||||||
console.log('Adding random snowflakes');
|
console.log('Adding random snowflakes');
|
||||||
|
|
||||||
const snowflakeSymbols = ['❅', '❆']; // some snowflake symbols
|
|
||||||
const snowflakeSymbolsMobile = ['❅', '❆', '❄']; // some snowflake symbols mobile version
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
// create a new snowflake element
|
// create a new snowflake element
|
||||||
const snowflake = document.createElement('div');
|
const snowflake = document.createElement('div');
|
||||||
@@ -70,7 +67,7 @@ function addRandomSnowflakes(count) {
|
|||||||
// set random horizontal position, animation delay and size(uncomment lines to enable)
|
// set random horizontal position, animation delay and size(uncomment lines to enable)
|
||||||
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
const randomLeft = Math.random() * 100; // position (0% to 100%)
|
||||||
const randomAnimationDelay = Math.random() * 8; // delay (0s to 8s)
|
const randomAnimationDelay = Math.random() * 8; // delay (0s to 8s)
|
||||||
const randomAnimationDelay2 = Math.random() * 5; // delay (0s to 5s)
|
const randomAnimationDelay2 = -(Math.random() * 5); // delay (-5s to 0s)
|
||||||
|
|
||||||
// apply styles
|
// apply styles
|
||||||
snowflake.style.left = `${randomLeft}%`;
|
snowflake.style.left = `${randomLeft}%`;
|
||||||
|
|||||||
Reference in New Issue
Block a user