From d0634e4487a6f89e68a15376c82461aa52bfc383 Mon Sep 17 00:00:00 2001 From: CodeDevMLH <145071728+CodeDevMLH@users.noreply.github.com> Date: Fri, 27 Feb 2026 23:18:07 +0100 Subject: [PATCH] Refactor sports.js to streamline configuration handling, remove unused variables, and enhance code readability --- Jellyfin.Plugin.Seasonals/Web/sports.js | 43 +++++++++++-------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Jellyfin.Plugin.Seasonals/Web/sports.js b/Jellyfin.Plugin.Seasonals/Web/sports.js index 45ea29a..cc1910f 100644 --- a/Jellyfin.Plugin.Seasonals/Web/sports.js +++ b/Jellyfin.Plugin.Seasonals/Web/sports.js @@ -2,28 +2,30 @@ const config = window.SeasonalsPluginConfig?.Sports || {}; const sports = config.EnableSports !== undefined ? config.EnableSports : true; const symbolCount = config.SymbolCount || 5; -const useRandomSymbols = config.EnableRandomSymbols !== undefined ? config.EnableRandomSymbols : true; -const enableRandomMobile = config.EnableRandomSymbolsMobile !== undefined ? config.EnableRandomSymbolsMobile : false; const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; const enableTrophy = config.EnableTrophy !== undefined ? config.EnableTrophy : false; +const rawSportsBalls = config.SportsBalls || 'football,basketball,tennis,volleyball'; +const turfColorHex = config.TurfColor || '#228b22'; +const confettiColors = config.ConfettiColors ? config.ConfettiColors.split(',') : ['#000000', '#FF0000', '#FFCC00']; // Add Country Colored confetti + // Pre-declare and manage image assets +// Credits: https://flaticon.com const SPORTS_ASSETS = { - badminton: ['badminton_1', 'badminton_2'], - baseball: ['baseball_1', 'baseball_2'], - basketball: ['basketball_1', 'basketball_2'], - billiard: Array.from({length: 14}, (_, i) => `billiard_ball_${i + 1}`), - bowling: ['bowling_1', 'bowling_2'], - football: Array.from({length: 5}, (_, i) => `football_${i + 1}`), - golf: ['golf_ball_1', 'golf_ball_2'], - rugby: ['rugby_ball_1', 'rugby_ball_2'], - table_tennis: ['table_tennis_ball_1', 'table_tennis_ball_2'], - tennis: ['tennis_ball_1', 'tennis_ball_2'], - volleyball: ['volleyball_1', 'volleyball_2'], - waterball: ['waterball_1', 'waterball_2'] + badminton: ['badminton_1', 'badminton_2'], + baseball: ['baseball_1', 'baseball_2'], + basketball: ['basketball_1', 'basketball_2'], + billiard: Array.from({length: 14}, (_, i) => `billiard_ball_${i + 1}`), + bowling: ['bowling_1', 'bowling_2'], + football: Array.from({length: 5}, (_, i) => `football_${i + 1}`), + golf: ['golf_ball_1', 'golf_ball_2'], + rugby: ['rugby_ball_1', 'rugby_ball_2'], + table_tennis: ['table_tennis_ball_1', 'table_tennis_ball_2'], + tennis: ['tennis_ball_1', 'tennis_ball_2'], + volleyball: ['volleyball_1', 'volleyball_2'], + waterball: ['waterball_1', 'waterball_2'] }; -const turfColorHex = config.TurfColor || '#228b22'; let msgPrinted = false; @@ -67,11 +69,10 @@ function createSports() { document.body.appendChild(container); } - // Parse turf color config // Create a turf/grass overlay at the bottom using the provided hex const turf = document.createElement('div'); turf.className = 'sports-turf'; - // Using hex with transparency (e.g., 4D = 30%, CC = 80%) + // Using hex with transparency turf.style.background = `linear-gradient(180deg, transparent 0%, ${turfColorHex}4D 30%, ${turfColorHex}CC 100%)`; container.appendChild(turf); @@ -85,7 +86,6 @@ function createSports() { const useRandomDuration = enableDifferentDuration !== false; // Map standard sports balls to spawn based on category configuration - const rawSportsBalls = config.SportsBalls || 'football,basketball,tennis,volleyball'; const chosenCategories = rawSportsBalls.split(',').map(s => s.trim()).filter(s => s !== ''); const createBall = (randomItem) => { @@ -140,7 +140,7 @@ function createSports() { // Create falling sports balls chosenCategories.forEach(category => { let variants = SPORTS_ASSETS[category]; - if (!variants) variants = [category]; // Legacy fallback + if (!variants) variants = [category]; for (let i = 0; i < ballsPerCategory; i++) { // Pick a random variant @@ -162,7 +162,6 @@ function createSports() { let trophyImg = document.createElement('img'); trophyImg.src = `../Seasonals/Resources/sport_assets/trophy.gif`; - // Randomly scale trophy slightly larger trophyImg.style.transform = `scale(${Math.random() * 0.5 + 0.8})`; trophyImg.onerror = function() { this.style.display = 'none'; @@ -211,8 +210,6 @@ function createSports() { setTimeout(() => { if (document.body.contains(container)) launchTrophy(); }, Math.random() * 5000 + 2000); } - // Add Germany Colored confetti (Black, Red, Gold) - const confettiColors = ['#000000', '#FF0000', '#FFCC00']; const confettiCount = isMobile ? 30 : 60; for (let i = 0; i < confettiCount; i++) { @@ -257,8 +254,6 @@ function createSports() { } } -/* Removed legacy fallback logic */ - function initializeSports() { if (!sports) return; createSports();