From b251d9c2e52bc7c8f5af8181906c3958ad2b3af3 Mon Sep 17 00:00:00 2001 From: blankie Date: Fri, 1 Sep 2023 11:26:10 +1000 Subject: [PATCH] Update Compass QoL Enhancer to 1.13.1 - Tabs specified in the URL are now opened as fast as possible - Fix some panels not having their tabs linked to --- Compass QoL Enhancer.user.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Compass QoL Enhancer.user.js b/Compass QoL Enhancer.user.js index d17eb3d..a60db5c 100644 --- a/Compass QoL Enhancer.user.js +++ b/Compass QoL Enhancer.user.js @@ -2,7 +2,7 @@ // @name Compass QoL Enhancer // @namespace blankie-scripts // @match http*://*.compass.education/* -// @version 1.13.0 +// @version 1.13.1 // @author blankie // @description A userscript that adds small but useful features for Compass, such as the ability to close windows by clicking on the background // @inject-into page @@ -223,15 +223,19 @@ function handleNewCalendarEvent(element, calendar) { function handlePanelItem(panel, panelItem, isDefault, tabToOpen) { let panelId = panelItem.itemId || panelItem.id; let panelItemHash = getPanelItemHash(panelId, isDefault); - // Automatically open tab specified in fragment if (panelId === tabToOpen) { - // if the sessions tab is automatically opened, the currently selected tab is still dashboard for some reason - // i can't be arsed to read any more minified javascript, so this is the best fix that you'll get - // it does look like that this bug only manifests if the tab is activated while the initial loading thing is shown - setTimeout(function() { + // if the sessions tab is automatically opened, the currently selected tab is still dashboard for some reason, + // hence this hook to open it when the dashboard finishes loading + if (panel.setDashboardToLoading) { + let original = panel.setDashboardToLoading; + panel.setDashboardToLoading = function(loading) { + original.apply(this, arguments); + !loading && panel.setActiveTab(panelItem); + } + } else { panel.setActiveTab(panelItem); - }, 1000); + } } // /Communicate/SchoolDocumentation.aspx does not have tabs @@ -320,7 +324,11 @@ function handleNewNode(node, observer) { } } else if (!qolTabOpened && node.classList.contains("x-panel")) { qolTabOpened = true; - let panel = unsafeWindow.Ext.getCmp(node.id); + let topMostPanel = node; + while (topMostPanel.parentElement.closest(".x-panel")) { + topMostPanel = topMostPanel.parentElement.closest(".x-panel"); + } + let panel = unsafeWindow.Ext.getCmp(topMostPanel.id); let tabToOpen = window.location.pathname === "/Organise/Activities/Activity.aspx" ? getHashSearch().get("qol_open_tab") : (window.location.hash.replace(/^#(.+?)&.*$/, "$1") || null);