Skip to content

Instantly share code, notes, and snippets.

@daffodilistic
Last active February 19, 2022 03:39
Show Gist options
  • Save daffodilistic/e3fe8f4a0cad805f3219c383aedd37d2 to your computer and use it in GitHub Desktop.
Save daffodilistic/e3fe8f4a0cad805f3219c383aedd37d2 to your computer and use it in GitHub Desktop.
Auto-sort by filename on page load in LumiNUS
// ==UserScript==
// @name LumiNUSAutoSort
// @description Sorts files alphabetically by default when you view the "Files" section of a module in LumiNUS
// @author Soh Thiam Hing
// @license OSL-3.0
// @version 1.0
// @match https://luminus.nus.edu.sg/*
// @namespace com.daffodilistic.tampermonkey
// @require https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@6b9ca81bf32899b4274086aa9d48c3ce5648e0b6/waitForKeyElements.js
// ==/UserScript==
waitForKeyElements(selectSortIconElement, sortByFilename, false);
function selectSortIconElement() {
let targets = document.querySelectorAll("list-view > section > header > column.name > div > i");
let elements = [];
for (const t of targets) {
if (t.parentNode.textContent.includes("File Name") && !t.hasAttribute('data-userscript-alreadyfound')) {
elements.push(t);
}
}
return elements;
}
function sortByFilename(node) {
let event = new Event('click');
node.dispatchEvent(event);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment