Compare commits

...

2 Commits

Author SHA1 Message Date
blankie 03debb468a
Update Elements with ID lister to 1.0.12
- Set `all` to `initial` (https://lamplightdev.com/blog/2019/03/26/why-is-my-web-component-inheriting-styles/)
- See the `name` attribute in anchor tags as IDs (https://wayland.freedesktop.org/docs/html/apb.html)
- Attempt to get text by going up the DOM (https://wayland.freedesktop.org/docs/html/apb.html)
2023-08-01 17:04:50 +10:00
blankie 906974ae67
Update Compass QoL Enhancer to 1.4.0
- Display calendar events' end time now without having to hover over them
2023-08-01 16:55:53 +10:00
3 changed files with 31 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.3.0 // @version 1.4.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
@ -84,8 +84,8 @@ function handleNewNode(node) {
if (node.localName === "td") { if (node.localName === "td") {
node.setAttribute("role", "button"); node.setAttribute("role", "button");
} }
for (let expander of node.querySelectorAll("td, .x-tree-expander")) { for (let element of node.querySelectorAll("td, .x-tree-expander")) {
expander.setAttribute("role", "button"); element.setAttribute("role", "button");
} }
} }
} }
@ -119,9 +119,13 @@ function handleNewCalendarEvent(element) {
let calendarElement = element.closest(".x-component.ext-cal-ct, .x-component.ext-cal-body-ct"); let calendarElement = element.closest(".x-component.ext-cal-ct, .x-component.ext-cal-body-ct");
let calendar = unsafeWindow.Ext.getCmp(calendarElement.id); let calendar = unsafeWindow.Ext.getCmp(calendarElement.id);
if (a.classList.contains("activity-type-1")) { if (a.classList.contains("activity-type-1")) {
// Add a link for activities/"standard classes" // Add a link and show the finish time for activities/"standard classes"
let data = calendar.getEventRecordFromEl(element).data; let data = calendar.getEventRecordFromEl(element).data;
let startString = unsafeWindow.Ext.util.Format.date(data.start, unsafeWindow.Compass.TIME_NO_PERIOD_FORMAT);
let finishString = unsafeWindow.Ext.util.Format.date(data.finish, unsafeWindow.Compass.TIME_NO_PERIOD_FORMAT);
a.href = `/Organise/Activities/Activity.aspx?targetUserId=${data.targetStudentId}#session/${data.instanceId}`; a.href = `/Organise/Activities/Activity.aspx?targetUserId=${data.targetStudentId}#session/${data.instanceId}`;
// yes, innerHTML. longTitleWithoutTime can apparently contain HTML. lets hope that startString and finishString don't
a.querySelector("span").innerHTML = `${startString} - ${finishString}: ${data.longTitleWithoutTime}`;
preventCompassHandler = true; preventCompassHandler = true;
} else if (a.classList.contains("activity-type-10")) { } else if (a.classList.contains("activity-type-10")) {
// Add a link for learning tasks // Add a link for learning tasks

View File

@ -6,7 +6,7 @@
// @grant GM_getResourceURL // @grant GM_getResourceURL
// @require https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.js#sha256-cec1a2e320aab77e28bad4ad6bc5e532a6ef5757345c19bb5158aa880b7162a6 // @require https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.js#sha256-cec1a2e320aab77e28bad4ad6bc5e532a6ef5757345c19bb5158aa880b7162a6
// @resource dialogPolyfillCSS https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.css#sha256-4dcb3ab62e545f30bf06a4824c253641ee889ca85ca28d5447590557922496ab // @resource dialogPolyfillCSS https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.min.css#sha256-4dcb3ab62e545f30bf06a4824c253641ee889ca85ca28d5447590557922496ab
// @version 1.0.11 // @version 1.0.12
// @author blankie // @author blankie
// @description A userscript that adds a "Show elements popup" option to the Monkey Menu which lists all elements with an ID // @description A userscript that adds a "Show elements popup" option to the Monkey Menu which lists all elements with an ID
// @inject-into content // @inject-into content
@ -19,7 +19,9 @@ const ACCENT_COLOR = "#962AC3";
const BRIGHT_ACCENT_COLOR = "#DE6DE6"; const BRIGHT_ACCENT_COLOR = "#DE6DE6";
const DIALOG_WRAPPER_CSS = ` const DIALOG_WRAPPER_CSS = `
all: unset; /* https://lamplightdev.com/blog/2019/03/26/why-is-my-web-component-inheriting-styles/ */
all: initial;
position: fixed; position: fixed;
top: 0; top: 0;
width: 100%; width: 100%;
@ -32,7 +34,6 @@ dialog {
max-height: 90%; max-height: 90%;
max-width: 90%; max-width: 90%;
font-size: 11pt; font-size: 11pt;
text-align: left;
font-family: sans-serif; font-family: sans-serif;
color-scheme: dark; color-scheme: dark;
overflow-y: auto; overflow-y: auto;
@ -143,7 +144,7 @@ function hideElementList() {
function getElementList() { function getElementList() {
let elements = []; let elements = [];
for (let element of document.body.querySelectorAll("[id]")) { for (let element of document.body.querySelectorAll("[id], a[name]")) {
if (shouldIgnoreElement(element)) { if (shouldIgnoreElement(element)) {
continue; continue;
} }
@ -155,9 +156,12 @@ function getElementList() {
function shouldIgnoreElement(element) { function shouldIgnoreElement(element) {
// Check if the element is not visible // Check if the element is not visible
let rect = element.getBoundingClientRect(); // https://wayland.freedesktop.org/docs/html/apb.html has <a name=...> elements with no size
if (rect.height === 0 || rect.width === 0) { if (element.localName !== "a") {
return true; let rect = element.getBoundingClientRect();
if (rect.height === 0 || rect.width === 0) {
return true;
}
} }
// Check if the element is a svg or a part of one // Check if the element is a svg or a part of one
@ -174,11 +178,15 @@ function shouldIgnoreElement(element) {
function getElementListItem(element) { function getElementListItem(element) {
let newLocation = new URL(location.href); let newLocation = new URL(location.href);
let id = element.id;
if (!id && element.localName === "a") {
id = element.name;
}
let li = document.createElement("li"); let li = document.createElement("li");
let a = document.createElement("a"); let a = document.createElement("a");
newLocation.hash = a.innerText = "#" + element.id; newLocation.hash = a.innerText = "#" + id;
a.href = newLocation.href; a.href = newLocation.href;
a.addEventListener("click", function(e) { a.addEventListener("click", function(e) {
if (e.ctrlKey) { if (e.ctrlKey) {
@ -198,7 +206,12 @@ function getElementListItem(element) {
function getElementDescription(element) { function getElementDescription(element) {
let addEilipses = false; let addEilipses = false;
let text = (element.innerText || "").trim(); // Attempt to get text by going up the DOM, as https://wayland.freedesktop.org/docs/html/apb.html has elements with no content
let text = "";
while (!text && element) {
text = (element.innerText || "").trim();
element = element.parentElement;
}
let newlineIndex = text.indexOf("\n"); let newlineIndex = text.indexOf("\n");
if (newlineIndex !== -1) { if (newlineIndex !== -1) {

View File

@ -22,6 +22,7 @@ A userscript that adds small but useful features for Compass. Features include:
- The ability to close windows by clicking on the background - The ability to close windows by clicking on the background
- Calendar events are now links (they work with [Link Hints] now! you can also - Calendar events are now links (they work with [Link Hints] now! you can also
ctrl+click on "standard classes" and learning tasks) ctrl+click on "standard classes" and learning tasks)
- Calendar events now show their end time without having to being hovered
- Tabs are now links (you can refresh pages and the tab will automatically - Tabs are now links (you can refresh pages and the tab will automatically
open. you can also ctrl+click on them) open. you can also ctrl+click on them)
- Files and folders in Resources is now marked clickable ([Link Hints] can now - Files and folders in Resources is now marked clickable ([Link Hints] can now