-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbettersizes.user.js
76 lines (74 loc) · 1.98 KB
/
bettersizes.user.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
// ==UserScript==
// @name Better sizes
// @namespace https://volafile.org/
// @icon https://volafile.org/favicon.ico
// @version 1
// @description Because lain
// @author Me
// @match https://volafile.org/*
// @run-at document-idle
// @grant none
// ==/UserScript==
(function() {
'use strict';
var prettySize = (function(uselocale) {
function toLocaleStringSupportsLocales() {
var number = 0;
try {
number.toLocaleString('i');
} catch (e) {
return e.name === 'RangeError';
}
return false;
}
var fixer = uselocale && toLocaleStringSupportsLocales() ?
function (digits) {
return this.toLocaleString(undefined, {
minimumFractionDigits: digits,
maximumFractionDigits: digits,
useGrouping: false
});
} :
Number.prototype.toFixed;
var units = [
' B',
' KB',
' MB',
' GB',
' TB',
' PB',
' EB',
' MercoByte'
];
return function prettySize(n) {
var o = 0, f = 0, u;
while (n > 1024) {
n /= 1024;
++o;
}
if (!o) {
return n.toFixed(0) + ' B';
}
u = units[o];
if (n < 10) {
f = 2;
}
else if (n < 100) {
f = 1;
}
if (o > 3) {
// large size force multiplier: adds +3cp
++f;
}
return fixer.call(n, f) + units[o];
};
})(false);
function DOET() {
if (window.format && window.format.prettySize) {
window.format.prettySize = prettySize;
return;
}
setTimeout(DOET, 0);
}
DOET();
})();