Update Compass QoL Enhancer to 1.15.0

- Fix text on news feed items being unselected on mouse up
- Make links submitted to learning tasks actual links
This commit is contained in:
blankie 2023-09-06 17:26:52 +10:00
parent b3558d6fc6
commit 59aef8d509
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 50 additions and 11 deletions

View File

@ -2,7 +2,7 @@
// @name Compass QoL Enhancer
// @namespace blankie-scripts
// @match http*://*.compass.education/*
// @version 1.14.0
// @version 1.15.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
@ -71,6 +71,26 @@ if (UserProfileNewWidget) {
};
}
function handleNewsItemClick() {
if (!this.moreButton.hidden) {
Compass.saveScrollPosition();
this.expandTruncated();
}
}
let NewsfeedItemWidget = getExtClass("Compass.widgets.NewsfeedItemWidget");
if (NewsfeedItemWidget) {
let original = NewsfeedItemWidget.prototype.renderLayout;
NewsfeedItemWidget.prototype.renderLayout = function() {
original.apply(this, arguments);
// prevent clicking on text from expanding the item since this disrupts selecting text, and we're gonna extend this to the entire item anyway
this.newsItemTextContainer.events.afterrender = true;
// Expand news feed items by clicking on them
this.on("afterrender", function() {
this.el.on("click", handleNewsItemClick.bind(this), undefined, {single: true});
});
}
}
// Automatically open learning tasks specified in the URL
let LearningTasksDetailsWidgetNew = getExtClass("Compass.widgets.LearningTasksDetailsWidgetNew");
if (LearningTasksDetailsWidgetNew) {
@ -98,9 +118,9 @@ if (LearningTasksDetailsWidgetNew) {
}
// Automatically add (and remove) the currently open learning task to the URL
function handleLearningTaskOpen(window) {
function handleLearningTaskShow() {
let search = getHashSearch();
search.set("qol_learning_task", window.learningTask.data.id);
search.set("qol_learning_task", this.learningTask.data.id);
history.pushState("", "", `#${search.laxToString()}`);
}
function handleLearningTaskClose() {
@ -113,11 +133,12 @@ if (LearningTasksSubmissionWidget) {
let original = LearningTasksSubmissionWidget.prototype.initComponent;
LearningTasksSubmissionWidget.prototype.initComponent = function() {
original.apply(this, arguments);
handleLearningTaskOpen(this);
this.on("show", handleLearningTaskShow.bind(this));
this.on("close", handleLearningTaskClose);
}
}
// Make session previous/next button links
function updateInstanceButton(instanceDetails, instanceButton, offset) {
// Make previous/next session buttons links
let index = instanceDetails.instanceStore.indexOfId(instanceDetails.m_instanceId);
@ -313,6 +334,27 @@ function handleLearningTasksTable(element) {
}
}
// Make links submitted to a learning task actual links
function handleLearningTaskSubmissionTable(element) {
let items = unsafeWindow.Ext.getCmp(element.id).store.data.items;
let lastColumns = element.querySelectorAll(".x-grid-cell-last img");
for (let i = 0; i < items.length; i++) {
let item = items[i].data;
let img = lastColumns[i];
if (item.submissionFileType !== unsafeWindow.Compass.enums.LearningTasksSubmissionFileType.SubmissionUrl) {
continue;
}
let a = document.createElement("a");
a.href = item.fileName;
a.addEventListener("click", function(event) {
event.stopImmediatePropagation();
}, {passive: true});
img.replaceWith(a);
a.append(img);
}
}
function handleCKEditor(instance) {
instance.on("contentDom", function() {
let editable = instance.editable();
@ -371,6 +413,8 @@ function handleNewNode(node, observer) {
}
} else if (node.localName === "table" && node.closest(".sel-learning-tasks-widget")) {
handleLearningTasksTable(node);
} else if (node.classList.contains("x-grid-view") && unsafeWindow.Ext.getCmp(node.id).up("#submissionsPanel")) {
handleLearningTaskSubmissionTable(node);
} else if (node.classList.contains("cke")) {
let instance = unsafeWindow.CKEDITOR.instances[node.id.substring(4)];
handleCKEditor(instance);
@ -410,13 +454,6 @@ document.body.addEventListener("click", function(event) {
} else if (event.target.classList.contains("x-form-file-btn")) {
// Make Link Hints work with uploading files
event.target.querySelector("input[type=file]").click();
} else if (event.target.closest(".newsfeed-newsItem") && !event.target.closest("a")) {
// Expand news feed items by clicking on them
// the <a> check is to prevent expending by clicking on a link (say, to a file)
let seeMore = event.target.closest(".newsfeed-newsItem").querySelector(".newsfeed-newsItem-seeMoreCTA a");
if (seeMore) {
seeMore.click();
}
}
}, {passive: true});

View File

@ -35,6 +35,8 @@ A userscript that adds small but useful features for Compass. Features include:
- File upload buttons now work with [Link Hints]
- Links inside lesson plans now open in the parent tab by default instead of
creating a new tab
- Links submitted to learning tasks are now actual links (they now work with
[Link Hints] and they can be ctrl-clicked)
- Ctrl-clicking an activity in a user's learning tasks tab no longer collapses
everything else
- Learning tasks now being links (you can ctrl-click them)