Skip to content

Instantly share code, notes, and snippets.

@quericy
Created March 18, 2020 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quericy/38887c294fb4174f83bd395c93a93a4f to your computer and use it in GitHub Desktop.
Save quericy/38887c294fb4174f83bd395c93a93a4f to your computer and use it in GitHub Desktop.
surgio 流量统计(QuantumultX定时脚本)
/**
* @fileoverview check surgio traffic
* @version 1.0.0
* @supported Quantumult X (v1.0.5-build166)
*/
// add in QuantumultX config:
// [task_local]
// 0 5 */12 * * checkin_surgio_traffic.js
var domain = "替换为你的部署域名"
var accessToken = "替换为你的访问授权"
var providerList = [
"替换为你的provider名称",
//"可添加更多的provider名称",
]
// run script
function launch() {
for (var i in providerList) {
let providerName = providerList[i]
query_traffic(providerName, domain, accessToken)
}
}
launch();
function query_traffic(providerName, domain, accessToken) {
var api = "https://" + domain + "/api/providers/" + providerName + "/subscription?access_token=" + accessToken;
var method = "GET";
var myRequest = {
url: api,
method: method,
//headers: headers,
//body: JSON.stringify(data)
};
$task.fetch(myRequest).then(response => {
var obj = JSON.parse(response.body);
var status = obj.status;
var data = obj.data;
if (status != 'ok') { // 接口状态码异常
$notify("❕流量统计", "获取失败", status); // Wrong!
} else {
$notify("❕流量统计", "服务提供者:" + providerName, "已用:" + data.used + " " + "剩余:" + data.left + "\n" + "总计:" + data.total + " " + "有效期:" + data.expire); // Success!
}
}, reason => {
// reason.error
$notify("❕流量统计", "获取失败", reason.error); // Error!
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment