Skip to content

Instantly share code, notes, and snippets.

@ZE3kr
Last active December 7, 2021 07:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZE3kr/045168c6f27f6effcf733e6ee45967db to your computer and use it in GitHub Desktop.
Save ZE3kr/045168c6f27f6effcf733e6ee45967db to your computer and use it in GitHub Desktop.
Surge 少数派流量监控模块
#!name=少数派流量监控
#!desc=实时查询还剩多少流量
#!system=ios
[Panel]
ssp_bandwidth_check = script-name=ssp_bandwidth_check, title="少数派流量监控", update-interval=300
[Script]
ssp_bandwidth_check = type=generic, script-path=PASTE_YOUR_SCRIPT_PATH_HERE
const USER_NAME = `name@example.com`
const PASSWORD = `123456`
let cookie = {}
const json = $persistentStore.read('ssp')
if (json) {
cookie = JSON.parse(json)
}
let { value, expires } = cookie
if (!cookie || !expires || expires < +Date.now()) {
console.log('Cookie expires')
$httpClient.post({
url: 'https://ssp-net.me/api/v1/passport/auth/login',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
body: 'email=' + encodeURIComponent(USER_NAME) + '&password=' + encodeURIComponent(PASSWORD)
}, function (error, response) {
if (!error) {
value = response.headers['Set-Cookie'].split(';')[0]
$persistentStore.write('ssp', JSON.stringify({ value, expires: Date.now() + 7_200_000 }))
getUsage()
}
})
} else {
getUsage()
}
function getUsage() {
$httpClient.get({
'url': 'https://ssp-net.me/api/v1/user/getSubscribe',
headers: { cookie: value }
}, function (error, response, data) {
if (!error) {
const usage = JSON.parse(data)
const used = usage?.data?.u + usage?.data?.d
const total = usage?.data?.transfer_enable
const days = usage?.data?.reset_day
const percentage = 100 * used / total
const remain_days = Math.floor((usage?.data?.expired_at - Date.now() / 1000) / 86400)
const style = percentage < 60 ? 'good' : percentage < 90 ? 'alert' : 'error';
const content = remain_days > days + 1 ? `${days} 日后重置流量` : `${remain_days} 日后订阅到期`;
const title = `少数派 ${(used / (1<<30)).toFixed(2)} / ${(total / (1<<30)).toFixed(0)} GB`
$done({ title, content, style });
}
})
}

Surge 少数派流量监控模块

使用方法:

  1. 新建一个 Gist,复制 0_ssp.sgmodule1_ssp.js 文件内容
  2. 修改 USER_NAMEPASSWORD 变量,然后点击 Create secret gist(请不要 fork,因为 fork 后只能是 public gist)
  3. 创建成功后拷贝 1_ssp.js 的 raw 地址,并替换 0_ssp.sgmodule 中的 PASTE_YOUR_SCRIPT_PATH_HERE 为拷贝的地址
  4. 拷贝 0_ssp.sgmodule 的 raw 地址作为 Surge Module 使用
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment