Skip to content

Commit fc7f2ad

Browse files
committed
Added sub-store data query scripts.
1 parent 11be941 commit fc7f2ad

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Sub-store-parser/DataQuery.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/******************************
2+
3+
Sub-Store外置流量查询脚本
4+
5+
该脚本基于Sub-Store, 可解决APP使用Sub-Store链接后, 没有流量通知的问题. 使用前需确认您的机场订阅是否支持流量信息.
6+
Sub-Store订阅管理器: https://github.com/Peng-YM/Sub-Store
7+
8+
测试兼容: QuantumultX, Surge, Loon.
9+
使用方法: 打开Sub-Store => 订阅 => 编辑 => 节点操作+ => 脚本操作 => 填入脚本链接或粘贴脚本 => 保存
10+
11+
您的APP更新Sub-Store订阅链接时, 将自动发送流量通知.
12+
13+
脚本链接: https://raw.githubusercontent.com/NobyDa/Script/master/Sub-store-parser/DataQuery.js
14+
15+
******************************/
16+
17+
function operator(proxies) {
18+
try {
19+
if ($request.headers["User-Agent"].match(/Quant|Surge|Loon|Decar/)) {
20+
function AllSubs(subsUrl, subsName) {
21+
$.http.get(subsUrl).then(resp => {
22+
try { //reference to https://github.com/KOP-XIAO/QuantumultX/blob/master/Scripts/resource-parser.js
23+
var sinfo = JSON.stringify(resp.headers).replace(/ /g, "").toLowerCase();
24+
var total = (parseFloat(sinfo.split("total=")[1].split(",")[0]) / (1024 ** 3)).toFixed(0);
25+
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);
26+
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);
27+
if (sinfo.indexOf("expire=") != -1) {
28+
var epr = new Date(parseFloat(sinfo.split("expire=")[1].split(",")[0]) * 1000);
29+
var year = epr.getFullYear();
30+
var mth = epr.getMonth() + 1 < 10 ? '0' + (epr.getMonth() + 1) : (epr.getMonth() + 1);
31+
var day = epr.getDate() < 10 ? "0" + (epr.getDate()) : epr.getDate();
32+
var epr = `🔹 过期时间:「 ${year}-${mth}-${day} 」`
33+
} else {
34+
var epr = "";
35+
}
36+
$.notify(`🔹 订阅昵称:「 ${subsName} 」`, epr, `🔸 已用流量:「 ${usd} GB 」\n🔸 剩余流量:「 ${left} GB 」`)
37+
} catch (errInfo) {
38+
console.log(`\n🔹 订阅昵称:「 ${subsName} 」\n🔺 查询失败: ${errInfo}`)
39+
}
40+
}, er => $.notify(`🔹 订阅昵称:「 ${subsName} 」`, ``, `🔺 查询失败: ${er}`))
41+
}
42+
const subtag = $request.url.match(/download\/(collection\/)?([\w-_]*)/)[2]
43+
const rawInfo = $.read('subs')
44+
if ($request.url.match(/\/collection\//)) {
45+
const readName = $.read('collections')
46+
for (var i = 0; i < readName[subtag].subscriptions.length; i++) {
47+
const rawUrl = rawInfo[readName[subtag].subscriptions[i]].url;
48+
const rawName = readName[subtag].subscriptions[i];
49+
AllSubs(rawUrl, rawName);
50+
}
51+
} else {
52+
AllSubs(rawInfo[subtag].url, rawInfo[subtag].name);
53+
}
54+
}
55+
} catch (err) {
56+
console.log(`\n🔺 查询失败: \n${err.message}`)
57+
} finally {
58+
return proxies
59+
}
60+
}

0 commit comments

Comments
 (0)