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:
parent
8a3332b66e
commit
3496751789
|
@ -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("<div ", "<div data-qol-session={id} ");
|
||||
}
|
||||
|
||||
function handleNewCalendarEvent(element, calendar) {
|
||||
// Turn each calendar event into a link so that Link Hints can recognize it
|
||||
let a = document.createElement("a");
|
||||
for (let attr of element.attributes) {
|
||||
|
@ -62,10 +109,6 @@ function handleNewCalendarEvent(element) {
|
|||
a.replaceChildren(...element.childNodes);
|
||||
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;
|
||||
|
||||
if (a.classList.contains("activity-type-1")) {
|
||||
|
@ -108,11 +151,11 @@ 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";
|
||||
}
|
||||
let panelItemHash = getPanelItemHash(panelId, isDefault);
|
||||
|
||||
// Automatically open tab specified in fragment
|
||||
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) {
|
||||
instance.on("contentDom", function() {
|
||||
let editable = instance.editable();
|
||||
|
@ -186,9 +252,17 @@ function handleNewNode(node, observer) {
|
|||
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"))) {
|
||||
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")) {
|
||||
handleNewCalendarEvent(element);
|
||||
handleNewCalendarEvent(element, calendar);
|
||||
}
|
||||
} else if (!qolTabOpened && node.classList.contains("x-panel")) {
|
||||
qolTabOpened = true;
|
||||
|
@ -210,6 +284,8 @@ function handleNewNode(node, observer) {
|
|||
}
|
||||
} else if (node.localName === "table" && node.closest(".sel-learning-tasks-widget")) {
|
||||
handleLearningTasksTable(node);
|
||||
} else if (node.classList.contains("x-boundlist-item") && node.dataset.qolSession) {
|
||||
handleSessionItem(node);
|
||||
} else if (node.classList.contains("cke")) {
|
||||
let instance = unsafeWindow.CKEDITOR.instances[node.id.substring(4)];
|
||||
handleCKEditor(instance);
|
||||
|
@ -218,6 +294,8 @@ function handleNewNode(node, observer) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let observer = new MutationObserver(function(mutations, observer) {
|
||||
for (let mutation of mutations) {
|
||||
if (mutation.type !== "childList") {
|
||||
|
@ -228,6 +306,7 @@ let observer = new MutationObserver(function(mutations, observer) {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {childList: true, subtree: true});
|
||||
document.body.addEventListener("click", function(event) {
|
||||
if (event.target.classList.contains("x-mask")) {
|
||||
|
|
|
@ -33,6 +33,8 @@ A userscript that adds small but useful features for Compass. Features include:
|
|||
creating a new tab
|
||||
- Ctrl-clicking an activity in a user's learning tasks tab no longer collapses
|
||||
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 option to remember logins is unchecked by default
|
||||
|
||||
|
|
Loading…
Reference in New Issue