fix account network usage
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
0f149ba5c7
commit
2bb73ce828
@ -2,13 +2,22 @@ import {requestAPI, goToPage, getCookie, setTitleAndHeader} from "./utils.js";
|
||||
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
let SIPrefix = [
|
||||
let prefixes = {
|
||||
1024: [
|
||||
"",
|
||||
"Ki",
|
||||
"Mi",
|
||||
"Gi",
|
||||
"Ti"
|
||||
],
|
||||
1000: [
|
||||
"",
|
||||
"K",
|
||||
"M",
|
||||
"G",
|
||||
"T"
|
||||
]
|
||||
}
|
||||
|
||||
async function init() {
|
||||
setTitleAndHeader();
|
||||
@ -48,15 +57,16 @@ function buildResourceTable (resources, tableid) {
|
||||
function parseNumber(value, unitData) {
|
||||
let compact = unitData.compact;
|
||||
let multiplier = unitData.multiplier;
|
||||
let base = unitData.base;
|
||||
let unit = unitData.unit;
|
||||
value = multiplier * value;
|
||||
if (value <= 0) {
|
||||
return `0 ${unit}`;
|
||||
}
|
||||
else if (compact) {
|
||||
let exponent = Math.floor(Math.log2(value) / 10);
|
||||
value = value / 1024 ** exponent;
|
||||
let unitPrefix = SIPrefix[exponent];
|
||||
let exponent = Math.floor(Math.log(value) / Math.log(base));
|
||||
value = value / base ** exponent;
|
||||
let unitPrefix = prefixes[base][exponent];
|
||||
return `${value} ${unitPrefix}${unit}`
|
||||
}
|
||||
else {
|
||||
|
@ -442,17 +442,17 @@ function populateNetworks () {
|
||||
});
|
||||
let ordered_keys = getOrdered(networks);
|
||||
ordered_keys.forEach(element => {
|
||||
addNetworkLine("networks", `${prefix}${element}`, networks[element]);
|
||||
addNetworkLine("networks", prefix, element, networks[element]);
|
||||
});
|
||||
}
|
||||
|
||||
function addNetworkLine (fieldset, netID, netDetails) {
|
||||
function addNetworkLine (fieldset, prefix, netID, netDetails) {
|
||||
let field = document.querySelector(`#${fieldset}`);
|
||||
|
||||
let icon = document.createElement("img");
|
||||
icon.src = "images/resources/network.svg";
|
||||
icon.alt = netID;
|
||||
icon.dataset.network = netID;
|
||||
icon.dataset.network = `${prefix}${netID}`;
|
||||
icon.dataset.netvals = netDetails;
|
||||
field.appendChild(icon);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user