-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarsnap.js
More file actions
34 lines (31 loc) · 952 Bytes
/
tarsnap.js
File metadata and controls
34 lines (31 loc) · 952 Bytes
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
// ==UserScript==
// @name Tarsnap Human Readable
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Tarsnap Human Readable
// @author You
// @match https://www.tarsnap.com/manage.cgi*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function convert(value) {
const units = ['o', 'Kio', 'Mio', 'Gio', 'Tio'];
const values = value.split(" ");
if (!values || values.length !== 2 || values[1] !== 'bytes') {
return value;
}
var bValue = values[0];
var unitIdx = 0;
while (bValue >= 1000) {
bValue = bValue / 1024;
unitIdx += 1;
}
return bValue.toFixed(2) + ' ' + units[unitIdx];
}
for(let num of document.querySelectorAll("td")) {
if (num.textContent.includes(' bytes')) {
num.textContent = convert(num.textContent);
}
}
})();