Update Compass QoL Enhancer to 1.29.0

- Fix opening links with ampersands submitted in Learning Tasks
This commit is contained in:
blankie 2024-03-18 14:54:45 +11:00
parent cbebfa5995
commit 65a219c844
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 18 additions and 14 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.28.0 // @version 1.29.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
@ -129,16 +129,18 @@ function handleNewsItemClick(event) {
this.expandTruncated(); this.expandTruncated();
} }
} }
let NewsfeedItemWidget = getExtClass("Compass.widgets.NewsfeedItemWidget"); function handleNewsItem(newsItem) {
if (NewsfeedItemWidget) { if (!newsItem.priority) {
function addImportantFlag(newsItem) { return;
}
let img = document.createElement("img"); let img = document.createElement("img");
img.src = `${newsItem.m_AssetPath}Pix/16x16/flag_orange.png`; img.src = `${newsItem.m_AssetPath}Pix/16x16/flag_orange.png`;
img.classList.add("priority-flag"); img.classList.add("priority-flag");
img.dataset.qtip = "This news item has been flagged as important"; img.dataset.qtip = "This news item has been flagged as important";
newsItem.newsItemDetails.el.dom.querySelector("div > span > div > span").append(img); newsItem.newsItemDetails.el.dom.querySelector("div > span > div > span").append(img);
} }
let NewsfeedItemWidget = getExtClass("Compass.widgets.NewsfeedItemWidget");
if (NewsfeedItemWidget) {
let originalRenderLayout = NewsfeedItemWidget.prototype.renderLayout; let originalRenderLayout = NewsfeedItemWidget.prototype.renderLayout;
NewsfeedItemWidget.prototype.renderLayout = function() { NewsfeedItemWidget.prototype.renderLayout = function() {
originalRenderLayout.apply(this, arguments); originalRenderLayout.apply(this, arguments);
@ -148,9 +150,7 @@ if (NewsfeedItemWidget) {
// Expand news feed items by clicking on them // Expand news feed items by clicking on them
this.el.on("click", handleNewsItemClick.bind(this), this.el); this.el.on("click", handleNewsItemClick.bind(this), this.el);
// Add important flag to priority news items // Add important flag to priority news items
if (this.priority) { handleNewsItem(this);
addImportantFlag(this);
}
}); });
} }
@ -597,7 +597,10 @@ function handleLearningTaskSubmissionTable(element) {
if (item.submissionFileType === LearningTasksSubmissionFileType.File) { if (item.submissionFileType === LearningTasksSubmissionFileType.File) {
url = `/Services/FileDownload/FileRequestHandler?FileDownloadType=2&taskId=${taskId}&submissionId=${item.id}`; url = `/Services/FileDownload/FileRequestHandler?FileDownloadType=2&taskId=${taskId}&submissionId=${item.id}`;
} else if (item.submissionFileType === LearningTasksSubmissionFileType.SubmissionUrl) { } else if (item.submissionFileType === LearningTasksSubmissionFileType.SubmissionUrl) {
url = item.fileName; // Fix opening submitted links with ampersands
let parser = new DOMParser();
let document = parser.parseFromString(item.fileName, "text/html");
url = document.documentElement.textContent;
} else { } else {
continue; continue;
} }
@ -827,7 +830,7 @@ if (unsafeWindow.CKEDITOR) {
for (let attr of script.attributes) { for (let attr of script.attributes) {
scriptClone.setAttribute(attr.name, attr.value); scriptClone.setAttribute(attr.name, attr.value);
} }
scriptClone.innerText = script.innerText; scriptClone.innerText = script.textContent;
script.replaceWith(scriptClone); script.replaceWith(scriptClone);
} }
this.$.dispatchEvent(new Event("DOMContentLoaded")); this.$.dispatchEvent(new Event("DOMContentLoaded"));

View File

@ -41,6 +41,7 @@ A userscript that adds small but useful features for Compass. Features are:
permission information) permission information)
- File upload buttons now work with [Link Hints] - File upload buttons now work with [Link Hints]
- Fix submitting links by simply pressing Enter - Fix submitting links by simply pressing Enter
- Fix opening links with ampersands submitted in Learning Tasks
- Links inside lesson plans now open in the parent tab by default instead of - Links inside lesson plans now open in the parent tab by default instead of
creating a new tab creating a new tab
- Files and links submitted to learning tasks are now actual links (they now - Files and links submitted to learning tasks are now actual links (they now