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
This commit is contained in:
blankie 2023-08-14 19:43:21 +10:00
parent 8a3332b66e
commit 3496751789
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 89 additions and 8 deletions

View File

@ -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.9.0 // @version 1.10.0
// @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
@ -49,7 +49,54 @@ function getPanelItemHash(panelId, isDefault) {
return `#${encodeURIComponent(panelId)}`; 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("<div ", "<div data-qol-session={id} ");
}
function handleNewCalendarEvent(element, calendar) {
// Turn each calendar event into a link so that Link Hints can recognize it // Turn each calendar event into a link so that Link Hints can recognize it
let a = document.createElement("a"); let a = document.createElement("a");
for (let attr of element.attributes) { for (let attr of element.attributes) {
@ -62,10 +109,6 @@ function handleNewCalendarEvent(element) {
a.replaceChildren(...element.childNodes); a.replaceChildren(...element.childNodes);
let preventCompassHandler = false; let preventCompassHandler = false;
let calendar = unsafeWindow.Ext.getCmp(element.closest(".x-component").id);
if (calendar.view) {
calendar = calendar.view;
}
let calendarData = calendar.getEventRecordFromEl(element).data; let calendarData = calendar.getEventRecordFromEl(element).data;
if (a.classList.contains("activity-type-1")) { if (a.classList.contains("activity-type-1")) {
@ -108,11 +151,11 @@ 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";
} }
let panelItemHash = getPanelItemHash(panelId, isDefault);
// Automatically open tab specified in fragment // Automatically open tab specified in fragment
if (panelId === tabToOpen) { if (panelId === tabToOpen) {
@ -159,6 +202,29 @@ function handleLearningTasksTable(element) {
} }
} }
function handleSessionItem(element) {
// Make sessions in the sessions dropdown links
let style = getComputedStyle(element);
let a = document.createElement("a");
a.href = `#session/${element.dataset.qolSession}`;
a.style.display = "block";
a.style.textDecoration = "none";
a.style.padding = style.padding;
a.style.color = style.color;
a.append(...element.childNodes);
a.addEventListener("click", function(event) {
if (event.ctrlKey) {
event.stopImmediatePropagation();
} else {
event.preventDefault();
}
});
element.style.padding = 0;
element.append(a);
}
function handleCKEditor(instance) { function handleCKEditor(instance) {
instance.on("contentDom", function() { instance.on("contentDom", function() {
let editable = instance.editable(); let editable = instance.editable();
@ -186,9 +252,17 @@ function handleNewNode(node, observer) {
return; return;
} }
if (node.id === "CompassManagersActivityDefaultManager") {
handleActivityManager(node);
}
if (node.parentElement && (node.classList.contains("ext-cal-hd-ct") || node.classList.contains("ext-cal-bg-tbl") || node.classList.contains("ext-cal-inner-ct") || node.classList.contains("ext-cal-mdv"))) { if (node.parentElement && (node.classList.contains("ext-cal-hd-ct") || node.classList.contains("ext-cal-bg-tbl") || node.classList.contains("ext-cal-inner-ct") || node.classList.contains("ext-cal-mdv"))) {
let calendar = unsafeWindow.Ext.getCmp(node.closest(".x-component").id);
if (calendar.view) {
calendar = calendar.view;
}
for (let element of node.querySelectorAll("div.ext-cal-evt")) { for (let element of node.querySelectorAll("div.ext-cal-evt")) {
handleNewCalendarEvent(element); handleNewCalendarEvent(element, calendar);
} }
} else if (!qolTabOpened && node.classList.contains("x-panel")) { } else if (!qolTabOpened && node.classList.contains("x-panel")) {
qolTabOpened = true; qolTabOpened = true;
@ -210,6 +284,8 @@ function handleNewNode(node, observer) {
} }
} else if (node.localName === "table" && node.closest(".sel-learning-tasks-widget")) { } else if (node.localName === "table" && node.closest(".sel-learning-tasks-widget")) {
handleLearningTasksTable(node); handleLearningTasksTable(node);
} else if (node.classList.contains("x-boundlist-item") && node.dataset.qolSession) {
handleSessionItem(node);
} else if (node.classList.contains("cke")) { } else if (node.classList.contains("cke")) {
let instance = unsafeWindow.CKEDITOR.instances[node.id.substring(4)]; let instance = unsafeWindow.CKEDITOR.instances[node.id.substring(4)];
handleCKEditor(instance); handleCKEditor(instance);
@ -218,6 +294,8 @@ function handleNewNode(node, observer) {
} }
} }
let observer = new MutationObserver(function(mutations, observer) { let observer = new MutationObserver(function(mutations, observer) {
for (let mutation of mutations) { for (let mutation of mutations) {
if (mutation.type !== "childList") { if (mutation.type !== "childList") {
@ -228,6 +306,7 @@ let observer = new MutationObserver(function(mutations, observer) {
} }
} }
}); });
observer.observe(document.body, {childList: true, subtree: true}); observer.observe(document.body, {childList: true, subtree: true});
document.body.addEventListener("click", function(event) { document.body.addEventListener("click", function(event) {
if (event.target.classList.contains("x-mask")) { if (event.target.classList.contains("x-mask")) {

View File

@ -33,6 +33,8 @@ A userscript that adds small but useful features for Compass. Features include:
creating a new tab creating a new tab
- Ctrl-clicking an activity in a user's learning tasks tab no longer collapses - Ctrl-clicking an activity in a user's learning tasks tab no longer collapses
everything else everything else
- The previous/next buttons and sessions dropdown are now links (you can now
use [Link Hints] and ctrl-click to open them)
- The context menu that only says "Copy" is now suppressed - The context menu that only says "Copy" is now suppressed
- The option to remember logins is unchecked by default - The option to remember logins is unchecked by default