Refactor hearts.js: reorganize heartSymbols array and clean up observer initialization
This commit is contained in:
@@ -6,6 +6,9 @@ const randomSymbolsMobile = config.EnableRandomSymbolsMobile !== undefined ? con
|
|||||||
const enableDiffrentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different animation duration for random symbols
|
const enableDiffrentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different animation duration for random symbols
|
||||||
const heartsCount = config.SymbolCount || 25; // count of random extra symbols
|
const heartsCount = config.SymbolCount || 25; // count of random extra symbols
|
||||||
|
|
||||||
|
// Array of hearts characters
|
||||||
|
const heartSymbols = ['❤️', '💕', '💞', '💓', '💗', '💖'];
|
||||||
|
|
||||||
let msgPrinted = false; // flag to prevent multiple console messages
|
let msgPrinted = false; // flag to prevent multiple console messages
|
||||||
|
|
||||||
// function to check and control the hearts
|
// function to check and control the hearts
|
||||||
@@ -36,19 +39,13 @@ function toggleHearts() {
|
|||||||
|
|
||||||
// observe changes in the DOM
|
// observe changes in the DOM
|
||||||
const observer = new MutationObserver(toggleHearts);
|
const observer = new MutationObserver(toggleHearts);
|
||||||
|
|
||||||
// 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
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Array of hearts characters
|
|
||||||
const heartSymbols = ['❤️', '💕', '💞', '💓', '💗', '💖'];
|
|
||||||
|
|
||||||
|
|
||||||
function addRandomSymbols(count) {
|
function addRandomSymbols(count) {
|
||||||
const heartsContainer = document.querySelector('.hearts-container'); // get the hearts container
|
const heartsContainer = document.querySelector('.hearts-container'); // get the hearts container
|
||||||
if (!heartsContainer) return; // exit if hearts container is not found
|
if (!heartsContainer) return; // exit if hearts container is not found
|
||||||
|
|||||||
Reference in New Issue
Block a user