Update Compass QoL Enhancer to 1.24.2

- Fix popups being occluded by the prioritised nav bar
- Fix `qol_learning_task` being stripped on /Organise/Activities/Activity.aspx
This commit is contained in:
blankie 2023-11-29 18:24:27 +11:00
parent ed2fbde27a
commit ed564db7fa
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 18 additions and 6 deletions

View File

@ -2,7 +2,7 @@
// @name Compass QoL Enhancer
// @namespace blankie-scripts
// @match http*://*.compass.education/*
// @version 1.24.1
// @version 1.24.2
// @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
@ -15,7 +15,8 @@ let qolTabOpened = false;
let qolLearningTaskOpened = false;
let modifyUrlHash = true;
let shownWindows = 0;
let productNavBar = document.querySelector("#productNavBar");
// popups should bot be blocked by the prioritised nav bar
let productNavBar = window.location.pathname !== "/ActionCentre/" ? document.querySelector("#productNavBar") : null;
// needed because .toString() adds a trailing = for empty values
URLSearchParams.prototype.laxToString = function() {
@ -189,7 +190,7 @@ function handleLearningTaskShow() {
let search = getHashSearch();
search.set("qol_learning_task", this.learningTask.data.id);
history.pushState("", "", `#${search.laxToString()}`);
window.location.hash = `#${search.laxToString()}`;
}
function handleLearningTaskClose() {
if (!modifyUrlHash) {
@ -198,7 +199,7 @@ function handleLearningTaskClose() {
let search = getHashSearch();
search.delete("qol_learning_task");
history.pushState("", "", `#${search.laxToString()}`);
window.location.hash = `#${search.laxToString()}`;
}
let LearningTasksSubmissionWidget = getExtClass("Compass.widgets.LearningTasksSubmissionWidget");
if (LearningTasksSubmissionWidget) {
@ -223,6 +224,17 @@ function updateInstanceButton(instanceDetails, instanceButton, offset) {
}
let InstanceDetailsWidget = getExtClass("Compass.widgets.InstanceDetailsWidget");
if (InstanceDetailsWidget) {
// recreation of updateURLHash to fix qol_learning_task being stripped
// example: /Organise/Activities/Activity.aspx#activity/67672&openLearningTaskTab&qol_learning_task=77334
InstanceDetailsWidget.prototype.updateURLHash = function(useInstanceId) {
let match = window.location.hash.match(/^#.*?[?&](.+)$/);
let hash = useInstanceId ? `session/${this.m_instanceId}` : `activity/${this.m_activityId}`;
if (match) {
hash += `&${match[1]}`;
}
window.location.hash = `#${hash}`;
};
let originalUpdateInstanceHeader = InstanceDetailsWidget.prototype.updateInstanceHeader;
InstanceDetailsWidget.prototype.updateInstanceHeader = function() {
originalUpdateInstanceHeader.apply(this, arguments);
@ -463,9 +475,9 @@ function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
}
// prevent the browser from scrolling to the body
event.preventDefault();
if (modifyUrlHash && window.location.hash !== panelItemHash && (window.location.pathname === "/Organise/Activities/Activity.aspx" || !window.location.hash.startsWith(`${panelItemHash}&`))) {
if (modifyUrlHash && (window.location.pathname === "/Organise/Activities/Activity.aspx" || !window.location.hash.startsWith(`${panelItemHash}&`))) {
// Automatically add a reference to the tab when it is clicked
history.pushState("", "", panelItemHash);
window.location.hash = panelItemHash;
}
});
}