-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroyalroad.js
More file actions
56 lines (52 loc) · 1.55 KB
/
royalroad.js
File metadata and controls
56 lines (52 loc) · 1.55 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ==UserScript==
// @author dylanarmstrong
// @description Royalroad stuff
// @grant none
// @match https://*.royalroad.com/*
// @name royalroad
// @namespace https://github.com/dylanarmstrong/userscripts/
// @supportURL https://github.com/dylanarmstrong/userscripts/issues
// @updateURL https://raw.githubusercontent.com/dylanarmstrong/userscripts/main/royalroad.js
// @version 5
// ==/UserScript==
/**
* Just some royalroad stuff
*/
(function main() {
const colors = {
bad: "text-gray-400",
eh: "text-warning",
good: "text-blue-500",
ok: "text-black",
};
let els = document.querySelectorAll("[data-rr-initial-rating]");
for (let index = 0, length_ = els.length; index < length_; index++) {
const element = els[index];
const rate = document.createElement("span");
const number_ = Number.parseFloat(
element.getAttribute("data-rr-initial-rating"),
);
if (!Number.isNaN(number_)) {
let color;
if (number_ > 4.5) {
color = colors.good;
} else if (number_ > 4.1) {
color = colors.ok;
} else if (number_ > 3.8) {
color = colors.eh;
} else {
color = colors.bad;
}
rate.textContent = number_;
rate.classList.add(color, "font-bold");
element.parentNode.replaceChild(rate, element);
}
}
for (const element of document.querySelectorAll(
"div.bold.uppercase, span.bold.uppercase",
)) {
if (element.textContent.toLowerCase() === "advertisement") {
element.parentNode.remove();
}
}
})();