Files
qx/js/pingme_capture.js
T

96 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* PingMe CK 抓取 - Quantumult X Rewrite
*
* 订阅地址:
* https://gitea.chickliu.fun/Hermes/qx/raw/branch/main/conf/pingme.conf
*
* 输出格式严格对齐当前 NiuPanel 正确 CK
* {"url":"https://api.pingmeapp.com/app/queryBalanceAndBonus?...","headers":{...}}
*
* 兼容 api.pingmeapp.com 与 api.pingmeapp.net。
* 注意:pingme_multi.js 会从 url 自行解析查询参数并重算 sign,正确 CK 不需要 paramsRaw。
* 安全:不上传 CK,不请求第三方;仅在 QX 本地保存最近一次抓取结果。
*/
const SCRIPT_NAME = 'PingMe'
function notify(subtitle, message) {
$notify(SCRIPT_NAME, subtitle || '', message || '')
}
function done() {
$done({})
}
function setPref(key, value) {
try { return $prefs.setValueForKey(String(value), key) } catch (e) { return false }
}
function getHeader(headers, name) {
const lower = String(name).toLowerCase()
for (const k in (headers || {})) {
if (String(k).toLowerCase() === lower) return headers[k]
}
return ''
}
function hasQuery(url) {
return String(url || '').indexOf('?') >= 0 && String(url || '').split('?')[1].length > 0
}
function buildHeaders(headers, sourceUrl) {
// 严格按现有正确 pingme_ck.json 的 header 形状输出。
// 保留 Host/Connection/Accept-Encoding,因为当前正确 CK 就是这个集合;
// pingme_multi.js 后续会覆盖 Host 与 Accept-Encoding,不会影响执行。
const ordered = ['Host', 'Connection', 'Accept', 'User-Agent', 'Accept-Language', 'Accept-Encoding']
const out = {}
ordered.forEach(name => {
const v = getHeader(headers, name)
if (v !== undefined && v !== null && String(v) !== '') out[name] = String(v)
})
if (!out.Host) {
const m = String(sourceUrl || '').match(/^https?:\/\/([^/]+)/i)
out.Host = m ? m[1] : 'api.pingmeapp.com'
}
if (!out.Accept) out.Accept = '*/*'
return out
}
function buildRecord(req) {
return {
url: String(req.url || ''),
headers: buildHeaders(req.headers || {}, req.url)
}
}
function main() {
const req = typeof $request !== 'undefined' ? $request : null
if (!req || !req.url) {
notify('抓取失败', '没有 request 上下文')
return done()
}
const url = String(req.url || '')
if (!/^https?:\/\/api\.pingmeapp\.(?:net|com)\/app\/queryBalanceAndBonus(?:\?|$)/.test(url)) {
notify('等待正确接口', '请打开 PingMe 触发 queryBalanceAndBonus 接口')
return done()
}
if (!hasQuery(url)) {
notify('抓取失败', 'queryBalanceAndBonus 请求缺少查询参数')
return done()
}
const record = buildRecord(req)
const text = JSON.stringify(record)
setPref('pingme_ck_last', text)
notify('CK 获取成功', text)
done()
}
try {
main()
} catch (e) {
notify('脚本异常', String(e && e.message || e).slice(0, 220))
done()
}