2018-05-12 16:34:19 +00:00
|
|
|
/* global LazyLoad */
|
|
|
|
|
2018-10-11 19:24:41 +00:00
|
|
|
const page = {
|
2019-01-04 21:34:54 +00:00
|
|
|
lazyLoad: null
|
2018-10-11 19:21:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 21:34:54 +00:00
|
|
|
page.getPrettyBytes = function (num, si) {
|
2018-10-11 19:21:19 +00:00
|
|
|
// MIT License
|
|
|
|
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
2018-12-18 17:01:28 +00:00
|
|
|
if (!Number.isFinite(num)) return num
|
2018-10-11 19:21:19 +00:00
|
|
|
|
2019-01-04 21:34:54 +00:00
|
|
|
const neg = num < 0 ? '-' : ''
|
2019-01-14 13:06:57 +00:00
|
|
|
const scale = si ? 1000 : 1024
|
2018-12-18 17:01:28 +00:00
|
|
|
if (neg) num = -num
|
2019-01-14 13:06:57 +00:00
|
|
|
if (num < scale) return `${neg}${num} B`
|
2018-10-11 19:21:19 +00:00
|
|
|
|
2019-01-04 21:34:54 +00:00
|
|
|
const exponent = Math.min(Math.floor(Math.log10(num) / 3), 8) // 8 is count of KMGTPEZY
|
2019-01-14 13:06:57 +00:00
|
|
|
const numStr = Number((num / Math.pow(scale, exponent)).toPrecision(3))
|
2019-01-04 21:34:54 +00:00
|
|
|
const pre = (si ? 'kMGTPEZY' : 'KMGTPEZY').charAt(exponent - 1) + (si ? '' : 'i')
|
|
|
|
return `${neg}${numStr} ${pre}B`
|
2018-10-11 19:21:19 +00:00
|
|
|
}
|
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()
|
|
|
|
}
|