From 77b73718a6494dd9ccf739c72cc9faa55ec4be5d Mon Sep 17 00:00:00 2001 From: blankie Date: Mon, 11 Sep 2023 15:00:26 +1000 Subject: [PATCH] Update Compass QoL Enhancer to 1.17.0 - Sort files and folders alphabetically --- Compass QoL Enhancer.user.js | 32 +++++++++++++++++++++++++++++++- README.md | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Compass QoL Enhancer.user.js b/Compass QoL Enhancer.user.js index 5c34982..62c1450 100644 --- a/Compass QoL Enhancer.user.js +++ b/Compass QoL Enhancer.user.js @@ -2,7 +2,7 @@ // @name Compass QoL Enhancer // @namespace blankie-scripts // @match http*://*.compass.education/* -// @version 1.16.0 +// @version 1.17.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 @@ -205,6 +205,36 @@ if (InstanceDetailsWidget) { }; } +// Sort by name in wiki/resources +function wikiNodeSort(lhs, rhs) { + function isFolder(node) { + return node.data.type === unsafeWindow.Compass.enums.WikiNodeType.Folder; + } + + if (isFolder(lhs) && !isFolder(rhs)) { + return -1; + } else if (!isFolder(lhs) && isFolder(rhs)) { + return 1; + } + + let lhsName = lhs.data.name.toLowerCase(); + let rhsName = rhs.data.name.toLowerCase(); + if (lhsName < rhsName) { + return -1; + } else if (lhsName === rhsName) { + return 0; + } else { + return 1; + } +} +let WikiBrowserPanel = getExtClass("Compass.widgets.WikiBrowserPanel"); +if (WikiBrowserPanel) { + let original = WikiBrowserPanel.prototype.renderLayout; + WikiBrowserPanel.prototype.renderLayout = function() { + original.apply(this, arguments); + this.treePanel.store.sort({sorterFn: wikiNodeSort}); + } +} function handleNewCalendarEvent(element, calendar) { diff --git a/README.md b/README.md index b1171ce..78c0030 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ A userscript that adds small but useful features for Compass. Features are: - 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 +- FIles and folders in Resources are now sorted alphabetically - The option to remember logins is unchecked by default - The dashboard tab in a user's profile no longer points you to #dsh