const config = window.SeasonalsPluginConfig?.Easter || {};
const easter = config.EnableEaster !== undefined ? config.EnableEaster : true;
const enableBunny = config.EnableBunny !== undefined ? config.EnableBunny : true;
/* MARK: BUNNY LOCOMOTION CONFIGURATION */
const jumpDistanceVw = 5; // Distance in vw the bunny covers per jump
const jumpDurationMs = 770; // Time in ms the bunny spends moving during a jump
const pauseDurationMs = 116.6666; // Time in ms the bunny pauses between jumps
const minBunnyRestTime = config.MinBunnyRestTime || 2000;
const maxBunnyRestTime = config.MaxBunnyRestTime || 5000;
const eggCount = config.EggCount || 15;
const rabbit = "../Seasonals/Resources/easter_images/Osterhase.gif";
const easterEggImages = [
"../Seasonals/Resources/easter_images/egg_1.png",
"../Seasonals/Resources/easter_images/egg_2.png",
"../Seasonals/Resources/easter_images/egg_3.png",
"../Seasonals/Resources/easter_images/egg_4.png",
"../Seasonals/Resources/easter_images/egg_5.png",
"../Seasonals/Resources/easter_images/egg_6.png",
"../Seasonals/Resources/easter_images/egg_7.png",
"../Seasonals/Resources/easter_images/egg_8.png",
"../Seasonals/Resources/easter_images/egg_9.png",
"../Seasonals/Resources/easter_images/egg_10.png",
"../Seasonals/Resources/easter_images/egg_11.png",
"../Seasonals/Resources/easter_images/egg_12.png",
"../Seasonals/Resources/easter_images/eggs.png"
];
function createEasterGrassAndEggs(container) {
let grassContainer = container.querySelector('.easter-grass-container');
if (!grassContainer) {
grassContainer = document.createElement('div');
grassContainer.className = 'easter-grass-container';
container.appendChild(grassContainer);
}
grassContainer.innerHTML = '';
let pathsBg = '';
let pathsFg = '';
const w = window.innerWidth;
const hSVG = 80; // Grass 80px high
// Generate Grass
const bladeCount = w / 5;
for (let i = 0; i < bladeCount; i++) {
const height = Math.random() * 40 + 20;
const x = i * 5 + Math.random() * 3;
const hue = 80 + Math.random() * 40; // slightly more yellow-green for spring/easter
const color = `hsl(${hue}, 60%, 40%)`;
const line = ``;
if (Math.random() > 0.33) pathsBg += line; else pathsFg += line;
}
for (let i = 0; i < 200; i++) {
const x = Math.random() * w;
const h = 20 + Math.random() * 50;
const cY = hSVG - h;
const bend = x + (Math.random() * 40 - 20);
const color = Math.random() > 0.5 ? '#4caf50' : '#8bc34a';
const width = 1 + Math.random() * 2;
const path = ``;
if (Math.random() > 0.33) pathsBg += path; else pathsFg += path;
}
// Generate Flowers
const colors = ['#FF69B4', '#FFD700', '#87CEFA', '#FF4500', '#BA55D3', '#FFA500', '#FF1493'];
for (let i = 0; i < 40; i++) {
const x = 10 + Math.random() * (w - 20);
const y = hSVG * 0.1 + Math.random() * (hSVG * 0.5);
const col = colors[Math.floor(Math.random() * colors.length)];
let path = '';
path += ``;
const r = 2 + Math.random() * 1.5;
path += ``;
path += ``;
path += ``;
path += ``;
path += ``;
if (Math.random() > 0.33) pathsBg += path; else pathsFg += path;
}
grassContainer.innerHTML = `
`;
// Add Easter Eggs
for (let i = 0; i < eggCount; i++) {
const x = 2 + Math.random() * 96;
const y = Math.random() * 18; // 0 to 18px off bottom
const imageSrc = easterEggImages[Math.floor(Math.random() * easterEggImages.length)];
const eggImg = document.createElement('img');
eggImg.src = imageSrc;
eggImg.style.position = 'absolute';
eggImg.style.left = `${x}vw`;
eggImg.style.bottom = `${y}px`;
eggImg.style.width = `${15 + Math.random() * 10}px`;
eggImg.style.height = 'auto';
eggImg.style.transform = `rotate(${Math.random() * 60 - 30}deg)`;
eggImg.style.zIndex = Math.random() > 0.5 ? '1000' : '1004'; // Between grass layers
grassContainer.appendChild(eggImg);
}
}
let rabbitTimeout;
let isAnimating = false;
function addHoppingRabbit(container) {
if (!enableBunny) return;
const rabbitImg = document.createElement("img");
rabbitImg.id = "rabbit";
rabbitImg.src = rabbit;
rabbitImg.alt = "Hopping Easter Bunny";
rabbitImg.className = "hopping-rabbit";
rabbitImg.style.bottom = "-15px";
rabbitImg.style.position = "absolute";
container.appendChild(rabbitImg);
animateRabbit(rabbitImg);
}
function animateRabbit(rabbit) {
if (!rabbit || isAnimating) return;
isAnimating = true;
const startFromLeft = Math.random() >= 0.5;
const startX = startFromLeft ? -15 : 115;
let currentX = startX;
const endX = startFromLeft ? 115 : -15;
const direction = startFromLeft ? 1 : -1;
rabbit.style.transition = 'none';
const transformScale = startFromLeft ? 'scaleX(-1)' : '';
rabbit.style.transform = `translateX(${currentX}vw) ${transformScale}`;
const loopDurationMs = jumpDurationMs + pauseDurationMs;
let startTime = null;
function animationStep(timestamp) {
if (!document.querySelector('.easter-container') || rabbit.style.display === 'none') {
isAnimating = false;
// When hidden, we stop animating. The toggle function will re-init.
return;
}
if (!startTime) {
startTime = timestamp;
// FORCE GIF RESTART:
// The GIF must restart exactly when the jump loop starts.
// Re-assigning the src without a cache-busting timestamp resets it to frame 0
// while still allowing the browser to serve the cached file immediately.
const currSrc = rabbit.src.split('?')[0];
rabbit.src = '';
rabbit.src = currSrc;
}
const elapsed = timestamp - startTime;
// Calculate how many full loops (jump+pause) have happened
const completedLoops = Math.floor(elapsed / loopDurationMs);
const timeInCurrentLoop = elapsed % loopDurationMs;
// Determine if we are currently jumping or pausing
let currentLoopDistance = 0;
if (timeInCurrentLoop < jumpDurationMs) {
// We are in the jumping phase
currentLoopDistance = (timeInCurrentLoop / jumpDurationMs) * jumpDistanceVw;
} else {
// We are in the paused phase
currentLoopDistance = jumpDistanceVw;
}
currentX = startX + (completedLoops * jumpDistanceVw + currentLoopDistance) * direction;
// Update DOM without CSS transitions (since we control it per-frame)
rabbit.style.transform = `translateX(${currentX}vw) ${transformScale}`;
// Check if finished crossing
if ((direction === 1 && currentX >= endX) || (direction === -1 && currentX <= endX)) {
// Finished crossing! We can rest now.
// Since we explicitly reset the GIF to frame 0 at the start of every loop,
// we no longer have to snap the rest time to the loop duration mathematically.
let restTime = Math.random() * (maxBunnyRestTime - minBunnyRestTime) + minBunnyRestTime;
isAnimating = false;
rabbitTimeout = setTimeout(() => {
animateRabbit(document.querySelector('#rabbit'));
}, restTime);
return;
}
rabbitTimeout = requestAnimationFrame(animationStep);
}
// Start loop
rabbitTimeout = requestAnimationFrame(animationStep);
}
// Check visibility
function toggleEaster() {
const easterContainer = document.querySelector('.easter-container');
if (!easterContainer) 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');
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
easterContainer.style.display = 'none';
if (rabbitTimeout) {
clearTimeout(rabbitTimeout);
isAnimating = false; // Reset to allow restarting later
}
} else {
easterContainer.style.display = 'block';
if (!isAnimating && enableBunny) {
animateRabbit(document.querySelector('#rabbit'));
}
}
}
const observer = new MutationObserver(toggleEaster);
observer.observe(document.body, { childList: true, subtree: true, attributes: true });
function initializeEaster() {
if (!easter) return;
const container = document.querySelector('.easter-container') || document.createElement("div");
if (!document.querySelector('.easter-container')) {
container.className = "easter-container";
container.setAttribute("aria-hidden", "true");
document.body.appendChild(container);
}
createEasterGrassAndEggs(container);
addHoppingRabbit(container);
// Add resize listener to regenerate meadow
window.addEventListener('resize', () => {
if(document.querySelector('.easter-container')) {
createEasterGrassAndEggs(container);
}
});
toggleEaster();
}
initializeEaster();