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