2018-05-12 16:34:19 +00:00
|
|
|
/* global LazyLoad */
|
|
|
|
|
2018-10-11 19:24:41 +00:00
|
|
|
const page = {
|
2018-10-11 19:21:19 +00:00
|
|
|
lazyLoad: null,
|
|
|
|
|
|
|
|
// byte units for getPrettyBytes()
|
|
|
|
byteUnits: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
|
|
}
|
|
|
|
|
|
|
|
page.getPrettyBytes = num => {
|
|
|
|
// MIT License
|
|
|
|
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
2018-12-13 09:09:46 +00:00
|
|
|
|
2018-12-18 17:01:28 +00:00
|
|
|
if (!Number.isFinite(num)) return num
|
2018-10-11 19:21:19 +00:00
|
|
|
|
2018-10-11 19:24:41 +00:00
|
|
|
const neg = num < 0
|
2018-12-18 17:01:28 +00:00
|
|
|
if (neg) num = -num
|
|
|
|
if (num < 1) return (neg ? '-' : '') + num + ' B'
|
2018-10-11 19:21:19 +00:00
|
|
|
|
2018-10-11 19:24:41 +00:00
|
|
|
const exponent = Math.min(Math.floor(Math.log10(num) / 3), page.byteUnits.length - 1)
|
|
|
|
const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3))
|
|
|
|
const unit = page.byteUnits[exponent]
|
2018-10-11 19:21:19 +00:00
|
|
|
|
|
|
|
return (neg ? '-' : '') + numStr + ' ' + unit
|
|
|
|
}
|
2018-05-12 16:34:19 +00:00
|
|
|
|
2018-07-14 03:42:18 +00:00
|
|
|
window.onload = function () {
|
2018-10-11 19:24:41 +00:00
|
|
|
const elements = document.getElementsByClassName('file-size')
|
2018-12-18 17:01:28 +00:00
|
|
|
for (let i = 0; i < elements.length; i++)
|
2018-10-11 19:21:19 +00:00
|
|
|
elements[i].innerHTML = page.getPrettyBytes(parseInt(elements[i].innerHTML))
|
|
|
|
|
2018-05-12 16:34:19 +00:00
|
|
|
page.lazyLoad = new LazyLoad()
|
|
|
|
}
|