From 34967517891c48f9cfcaf7da686401ab2468a029 Mon Sep 17 00:00:00 2001 From: blankie Date: Mon, 14 Aug 2023 19:43:21 +1000 Subject: [PATCH] Update Compass QoL Enhancer to 1.10.0 - The previous/next session buttons and dropdown are now links - (attempt to) Optimise grabbing calendar info - Fix the Dashboard tab on /Records/User.aspx being #dashboard instead of #dsh --- Compass QoL Enhancer.user.js | 95 +++++++++++++++++++++++++++++++++--- README.md | 2 + 2 files changed, 89 insertions(+), 8 deletions(-) diff --git a/Compass QoL Enhancer.user.js b/Compass QoL Enhancer.user.js index 0e2d750..ca3cbc4 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.9.0 +// @version 1.10.0 // @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 @@ -49,7 +49,54 @@ function getPanelItemHash(panelId, isDefault) { return `#${encodeURIComponent(panelId)}`; } -function handleNewCalendarEvent(element) { +function updateInstanceButton(instanceDetails, instanceButton, offset) { + // Make previous/next session buttons links + let index = instanceDetails.instanceStore.indexOfId(instanceDetails.m_instanceId); + index += offset; + if (index >= 0 && index < instanceDetails.instanceStore.count()) { + let url = `#session/${instanceDetails.instanceStore.getAt(index).internalId}`; + instanceButton.el.dom.href = url; + } else { + instanceButton.el.dom.removeAttribute("href"); + } +} + +function handleInstanceButtonClick(event) { + if (event.ctrlKey) { + event.stopImmediatePropagation(); + } +} + +function handleActivityManager(element) { + let instanceDetails = unsafeWindow.Ext.getCmp(element.id).m_InstanceDetailsWidget; + let instanceNavigatorToolbar = instanceDetails.getInstanceNavigatorToolbar(); + let previousInstanceButton = instanceNavigatorToolbar.getComponent("previousInstanceButton"); + let nextInstanceButton = instanceNavigatorToolbar.getComponent("nextInstanceButton"); + let comboSelectInstance = instanceDetails.getCmbSelectIntance(); // not a typo :) + + let realUpdateInstanceHeader = instanceDetails.updateInstanceHeader; + instanceDetails.updateInstanceHeader = function() { + realUpdateInstanceHeader.apply(this, arguments); + updateInstanceButton(instanceDetails, previousInstanceButton, -1); + updateInstanceButton(instanceDetails, nextInstanceButton, 1); + }; + + for (let button of [previousInstanceButton, nextInstanceButton]) { + button.el.dom.addEventListener("click", handleInstanceButtonClick, {passive: true}); + // move all previous handlers back to the front + // new relic's browser agent would've borked this, but it did not?? + // i'll take what i can get i guess + // (note to self: unsafeWindow.NREUM = true if this breaks) + for (let handler of unsafeWindow.Ext.EventManager.getEventListenerCache(button, "click")) { + button.el.dom.removeEventListener("click", handler.wrap); + button.el.dom.addEventListener("click", handler.wrap); + } + } + + comboSelectInstance.tpl.html = comboSelectInstance.tpl.html.replace("