Update Compass QoL Enhancer to 1.16.0

- Slightly more elegantly suppress the barebones CKEditor context menu
- Workaround https://github.com/lydell/LinkHints/issues/86
This commit is contained in:
blankie 2023-09-11 08:31:47 +10:00
parent a2b8370309
commit eb1a4ab0a3
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 23 additions and 13 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.15.0 // @version 1.16.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
@ -86,7 +86,7 @@ if (NewsfeedItemWidget) {
this.newsItemTextContainer.events.afterrender = true; this.newsItemTextContainer.events.afterrender = true;
// Expand news feed items by clicking on them // Expand news feed items by clicking on them
this.on("afterrender", function() { this.on("afterrender", function() {
this.el.on("click", handleNewsItemClick.bind(this), undefined, {single: true}); this.el.on("click", handleNewsItemClick.bind(this), this.el, {single: true});
}); });
} }
} }
@ -138,7 +138,6 @@ if (LearningTasksSubmissionWidget) {
} }
} }
// Make session previous/next button links
function updateInstanceButton(instanceDetails, instanceButton, offset) { function updateInstanceButton(instanceDetails, instanceButton, offset) {
// Make previous/next session buttons links // Make previous/next session buttons links
let index = instanceDetails.instanceStore.indexOfId(instanceDetails.m_instanceId); let index = instanceDetails.instanceStore.indexOfId(instanceDetails.m_instanceId);
@ -367,7 +366,7 @@ function handleCKEditor(instance) {
function handleCKEditorLink(element) { function handleCKEditorLink(element) {
// Make links inside lesson plans open in the parent instead of a new tab // Make links inside lesson plans open in the parent instead of a new tab
if (element.target !== "_blank" && element.target) { if (element.target === "_parent") {
return; return;
} }
@ -462,17 +461,26 @@ for (let element of document.querySelectorAll("#productNavBar a[target='_blank']
element.removeAttribute("target"); element.removeAttribute("target");
} }
// Suppress that annoying barebones context menu that only has Copy
// why is it not obvious that you can just hold ctrl or shift to suppress it???
// i know it's compass' fault but i'm still frustrated
// unsafeWindow.CKEDITOR may not be set if you're on the login page, for example // unsafeWindow.CKEDITOR may not be set if you're on the login page, for example
if (unsafeWindow.CKEDITOR) { if (unsafeWindow.CKEDITOR) {
let originalOn = unsafeWindow.CKEDITOR.dom.domObject.prototype.on; // Suppress that annoying barebones context menu that only has Copy
unsafeWindow.CKEDITOR.dom.domObject.prototype.on = function(type, listener) { unsafeWindow.CKEDITOR.plugins.load("contextmenu", function() {
// https://stackoverflow.com/a/10815581 unsafeWindow.CKEDITOR.plugins.contextMenu.prototype.addTarget = function() {};
if (type !== "contextmenu") { });
return originalOn.apply(this, arguments);
// Workaround https://github.com/lydell/LinkHints/issues/86
CKEDITOR.dom.document.prototype.write = function(data) {
this.$.documentElement.innerHTML = data;
for (let script of this.$.documentElement.querySelectorAll("script")) {
// script.cloneNode() makes it not execute for some reason
let scriptClone = document.createElement("script");
for (let attr of script.attributes) {
scriptClone.setAttribute(attr.name, attr.value);
} }
scriptClone.innerText = script.innerText;
script.replaceWith(scriptClone);
}
this.$.dispatchEvent(new Event("DOMContentLoaded"));
}; };
} }

View File

@ -23,7 +23,7 @@ Hacky script to disable the client-side file limit per tab
## Compass QoL Enhancer ## Compass QoL Enhancer
A userscript that adds small but useful features for Compass. Features include: A userscript that adds small but useful features for Compass. Features are:
- The ability to close windows by clicking on the background - The ability to close windows by clicking on the background
- Calendar events now being links (they work with [Link Hints] now! you can - Calendar events now being links (they work with [Link Hints] now! you can
also ctrl+click on "standard classes", events, and learning tasks) also ctrl+click on "standard classes", events, and learning tasks)
@ -46,6 +46,8 @@ A userscript that adds small but useful features for Compass. Features include:
- Class and news feed items can now be opened by simply clicking on their - Class and news feed items can now be opened by simply clicking on their
background background
- The context menu that only says "Copy" is now suppressed - The context menu that only says "Copy" is now suppressed
- Workaround a [Link Hints bug](https://github.com/lydell/LinkHints/issues/86)
that prevents it from seeing links inside lesson plans and such
- 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