From e2c60136cf129297a3530f92bed47edc3383fb2d Mon Sep 17 00:00:00 2001 From: HighImKevin Date: Tue, 16 Sep 2025 05:24:15 -0400 Subject: [PATCH] Add Dashboard button fix and update Injector --- dashboardButtonFix.js | 34 ++++++++++++++++++++++++++++++++++ injector.js | 36 ++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 dashboardButtonFix.js diff --git a/dashboardButtonFix.js b/dashboardButtonFix.js new file mode 100644 index 0000000..3133ccf --- /dev/null +++ b/dashboardButtonFix.js @@ -0,0 +1,34 @@ +// Dashboard Button Fix +// This is a workaround for a bug in the dashboard back button +// The dashboard back button currently leaves the Jellyfin app if the user navigates to the dashboard directly from the URL +// This script sends you to home.html in these scenarios instead of leaving the app + +(function () { + function attachHandler() { + const btn = document.querySelector('button.MuiButtonBase-root'); + if (!btn) return; + + if (btn._backCheckAttached) return; + btn._backCheckAttached = true; + + btn.addEventListener('click', function (e) { + if (window.history.state?.idx === 0) { + // Stop normal handlers + e.stopImmediatePropagation(); + e.preventDefault(); + + console.log("[DashboardButtonFix]: No history to go back. Redirecting to home page."); + + // Changes this to the page you'd like to return to by default + Dashboard.navigate('/home.html'); + } + }, true); + } + + // Observe DOM in case button is recreated + const obs = new MutationObserver(attachHandler); + obs.observe(document.body, { childList: true, subtree: true }); + + // Initial run + attachHandler(); +})(); diff --git a/injector.js b/injector.js index d39c5ec..5f79371 100644 --- a/injector.js +++ b/injector.js @@ -9,19 +9,23 @@ // Set to true to enable, false to disable const ENABLED_SCRIPTS = { // Core functionality (required for other scripts) - cardBuilder: true, // Required by watchlist and homeScreen + cardBuilder: true, // Required by watchlist, homeScreen and search - // UI Enhancements + // UI and functional enhancements watchlist: true, // Watchlist functionality homeScreen: true, // Custom home screen sections search: true, // Enhanced search functionality + headerTabs: true, // Header tab enhancements customMenu: true, // Custom menu functionality exclusiveElsewhere: true, // Exclusive elsewhere branding - updoot: true, // Upvote functionality + + // Scripts with additional backend requirements + updoot: false, // Upvote functionality from https://github.com/BobHasNoSoul/jellyfin-updoot // Utility scripts backdropLeakFix: true, // Memory leak fixes + dashboardButtonFix: true, // Dashboard button fix }; // Script definitions with dependencies and metadata @@ -31,8 +35,7 @@ script: 'cardBuilder.js', css: null, dependencies: [], - description: 'Core card building functionality (required by other scripts)', - required: true + description: 'Core card building functionality (required by other scripts)' }, { name: 'watchlist', @@ -88,7 +91,14 @@ script: 'updoot.js', css: null, dependencies: [], - description: 'Upvote functionality' + description: 'Upvote functionality provided by https://github.com/BobHasNoSoul/jellyfin-updoot' + }, + { + name: 'dashboardButtonFix', + script: 'dashboardButtonFix.js', + css: null, + dependencies: [], + description: 'Fixes the dashboard button to redirect to the home page when the back button is clicked and there is no history to go back to' } ]; @@ -96,14 +106,7 @@ function validateConfiguration() { const errors = []; - // Check if required scripts are enabled - SCRIPT_DEFINITIONS.forEach(script => { - if (script.required && !ENABLED_SCRIPTS[script.name]) { - errors.push(`Required script '${script.name}' is disabled`); - } - }); - - // Check dependencies + // Check dependencies - only validate if the script is enabled SCRIPT_DEFINITIONS.forEach(script => { if (ENABLED_SCRIPTS[script.name]) { script.dependencies.forEach(dep => { @@ -124,7 +127,6 @@ // Get the root path for scripts (adjust this based on your setup) function getScriptRoot() { - // Fallback: assume scripts are in the same directory return 'https://cdn.jsdelivr.net/gh/ranaldsgift/KefinTweaks/'; } @@ -190,11 +192,13 @@ // Load a script and its dependencies async function loadScriptWithDependencies(scriptDef) { try { - // Load dependencies first + // Load dependencies first - only if they are enabled for (const depName of scriptDef.dependencies) { const depScript = SCRIPT_DEFINITIONS.find(s => s.name === depName); if (depScript && ENABLED_SCRIPTS[depName]) { await loadScriptWithDependencies(depScript); + } else if (depScript && !ENABLED_SCRIPTS[depName]) { + console.warn(`[KefinTweaks Injector] Dependency '${depName}' is disabled, skipping for '${scriptDef.name}'`); } }