Repository navigation
Expand file tree
/
Copy pathprogress.html
More file actions
92 lines (83 loc) · 3.29 KB
/
Copy pathprogress.html
File metadata and controls
92 lines (83 loc) · 3.29 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: system-ui; padding: 20px; background: #f0f0f0; margin: 0; }
.container { text-align: center; }
.status { font-size: 14px; margin-bottom: 15px; color: #333; }
.progress-bar { width: 100%; height: 10px; background: #ddd; border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; background: #4CAF50; width: 0%; transition: width 0.3s; }
.percentage { margin-top: 10px; font-size: 12px; color: #666; }
.button-container { margin-top: 15px; }
#cancelBtn { padding: 8px 16px; background: #f44336; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; }
#cancelBtn:hover { background: #d32f2f; }
#cancelBtn:disabled { background: #ccc; cursor: not-allowed; }
</style>
</head>
<body>
<div class="container">
<div class="status" id="status">Checking for updates...</div>
<div class="progress-bar"><div class="progress-fill" id="progressFill"></div></div>
<div class="percentage" id="percentage">0%</div>
<div class="button-container">
<button id="cancelBtn">Cancel</button>
</div>
</div>
<script>
let canCancel = false;
let currentProgress = 0;
let autoIncrementStartProgress = 0;
let autoIncrementTimeout = null;
let incrementsApplied = 0;
function stopAutoIncrement() {
if (autoIncrementTimeout) {
clearTimeout(autoIncrementTimeout);
autoIncrementTimeout = null;
incrementsApplied = 0;
}
}
function startAutoIncrement() {
stopAutoIncrement();
autoIncrementStartProgress = currentProgress;
incrementsApplied = 0;
function scheduleNextIncrement() {
autoIncrementTimeout = setTimeout(() => {
// Check if we've already applied 35% increment
if (incrementsApplied < 35) {
const newProgress = currentProgress + 1;
// Prevent overflow beyond 100%
if (newProgress <= 100) {
currentProgress = newProgress;
document.getElementById('progressFill').style.width = currentProgress + '%';
document.getElementById('percentage').textContent = currentProgress + '%';
incrementsApplied++;
}
}
// Continue scheduling if we haven't reached 35% increment yet
if (incrementsApplied < 35) {
scheduleNextIncrement();
}
}, 5000);
}
scheduleNextIncrement();
}
window.progressAPI.onUpdateProgress(([status, progress, cancellable]) => {
currentProgress = progress;
document.getElementById('status').textContent = status;
document.getElementById('progressFill').style.width = progress + '%';
document.getElementById('percentage').textContent = progress + '%';
canCancel = cancellable || false;
document.getElementById('cancelBtn').disabled = !canCancel;
// Start auto-increment when a new progress value is set
startAutoIncrement();
});
document.getElementById('cancelBtn').addEventListener('click', () => {
if (canCancel) {
window.progressAPI.cancelUpdate();
document.getElementById('cancelBtn').disabled = true;
stopAutoIncrement();
}
});
</script>
</body>
</html>