-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprogressbars.js
149 lines (123 loc) · 4.83 KB
/
progressbars.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function progressBarContainer() {
const containerId = 'MemDump_progressContainer';
const existingContainer = document.getElementById(containerId);
if (existingContainer) return existingContainer;
const progress_bar_container = document.createElement("div");
progress_bar_container.id = containerId;
try {
document.querySelector(".rebrand-header-root").prepend(progress_bar_container);
} catch (err) {
document.body.prepend(progress_bar_container);
}
return progress_bar_container;
}
function progressBar(barId, padding = true) {
const existingBar = document.getElementById(barId);
if (existingBar) return existingBar;
const progress_bar_container = progressBarContainer();
if (!progress_bar_container) return;
const progress_bar = document.createElement("div");
progress_bar.id = barId;
progress_bar_container.appendChild(progress_bar);
const padId = 'MemDump_progress-padding-' + barId.split('-').at(-1);
const existingPad = document.getElementById(padId);
if (!padding || existingPad) return progress_bar;
const padding_bar = document.createElement("div");
padding_bar.id = padId;
try {
document.querySelector("#page-head").prepend(padding_bar);
} catch (err) {}
return progress_bar;
}
function batchProgressBar(batch_size) {
if (batch_size < 2) return;
return progressBar('MemDump_progress-batch');
}
function scanProgressBar(threadN) {
return progressBar('MemDump_progress-thread-' + threadN);
}
function mediaProgressBar() {
return progressBar('MemDump_progress-media', false);
}
function removeScanBar(threadN) {
const progress_bar = document.getElementById('MemDump_progress-thread-' + threadN);
if (progress_bar) {
progress_bar.style.animationPlayState = "paused";
setTimeout(()=>{
void progress_bar.offsetHeight;
progress_bar.classList.add('off');
progress_bar.style.animationPlayState = "running";
}, 500);
}
const padding_bar = document.getElementById('MemDump_progress-padding-' + threadN);
const remaining_count = document.querySelectorAll('[id^="MemDump_progress-padding-"]').length;
if (padding_bar && remaining_count > 1) {
padding_bar.style.animationPlayState = "paused";
setTimeout(()=>{
void padding_bar.offsetHeight;
padding_bar.classList.add('off');
padding_bar.style.animationPlayState = "running";
}, 500);
}
}
//progress updates (glue)
function updScanProgress(threadN, cidd, levels_done, levels_todo, label = undefined) {
//text progress (console)
const done_str = levels_todo !== "" ? `${levels_done}/${levels_todo}` : "";
if (levels_done === 0) {
if (levels_todo || label) {
console.log(`thread: ${threadN} | Start scanning ${cidd['cid']}`);
} else {
console.log(`thread: ${threadN} | Fetching metadata for ${cidd['cid']}`);
}
} else {
console.log(`thread: ${threadN} | cid: ${cidd['cid']} | scan progress: ${done_str}`);
}
const progress_bar = scanProgressBar(threadN);
if (!progress_bar) return;
//GUI progress
if (label !== undefined) {
progress_bar.setAttribute("progress-label", label);
}
progress_bar.setAttribute("progress-ratio", done_str);
if (levels_todo || label) {
if (!isNaN(parseInt(levels_todo, 10))) {
progress_bar.style.backgroundPosition = (100 * (1. - levels_done/levels_todo)).toFixed(2)+"%";
} else {
progress_bar.style.backgroundPosition = "42%";
}
} else {
progress_bar.classList.add('resetting');
progress_bar.style.backgroundPosition = "100%";
setTimeout(() => {
progress_bar.classList.remove('resetting');
}, 500);
}
}
function updBatchProgress(batch_done = 0, batch_size = 1, cidd = "") {
const done_str = `${batch_done}/${batch_size}`;
if (cidd) {
console.log(`cid: ${cidd['cid']} | scan complete (${done_str})`);
}
const batch_progress_bar = batchProgressBar(batch_size);
if (!batch_progress_bar) return;
batch_progress_bar.setAttribute("progress-label", "Batch progress");
batch_progress_bar.setAttribute("progress-ratio", done_str);
batch_progress_bar.style.backgroundPosition = (100 * (1. - batch_done/batch_size)).toFixed(2)+"%";
}
function updMediaProgress(media_done = 0, media_total = 1) {
const media_progress_bar = mediaProgressBar();
if (!media_progress_bar) return;
if (media_done === "done") {
console.log('media download complete');
media_progress_bar.setAttribute("progress-label", "");
media_progress_bar.setAttribute("progress-ratio", "done!");
media_progress_bar.classList.add('done');
return;
}
const done_str = `${media_done}/${media_total}`;
console.log("media download progress: ", done_str);
media_progress_bar.setAttribute("progress-label", "Downloading files...");
media_progress_bar.setAttribute("progress-ratio", done_str);
media_progress_bar.style.backgroundPosition = (100 * (1. - media_done/media_total)).toFixed(2)+"%";
}