Add speed formatting to display appropriate units (KB/s, MB/s)
Some checks failed
Some checks failed
This commit is contained in:
@@ -879,7 +879,7 @@ function createDownloadCard(download) {
|
||||
}
|
||||
|
||||
if (download.speed && download.speed > 0) {
|
||||
const speed = createDetailItem('Speed', download.speed);
|
||||
const speed = createDetailItem('Speed', formatSpeed(download.speed));
|
||||
details.appendChild(speed);
|
||||
}
|
||||
|
||||
@@ -936,6 +936,21 @@ function createDownloadCard(download) {
|
||||
return card;
|
||||
}
|
||||
|
||||
function formatSpeed(bytesPerSecond) {
|
||||
if (!bytesPerSecond || bytesPerSecond === 0) return '0 B/s';
|
||||
|
||||
const units = ['B/s', 'KB/s', 'MB/s', 'GB/s'];
|
||||
let value = bytesPerSecond;
|
||||
let unitIndex = 0;
|
||||
|
||||
while (value >= 1024 && unitIndex < units.length - 1) {
|
||||
value /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
return `${value.toFixed(2)} ${units[unitIndex]}`;
|
||||
}
|
||||
|
||||
function createDetailItem(label, value) {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'detail-item';
|
||||
|
||||
Reference in New Issue
Block a user