Update Compass QoL Enhancer to 1.2.1

- Add targetUserId/userId query parameters for activities/learning tasks
- Fix automatically opening the Schedule tab on user pages
- Fix the currently selected tab being Dashboard if Sessions is automatically
opened
This commit is contained in:
blankie 2023-07-26 16:05:23 +10:00
parent 93ce06a901
commit a00a99bcee
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 22 additions and 13 deletions

View File

@ -2,7 +2,7 @@
// @name Compass QoL Enhancer
// @namespace blankie-scripts
// @match http*://*.compass.education/*
// @version 1.2.0
// @version 1.2.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
@ -58,21 +58,20 @@ let observer = new MutationObserver(function(mutations) {
});
observer.observe(document.body, {childList: true, subtree: true});
// we make a copy of window.location.hash because the dashboard tab on a user's page would set the fragment to #dsh for some reason
let hashCopy = window.location.hash;
function handleNewNode(node) {
if (node.nodeType !== 1) {
return;
}
if (node.localName === "div" && node.classList.contains("ext-cal-evt")) {
handleNewCalendarEvent(node);
} else if (node.classList.contains("ext-cal-hd-ct")) {
// learning tasks need to be handled seperately for some reason
if (node.parentElement && (node.classList.contains("ext-cal-hd-ct") || node.classList.contains("ext-cal-bg-tbl") || node.classList.contains("ext-cal-inner-ct"))) {
for (let element of node.querySelectorAll("div.ext-cal-evt")) {
handleNewCalendarEvent(element);
}
} else if (!qolTabOpened && node.classList.contains("x-panel")) {
qolTabOpened = true;
let tabToOpen = window.location.hash.substring(1);
let tabToOpen = hashCopy.substring(1) || null;
if (window.location.pathname === "/Organise/Activities/Activity.aspx") {
tabToOpen = (new URLSearchParams(tabToOpen)).get("qol_open_tab");
}
@ -109,16 +108,17 @@ function handleNewCalendarEvent(element) {
a.replaceChildren(...element.childNodes);
let preventCompassHandler = false;
let calendarElement = element.closest(".x-component.ext-cal-ct, .x-component.ext-cal-body-ct");
let calendar = unsafeWindow.Ext.getCmp(calendarElement.id);
if (a.classList.contains("activity-type-1")) {
// Add a link for activities/"standard classes"
// missing targetUserId parameter, shouldn't matter too much if you're a student
let eventId = /\bcalendar-event-(\d+)\b/.exec(a.className)[1];
a.href = `/Organise/Activities/Activity.aspx#session/${eventId}`;
let data = calendar.getEventRecordFromEl(element).data;
a.href = `/Organise/Activities/Activity.aspx?targetUserId=${data.targetStudentId}#session/${data.instanceId}`;
preventCompassHandler = true;
} else if (a.classList.contains("activity-type-10")) {
// Add a link for learning tasks
// missing userId parameter, shouldn't matter too much if you're a student
a.href = "/Records/User.aspx#learningTasks";
let calendarPanel = calendar.ownerCalendarPanel;
a.href = calendarPanel.targetUserId !== undefined ? `/Records/User.aspx?userId=${calendarPanel.targetUserId}#learningTasks` : "/Records/User.aspx#learningTasks";
preventCompassHandler = true;
}
@ -135,6 +135,7 @@ function handleNewCalendarEvent(element) {
function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
let panelId = panelItem.itemId || panelItem.id;
let panelItemHash = getPanelItemHash(panelId, isDefault);
// i don't know why but dashboard is dsh
if (window.location.pathname === "/Records/User.aspx" && panelId === "dashboard") {
panelId = "dsh";
@ -142,11 +143,19 @@ function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
// Automatically open tab specified in fragment
if (panelId === tabToOpen) {
panel.setActiveTab(panelItem);
// 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() {
panel.setActiveTab(panelItem);
// reference the now active tab in the fragment if necessary (cough cough the reason why hashCopy exists)
if (panelItemHash !== window.location.hash) {
history.replaceState("", "", panelItemHash);
}
}, 1000);
}
panelItem.tab.preventDefault = false;
let panelItemHash = getPanelItemHash(panelId, isDefault);
panelItem.tab.el.dom.href = panelItemHash;
panelItem.tab.el.dom.addEventListener("click", function(event) {