Update Compass QoL Enhancer to 1.21.0
- Re-open panel tabs and learning tasks when the URL changes
This commit is contained in:
parent
40268aade6
commit
324d06fc74
|
@ -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.20.0
|
// @version 1.21.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
|
||||||
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
let qolTabOpened = false;
|
let qolTabOpened = false;
|
||||||
let qolLearningTaskOpened = false;
|
let qolLearningTaskOpened = false;
|
||||||
|
let modifyUrlHash = true;
|
||||||
let shownWindows = 0;
|
let shownWindows = 0;
|
||||||
|
|
||||||
// needed because .toString() adds a trailing = for empty values
|
// needed because .toString() adds a trailing = for empty values
|
||||||
|
@ -139,7 +140,10 @@ if (LearningTasksDetailsWidgetNew) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.openUrlLearningTask();
|
||||||
qolLearningTaskOpened = true;
|
qolLearningTaskOpened = true;
|
||||||
|
};
|
||||||
|
LearningTasksDetailsWidgetNew.prototype.openUrlLearningTask = function() {
|
||||||
let learningTask = parseInt(getHashSearch().get("qol_learning_task"), 10);
|
let learningTask = parseInt(getHashSearch().get("qol_learning_task"), 10);
|
||||||
if (isNaN(learningTask)) {
|
if (isNaN(learningTask)) {
|
||||||
return;
|
return;
|
||||||
|
@ -154,11 +158,19 @@ if (LearningTasksDetailsWidgetNew) {
|
||||||
|
|
||||||
// Automatically add (and remove) the currently open learning task to the URL
|
// Automatically add (and remove) the currently open learning task to the URL
|
||||||
function handleLearningTaskShow() {
|
function handleLearningTaskShow() {
|
||||||
|
if (!modifyUrlHash) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let search = getHashSearch();
|
let search = getHashSearch();
|
||||||
search.set("qol_learning_task", this.learningTask.data.id);
|
search.set("qol_learning_task", this.learningTask.data.id);
|
||||||
history.pushState("", "", `#${search.laxToString()}`);
|
history.pushState("", "", `#${search.laxToString()}`);
|
||||||
}
|
}
|
||||||
function handleLearningTaskClose() {
|
function handleLearningTaskClose() {
|
||||||
|
if (!modifyUrlHash) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let search = getHashSearch();
|
let search = getHashSearch();
|
||||||
search.delete("qol_learning_task");
|
search.delete("qol_learning_task");
|
||||||
history.pushState("", "", `#${search.laxToString()}`);
|
history.pushState("", "", `#${search.laxToString()}`);
|
||||||
|
@ -342,6 +354,15 @@ function handleNewCalendarEvent(element, calendar) {
|
||||||
element.replaceWith(a);
|
element.replaceWith(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePanel(panel) {
|
||||||
|
let tabToOpen = window.location.pathname === "/Organise/Activities/Activity.aspx"
|
||||||
|
? getHashSearch().get("qol_open_tab")
|
||||||
|
: (window.location.hash.replace(/^#(.+?)(?:&.*)?$/, "$1") || null);
|
||||||
|
for (let i = 0; i < panel.items.items.length; i++) {
|
||||||
|
handlePanelItem(panel, panel.items.items[i], i === 0, tabToOpen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
|
function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
|
||||||
let panelId = panelItem.itemId || panelItem.id;
|
let panelId = panelItem.itemId || panelItem.id;
|
||||||
// example of panel-<id>: /Organise/Subjects/Subject.aspx
|
// example of panel-<id>: /Organise/Subjects/Subject.aspx
|
||||||
|
@ -354,7 +375,7 @@ function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
|
||||||
if (panelId === tabToOpen) {
|
if (panelId === tabToOpen) {
|
||||||
// if the sessions tab is automatically opened, the currently selected tab is still dashboard for some reason,
|
// if the sessions tab is automatically opened, the currently selected tab is still dashboard for some reason,
|
||||||
// hence this hook to open it when the dashboard finishes loading
|
// hence this hook to open it when the dashboard finishes loading
|
||||||
if (panel.setDashboardToLoading) {
|
if (!qolTabOpened && panel.setDashboardToLoading) {
|
||||||
let original = panel.setDashboardToLoading;
|
let original = panel.setDashboardToLoading;
|
||||||
panel.setDashboardToLoading = function(loading) {
|
panel.setDashboardToLoading = function(loading) {
|
||||||
original.apply(this, arguments);
|
original.apply(this, arguments);
|
||||||
|
@ -380,7 +401,7 @@ function handlePanelItem(panel, panelItem, isDefault, tabToOpen) {
|
||||||
}
|
}
|
||||||
// prevent the browser from scrolling to the body
|
// prevent the browser from scrolling to the body
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (window.location.hash !== panelItemHash && (window.location.pathname === "/Organise/Activities/Activity.aspx" || !window.location.hash.startsWith(`${panelItemHash}&`))) {
|
if (modifyUrlHash && window.location.hash !== panelItemHash && (window.location.pathname === "/Organise/Activities/Activity.aspx" || !window.location.hash.startsWith(`${panelItemHash}&`))) {
|
||||||
// Automatically add a reference to the tab when it is clicked
|
// Automatically add a reference to the tab when it is clicked
|
||||||
history.pushState("", "", panelItemHash);
|
history.pushState("", "", panelItemHash);
|
||||||
}
|
}
|
||||||
|
@ -471,18 +492,12 @@ function handleNewNode(node, observer) {
|
||||||
handleNewCalendarEvent(element, calendar);
|
handleNewCalendarEvent(element, calendar);
|
||||||
}
|
}
|
||||||
} else if (!qolTabOpened && node.classList.contains("x-panel")) {
|
} else if (!qolTabOpened && node.classList.contains("x-panel")) {
|
||||||
qolTabOpened = true;
|
|
||||||
let topMostPanel = node;
|
let topMostPanel = node;
|
||||||
while (topMostPanel.parentElement.closest(".x-panel")) {
|
while (topMostPanel.parentElement.closest(".x-panel")) {
|
||||||
topMostPanel = topMostPanel.parentElement.closest(".x-panel");
|
topMostPanel = topMostPanel.parentElement.closest(".x-panel");
|
||||||
}
|
}
|
||||||
let panel = unsafeWindow.Ext.getCmp(topMostPanel.id);
|
handlePanel(unsafeWindow.Ext.getCmp(topMostPanel.id));
|
||||||
let tabToOpen = window.location.pathname === "/Organise/Activities/Activity.aspx"
|
qolTabOpened = true;
|
||||||
? getHashSearch().get("qol_open_tab")
|
|
||||||
: (window.location.hash.replace(/^#(.+?)(?:&.*)?$/, "$1") || null);
|
|
||||||
for (let i = 0; i < panel.items.items.length; i++) {
|
|
||||||
handlePanelItem(panel, panel.items.items[i], i === 0, tabToOpen);
|
|
||||||
}
|
|
||||||
} else if (node.closest("[id^='wikibrowserpanel-'], #CompassWidgetsWikiBrowserPanel")) {
|
} else if (node.closest("[id^='wikibrowserpanel-'], #CompassWidgetsWikiBrowserPanel")) {
|
||||||
// Make files and folders in wiki/resources clickable for Link Hints
|
// Make files and folders in wiki/resources clickable for Link Hints
|
||||||
if (node.localName === "td") {
|
if (node.localName === "td") {
|
||||||
|
@ -553,6 +568,54 @@ document.body.addEventListener("keydown", function(event) {
|
||||||
window.down("#saveButton").handler();
|
window.down("#saveButton").handler();
|
||||||
}, {passive: true});
|
}, {passive: true});
|
||||||
|
|
||||||
|
// Re-open panel tabs and learning tasks when the URL changes
|
||||||
|
function getLearningTaskWindow() {
|
||||||
|
let LearningTasksSubmissionWidget = getExtClass("Compass.widgets.LearningTasksSubmissionWidget");
|
||||||
|
|
||||||
|
for (let window of document.querySelectorAll(".x-window")) {
|
||||||
|
window = unsafeWindow.Ext.getCmp(window.id);
|
||||||
|
if (unsafeWindow.Ext.getClass(window) === LearningTasksSubmissionWidget) {
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function getLearningTaskTab(panel) {
|
||||||
|
return panel.items.items.find(function(tab) {
|
||||||
|
return tab.itemId === "learningtasks";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.addEventListener("hashchange", function(event) {
|
||||||
|
modifyUrlHash = false;
|
||||||
|
let isActivityPage = window.location.pathname === "/Organise/Activities/Activity.aspx";
|
||||||
|
let hashSearch = getHashSearch();
|
||||||
|
|
||||||
|
let panel = document.querySelector(".x-panel");
|
||||||
|
if (panel) {
|
||||||
|
panel = unsafeWindow.Ext.getCmp(panel.id);
|
||||||
|
if (isActivityPage && hashSearch.has("openLearningTaskTab")) {
|
||||||
|
panel.setActiveTab(getLearningTaskTab(panel));
|
||||||
|
} else if (isActivityPage && hashSearch.size === 1) {
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
panel.setActiveTab(panel.items.items[0]);
|
||||||
|
} else {
|
||||||
|
handlePanel(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let learningTaskWindow = getLearningTaskWindow();
|
||||||
|
if (learningTaskWindow) {
|
||||||
|
learningTaskWindow.close();
|
||||||
|
}
|
||||||
|
let learningTaskWidget = document.querySelector(".sel-learning-tasks-widget");
|
||||||
|
if (learningTaskWidget) {
|
||||||
|
unsafeWindow.Ext.getCmp(learningTaskWidget.id).openUrlLearningTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyUrlHash = true;
|
||||||
|
});
|
||||||
|
|
||||||
// Stop the calendar and email buttons from opening in a new tab
|
// Stop the calendar and email buttons from opening in a new tab
|
||||||
for (let element of document.querySelectorAll("#productNavBar a[target='_blank']")) {
|
for (let element of document.querySelectorAll("#productNavBar a[target='_blank']")) {
|
||||||
element.removeAttribute("target");
|
element.removeAttribute("target");
|
||||||
|
|
|
@ -57,6 +57,7 @@ A userscript that adds small but useful features for Compass. Features are:
|
||||||
- Workaround a [Link Hints bug](https://github.com/lydell/LinkHints/issues/86)
|
- Workaround a [Link Hints bug](https://github.com/lydell/LinkHints/issues/86)
|
||||||
that prevents it from seeing links inside lesson plans and such
|
that prevents it from seeing links inside lesson plans and such
|
||||||
- Files and folders in Resources are now sorted alphabetically
|
- Files and folders in Resources are now sorted alphabetically
|
||||||
|
- Reopening panel tabs and learning tasks when the URL changes
|
||||||
- The option to remember logins is unchecked by default
|
- The option to remember logins is unchecked by default
|
||||||
- The dashboard tab in a user's profile no longer points you to #dsh
|
- The dashboard tab in a user's profile no longer points you to #dsh
|
||||||
- Pages can no longer be scrolled if a window is currently open
|
- Pages can no longer be scrolled if a window is currently open
|
||||||
|
|
Loading…
Reference in New Issue