From 2fa3b446828651e2b5eba33a567f63003c731e4c Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Mon, 24 Nov 2025 15:53:55 -0500 Subject: [PATCH] Dom,-safe --- Scriptmonkey_Beta.ps1 | 53 ++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/Scriptmonkey_Beta.ps1 b/Scriptmonkey_Beta.ps1 index 480f180..28585bf 100644 --- a/Scriptmonkey_Beta.ps1 +++ b/Scriptmonkey_Beta.ps1 @@ -999,26 +999,42 @@ function flashTitle(finalTitle) { }, 800); } - - // ======================================================================= -// Tab Navigation +// Tab Navigation (DOM-safe) // ======================================================================= -const tabButtons = document.querySelectorAll(".tab-button"); -const tabContents = document.querySelectorAll(".tab-content"); -tabButtons.forEach(btn => { +document.addEventListener('DOMContentLoaded', () => { + const tabButtons = document.querySelectorAll(".tab-button"); + const tabContents = document.querySelectorAll(".tab-content"); + + if (!tabButtons || !tabButtons.length || !tabContents || !tabContents.length) { + console.error("ScriptMonkey: no tab buttons or tab contents found."); + return; + } + + tabButtons.forEach(btn => { btn.addEventListener("click", () => { - // clear active state - tabButtons.forEach(b => b.classList.remove("active")); - tabContents.forEach(c => c.classList.remove("active")); - // set new active - btn.classList.add("active"); - document.getElementById(btn.dataset.tab).classList.add("active"); + // clear active state + tabButtons.forEach(b => b.classList.remove("active")); + tabContents.forEach(c => c.classList.remove("active")); + + // set new active + btn.classList.add("active"); + const targetId = btn.dataset.tab; + const target = document.getElementById(targetId); + if (target) target.classList.add("active"); }); + }); + + // initialize default tab on load + const defaultBtn = document.querySelector(".tab-button[data-tab='{{defaultPage}}Tab']"); + const defaultTab = document.getElementById("{{defaultPage}}Tab"); + + if (defaultBtn) defaultBtn.classList.add("active"); + if (defaultTab) defaultTab.classList.add("active"); }); -// initialize default tab on load -document.querySelector(".tab-button[data-tab='{{defaultPage}}Tab']").classList.add("active"); -document.getElementById("{{defaultPage}}Tab").classList.add("active"); + + + // ======================================================================= // Task Trigger @@ -1092,12 +1108,17 @@ function updateOffboardSelectAll() { master.checked = Array.from(children).every(cb => cb.checked); } -// Attach off-board checkbox change handlers +// Attach off-board checkbox change handlers (DOM-safe) document.addEventListener('DOMContentLoaded', () => { const offChildren = document.querySelectorAll( '#offboardTab input[type=checkbox]:not(#offboardSelectAll)' ); + if (!offChildren || !offChildren.length) { + // This just means no off-boarding items were rendered; safe to ignore. + return; + } + offChildren.forEach(cb => cb.addEventListener('change', updateOffboardSelectAll) );