This commit is contained in:
MLH
2024-12-21 23:53:01 +01:00
parent ad6af82756
commit db532ccf44
4 changed files with 261 additions and 0 deletions

3
add_to_index_html.html Normal file
View File

@ -0,0 +1,3 @@
<script src="seasonals/christmas.js"></script>
<link rel="stylesheet" href="seasonals/christmas.css">
<div class="christmas-container"></div>

131
christmas.css Normal file
View File

@ -0,0 +1,131 @@
.christmas-container {
display: block;
pointer-events: none;
z-index: 0;
overflow: hidden;
}
.christmas {
position: fixed;
top: -10%;
font-size: 1em;
color: #fff;
font-family: Arial, sans-serif;
text-shadow: 0 0 5px #000;
user-select: none;
-webkit-animation-name: christmas-fall, christmas-shake;
-webkit-animation-duration: 10s, 3s;
-webkit-animation-timing-function: linear, ease-in-out;
-webkit-animation-iteration-count: infinite, infinite;
cursor: default;
animation-name: christmas-fall, christmas-shake;
animation-duration: 10s, 3s;
animation-timing-function: linear, ease-in-out;
animation-iteration-count: infinite, infinite;
}
@-webkit-keyframes christmas-fall {
0% {
top: -10%;
}
100% {
top: 100%;
}
}
@-webkit-keyframes christmas-shake {
0%,
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
50% {
-webkit-transform: translateX(80px);
transform: translateX(80px);
}
}
@keyframes christmas-fall {
0% {
top: -10%;
}
100% {
top: 100%;
}
}
@keyframes christmas-shake {
0%,
100% {
transform: translateX(0);
}
50% {
transform: translateX(80px);
}
}
.christmas:nth-of-type(0) {
left: 0%;
animation-delay: 0s, 0s;
}
.christmas:nth-of-type(1) {
left: 10%;
animation-delay: 1s, 1s;
}
.christmas:nth-of-type(2) {
left: 20%;
animation-delay: 6s, 0.5s;
}
.christmas:nth-of-type(3) {
left: 30%;
animation-delay: 4s, 2s;
}
.christmas:nth-of-type(4) {
left: 40%;
animation-delay: 2s, 2s;
}
.christmas:nth-of-type(5) {
left: 50%;
animation-delay: 8s, 3s;
}
.christmas:nth-of-type(6) {
left: 60%;
animation-delay: 6s, 2s;
}
.christmas:nth-of-type(7) {
left: 70%;
animation-delay: 2.5s, 1s;
}
.christmas:nth-of-type(8) {
left: 80%;
animation-delay: 1s, 0s;
}
.christmas:nth-of-type(9) {
left: 90%;
animation-delay: 3s, 1.5s;
}
.christmas:nth-of-type(10) {
left: 25%;
animation-delay: 2s, 0s;
}
.christmas:nth-of-type(11) {
left: 65%;
animation-delay: 4s, 2.5s;
}

107
christmas.js Normal file
View File

@ -0,0 +1,107 @@
const christmas = true; // enable/disable christmas
const randomChristmas = true; // enable random Christmas
const randomChristmasMobile = false; // enable random Christmas on mobile devices
const christmasCount = 25; // count of random extra christmas
let msgPrinted = false; // flag to prevent multiple console messages
// function to check and control the christmas
function toggleChristmas() {
const christmasContainer = document.querySelector('.christmas-container');
if (!christmasContainer) 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 christmas if video/trailer player is active or dashboard is visible
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
christmasContainer.style.display = 'none'; // hide christmas
if (!msgPrinted) {
console.log('Christmas hidden');
msgPrinted = true;
}
} else {
christmasContainer.style.display = 'block'; // show christmas
if (msgPrinted) {
console.log('Christmas visible');
msgPrinted = false;
}
}
}
// observe changes in the DOM
const observer = new MutationObserver(toggleChristmas);
// 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)
});
// Array of christmas characters
const christmasSymbols = ['❆','🎁', '❄️', '🎁', '🎅' , '🎊','🎁', '🎉'];
function addRandomChristmas(count) {
const christmasContainer = document.querySelector('.christmas-container'); // get the christmas container
if (!christmasContainer) return; // exit if christmas container is not found
console.log('Adding random christmas');
for (let i = 0; i < count; i++) {
// create a new christmas element
const christmasDiv = document.createElement('div');
christmasDiv.classList.add('christmas');
// pick a random christmas symbol
christmasDiv.textContent = christmasSymbols[Math.floor(Math.random() * christmasSymbols.length)];
// 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() * 8; // delay (0s to 8s)
const randomAnimationDelay2 = Math.random() * 5; // delay (0s to 5s)
// apply styles
christmasDiv.style.left = `${randomLeft}%`;
christmasDiv.style.animationDelay = `${randomAnimationDelay}s, ${randomAnimationDelay2}s`;
// add the christmas to the container
christmasContainer.appendChild(christmasDiv);
}
console.log('Random christmas added');
}
// initialize standard christmas
function initChristmas() {
const christmasContainer = document.querySelector('.christmas-container') || document.createElement("div");
if (!document.querySelector('.christmas-container')) {
christmasContainer.className = "christmas-container";
christmasContainer.setAttribute("aria-hidden", "true");
document.body.appendChild(christmasContainer);
}
// create the 12 standard christmas
for (let i = 0; i < 12; i++) {
const christmasDiv = document.createElement('div');
christmasDiv.className = 'christmas';
christmasDiv.textContent = christmasSymbols[Math.floor(Math.random() * christmasSymbols.length)];
christmasContainer.appendChild(christmasDiv);
}
}
// initialize christmas and add random christmas symbols after the DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
if (!christmas) return; // exit if christmas is disabled
initChristmas();
toggleChristmas();
const screenWidth = window.innerWidth; // get the screen width to detect mobile devices
if (randomChristmas && (screenWidth > 768 || randomChristmasMobile)) { // add random christmas only on larger screens, unless enabled for mobile devices
addRandomChristmas(christmasCount);
}
});

20
test-site.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Christmas Display</title>
<style>
body {
background-color: black;
}
</style>
</head>
<body>
<script src="christmas.js"></script>
<link rel="stylesheet" href="christmas.css">
<div class="christmas-container"></div>
</body>
</html>