MCPcopy Create free account
hub / github.com/NobyDa/Script / parseInfo

Function parseInfo

Sub-store-parser/DataQuery.js:51–66  ·  view source on GitHub ↗
(resp)

Source from the content-addressed store, hash-verified

49}
50
51function parseInfo(resp) { //reference to https://github.com/KOP-XIAO/QuantumultX/blob/master/Scripts/resource-parser.js
52 var sinfo = JSON.stringify(resp.headers || '').replace(/ /g, "").toLowerCase();
53 if (sinfo.indexOf("total=") == -1 && sinfo.indexOf("download=") == -1)
54 throw new Error('该订阅不包含流量信息');
55 // var total = (parseFloat(sinfo.split("total=")[1].split(",")[0]) / (1024 ** 3)).toFixed(0);
56 var usd = ((parseFloat(sinfo.indexOf("upload") != -1 ? sinfo.split("upload=")[1].split(",")[0] : "0") + parseFloat(sinfo.split("download=")[1].split(",")[0])) / (1024 ** 3)).toFixed(2);
57 var left = ((parseFloat(sinfo.split("total=")[1].split(",")[0]) / (1024 ** 3)) - ((parseFloat(sinfo.indexOf("upload") != -1 ? sinfo.split("upload=")[1].split(",")[0] : "0") + parseFloat(sinfo.split("download=")[1].split(",")[0])) / (1024 ** 3))).toFixed(2);
58 if (sinfo.indexOf("expire=") != -1) {
59 var epr = new Date(parseFloat(sinfo.split("expire=")[1].split(",")[0]) * 1000);
60 var year = epr.getFullYear();
61 var mth = epr.getMonth() + 1 < 10 ? '0' + (epr.getMonth() + 1) : (epr.getMonth() + 1);
62 var day = epr.getDate() < 10 ? "0" + (epr.getDate()) : epr.getDate();
63 return { expire: `${year}-${mth}-${day}`, used: usd, free: left }
64 }
65 return { used: usd, free: left }
66}

Callers 1

operatorFunction · 0.85

Calls 1

stringifyMethod · 0.45

Tested by

no test coverage detected