-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (55 loc) · 2.37 KB
/
Copy pathscript.js
File metadata and controls
68 lines (55 loc) · 2.37 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
57
58
59
60
61
62
63
64
65
66
67
68
function darkModeEnabled() {
var currentCSS = document.getElementById("highlight-css");
return currentCSS.getAttribute("href") === "file/css/highlightjs/github-dark.min.css";
}
function getColor(percentage) {
if (percentage == 0) return "rgba(0, 0, 0, 0)";
const bright_colors = [
{ stop: 0, color: [0, 123, 255] },
{ stop: 25, color: [0, 255, 0] },
{ stop: 50, color: [255, 255, 0] },
{ stop: 75, color: [255, 165, 0] },
{ stop: 100, color: [255, 0, 0] }
];
const muted_colors = [
{ stop: 0, color: [0, 61, 128] }, // Muted blue
{ stop: 25, color: [0, 128, 0] }, // Muted green
{ stop: 50, color: [128, 128, 0] }, // Muted yellow
{ stop: 75, color: [128, 82, 0] }, // Muted orange
{ stop: 100, color: [128, 0, 0] } // Muted red
];
const colors = darkModeEnabled()? muted_colors:bright_colors;
let startColor, endColor, startStop, endStop;
for (let i = 0; i < colors.length - 1; i++) {
if (percentage >= colors[i].stop && percentage <= colors[i + 1].stop) {
startColor = colors[i].color;
endColor = colors[i + 1].color;
startStop = colors[i].stop;
endStop = colors[i + 1].stop;
break;
}
}
const ratio = (percentage - startStop) / (endStop - startStop);
const r = Math.round(startColor[0] + ratio * (endColor[0] - startColor[0]));
const g = Math.round(startColor[1] + ratio * (endColor[1] - startColor[1]));
const b = Math.round(startColor[2] + ratio * (endColor[2] - startColor[2]));
return `rgb(${r}, ${g}, ${b})`;
}
function updateProgressBar(percentage) {
if (percentage === undefined) percentage = 0;
progressContainer.lastPercentage = percentage;
const progressBar = progressContainer.querySelector('.progress-bar');
progressBar.style.width = percentage + '%';
progressBar.style.backgroundColor = getColor(percentage);
}
function toggleDarkMode() {
if (darkModeEnabled()) {
var lightGray = getComputedStyle(document.body).getPropertyValue("--light-gray");
progressContainer.style.backgroundColor = lightGray;
} else {
progressContainer.style.backgroundColor = "#f3f4f6";
}
updateProgressBar(progressContainer.lastPercentage);
}
var progressContainer = document.querySelector('.progress-container');
toggleDarkMode();