-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd2l.js
More file actions
31 lines (29 loc) · 1.12 KB
/
d2l.js
File metadata and controls
31 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// ==UserScript==
// @name Better D2L
// @version 0.1
// @description Button to open all unread discussion posts
// @author Goofables
// @match https://d2l.sdbor.edu/*
// @icon https://www.google.com/s2/favicons?domain=d2l.sdbor.edu
// @grant none
// ==/UserScript==
function getElementsByXPath(xpath, parent) {
let results = [];
let query = document.evaluate(xpath, parent || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0, length = query.snapshotLength; i < length; ++i) {
results.push(query.snapshotItem(i));
}
return results;
}
setTimeout(
() => {
const button = document.createElement('button');
button.innerText = 'Open all unread';
button.addEventListener('click', () => {
for (const u of getElementsByXPath("//div[contains(@class,'d2l-le-disc-post') and contains(@class,'unread')]//a[contains(@class,'d2l-linkheading-link')]")) {
window.open(u.href, '_blank');
}
})
document.getElementById("createThreadButtonContainer").appendChild(button);
}, 500
)