Files
Jellyfin-Seasonals-Plugin/Jellyfin.Plugin.Seasonals/Web/olympia.js

136 lines
4.6 KiB
JavaScript

const config = window.SeasonalsPluginConfig?.Olympia || {};
const olympia = config.EnableOlympia !== undefined ? config.EnableOlympia : true;
const symbolCount = config.SymbolCount || 25;
const useRandomSymbols = config.EnableRandomSymbols !== undefined ? config.EnableRandomSymbols : true;
const enableRandomMobile = config.EnableRandomSymbolsMobile !== undefined ? config.EnableRandomSymbolsMobile : false;
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true;
let msgPrinted = false;
function toggleOlympia() {
const container = document.querySelector('.olympia-container');
if (!container) 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) {
container.style.display = 'none';
if (!msgPrinted) {
console.log('Olympia hidden');
msgPrinted = true;
}
} else {
container.style.display = 'block';
if (msgPrinted) {
console.log('Olympia visible');
msgPrinted = false;
}
}
}
const observer = new MutationObserver(toggleOlympia);
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true
});
function createOlympia() {
const container = document.querySelector('.olympia-container') || document.createElement('div');
if (!document.querySelector('.olympia-container')) {
container.className = 'olympia-container';
container.setAttribute("aria-hidden", "true");
document.body.appendChild(container);
}
const standardCount = 15;
const totalSymbols = symbolCount + standardCount;
let isMobile = window.matchMedia("only screen and (max-width: 768px)").matches;
let finalCount = totalSymbols;
if (isMobile) {
finalCount = enableRandomMobile ? totalSymbols : standardCount;
}
const useRandomDuration = enableDifferentDuration !== false;
const activeItems = ['gold', 'silver', 'bronze', 'torch'];
for (let i = 0; i < finalCount; i++) {
let symbol = document.createElement('div');
const randomItem = activeItems[Math.floor(Math.random() * activeItems.length)];
symbol.className = `olympia-symbol olympia-${randomItem}`;
let img = document.createElement('img');
img.src = `../Seasonals/Resources/olympia_images/${randomItem}.png`;
img.onerror = function() {
this.style.display = 'none';
this.parentElement.innerHTML = getOlympiaEmojiFallback(randomItem);
};
symbol.appendChild(img);
const leftPos = Math.random() * 100;
const delaySeconds = Math.random() * 10;
let durationSeconds = 8;
if (useRandomDuration) {
durationSeconds = Math.random() * 5 + 6; // 6 to 11 seconds
}
const startRot = Math.random() * 360;
symbol.style.setProperty('--start-rot', `${startRot}deg`);
symbol.style.setProperty('--end-rot', `${startRot + (Math.random() > 0.5 ? 360 : -360)}deg`);
symbol.style.left = `${leftPos}vw`;
symbol.style.animationDuration = `${durationSeconds}s`;
symbol.style.animationDelay = `${delaySeconds}s`;
container.appendChild(symbol);
}
// Olympic Ring Colors
const confettiColors = ['#0081C8', '#FCB131', '#000000', '#00A651', '#EE334E'];
const confettiCount = isMobile ? 30 : 60;
for (let i = 0; i < confettiCount; i++) {
let confetti = document.createElement('div');
confetti.className = 'olympia-confetti';
const color = confettiColors[Math.floor(Math.random() * confettiColors.length)];
confetti.style.backgroundColor = color;
const leftPos = Math.random() * 100;
const delaySeconds = Math.random() * 8;
const duration = Math.random() * 3 + 5;
confetti.style.left = `${leftPos}vw`;
confetti.style.animationDuration = `${duration}s`;
confetti.style.animationDelay = `${delaySeconds}s`;
container.appendChild(confetti);
}
}
function getOlympiaEmojiFallback(type) {
if (type === 'gold') return '🥇';
if (type === 'silver') return '🥈';
if (type === 'bronze') return '🥉';
if (type === 'torch') return '🔥';
return '';
}
function initializeOlympia() {
if (!olympia) return;
createOlympia();
toggleOlympia();
}
initializeOlympia();