From 922d335eda45269d53a23aa05fc2b644b4db47a0 Mon Sep 17 00:00:00 2001 From: "kiri.yang" Date: Wed, 18 Mar 2020 14:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0[=E4=B8=8D=E8=83=8C=E5=8D=95?= =?UTF-8?q?=E8=AF=8D]=E7=AD=BE=E5=88=B0=E4=BB=A5=E5=8F=8A=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E4=B8=80=E4=BA=9B=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bubei/README.md | 104 +++++++++++++++++++++++++++++++++++ bubei/bubei.js | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ zaker/zaker.js | 28 +++++----- 3 files changed, 260 insertions(+), 14 deletions(-) create mode 100644 bubei/README.md create mode 100644 bubei/bubei.js diff --git a/bubei/README.md b/bubei/README.md new file mode 100644 index 000000000..3e58d3ee2 --- /dev/null +++ b/bubei/README.md @@ -0,0 +1,104 @@ +# 不背单词 + +> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可 + +> 感谢[@danchaw](https://github.com/danchaw) PR +## 配置 (Surge) + +```properties +[MITM] +sapi.beingfine.cn + +[Script] +http-request ^https:\/\/sapi\.beingfine\.cn\/v3\/bb\/reward\/by-sign-in script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js +cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js +``` + +## 配置 (QuanX) + +```properties +[MITM] +sapi.beingfine.cn + +[rewrite_local] + +# [商店版] +^https:\/\/sapi\.beingfine\.cn\/v3\/bb\/reward\/by-sign-in url script-request-header bubei.js + +# [TestFlight] +^https:\/\/sapi\.beingfine\.cn\/v3\/bb\/reward\/by-sign-in url script-request-header https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js + +[task_local] + +# [商店版] +1 0 * * * bubei.js + +# [TestFlight] +1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/bubei/bubei.js +``` + +## 说明 + +1. 先把`sapi.beingfine.cn`加到`[MITM]` +2. 再配置重写规则: + - Surge: 把两条远程脚本放到`[Script]` + - QuanX: 把`bubei.js`传到`On My iPhone - Quantumult X - Scripts` (传到 iCloud 相同目录也可, 注意要打开 quanx 的 iCloud 开关) +3. 打开 APP[不背单词](https://apps.apple.com/cn/app/%E4%B8%8D%E8%83%8C%E5%8D%95%E8%AF%8D-%E7%9C%9F%E5%AE%9E%E8%AF%AD%E5%A2%83%E5%AD%A6%E8%8B%B1%E8%AF%AD%E5%8D%95%E8%AF%8D/id698570469) 然后手动签到 1 次, 系统提示: `首次写入不背单词Url成功🎉`和`首次写入不背单词Cookie成功🎉` +4. 最后就可以把第 1 条脚本注释掉了 +5. 运行一次脚本, 如果提示说明:aceess_denied#30103, 那就算成功了! + +> 第 1 条脚本是用来获取 cookie 的, 用浏览器访问一次获取 cookie 成功后就可以删掉或注释掉了, 但请确保在`登录成功`后再获取 cookie. + +> 第 2 条脚本是签到脚本, 每天`00:00:10`执行一次. + +## 常见问题 + +1. 无法写入 Cookie + + - 检查 Surge 系统通知权限放开了没 + - 如果你用的是 Safari, 请尝试在浏览地址栏`手动输入网址`(不要用复制粘贴) + +2. 写入 Cookie 成功, 但签到不成功 + + - 看看是不是在登录前就写入 Cookie 了 + - 如果是,请确保在登录成功后,再尝试写入 Cookie + +3. 为什么有时成功有时失败 + + - 很正常,网络问题,哪怕你是手工签到也可能失败(凌晨签到容易拥堵就容易失败) + - 暂时不考虑代码级的重试机制,但咱有配置级的(暴力美学): + + - `Surge`配置: + + ```properties + # 没有什么是一顿饭解决不了的: + cron "10 0 0 * * *" script-path=xxx.js # 每天00:00:10执行一次 + # 如果有,那就两顿: + cron "20 0 0 * * *" script-path=xxx.js # 每天00:00:20执行一次 + # 实在不行,三顿也能接受: + cron "30 0 0 * * *" script-path=xxx.js # 每天00:00:30执行一次 + + # 再粗暴点,直接: + cron "* */60 * * * *" script-path=xxx.js # 每60分执行一次 + ``` + + - `QuanX`配置: + + ```properties + [task_local] + 1 0 * * * xxx.js # 每天00:01执行一次 + 2 0 * * * xxx.js # 每天00:02执行一次 + 3 0 * * * xxx.js # 每天00:03执行一次 + + */60 * * * * xxx.js # 每60分执行一次 + ``` + +## 感谢 + +[@NobyDa](https://github.com/NobyDa) + +[@lhie1](https://github.com/lhie1) + +[@ConnersHua](https://github.com/ConnersHua) + +[@danchaw](https://github.com/danchaw) diff --git a/bubei/bubei.js b/bubei/bubei.js new file mode 100644 index 000000000..9dfe49f8d --- /dev/null +++ b/bubei/bubei.js @@ -0,0 +1,142 @@ +var appName = '不背单词' +var bubei = init() +var URL = bubei.getdata("UrlBB") +var KEY = bubei.getdata("CookieBB") + +let isGetCookie = typeof $request !== 'undefined' + +if (isGetCookie) { + getcookie() +} else { + sign() +} + +function getcookie() { + var url = $request.url; + if (url) { + var UrlKeyBB = "UrlBB"; + var UrlValueBB = url; + if (bubei.getdata(UrlKeyBB) != (undefined || null)) { + if (bubei.getdata(UrlKeyBB) != UrlValueBB) { + var url = bubei.setdata(UrlValueBB, UrlKeyBB); + if (!url) { + bubei.msg("更新" + appName + "Url失败‼️", "", ""); + } else { + bubei.msg("更新" + appName + "Url成功🎉", "", ""); + } + } else { + bubei.msg(appName + "Url未变化❗️", "", ""); + } + } else { + var url = bubei.setdata(UrlValueBB, UrlKeyBB); + if (!url) { + bubei.msg("首次写入" + appName + "Url失败‼️", "", ""); + } else { + bubei.msg("首次写入" + appName + "Url成功🎉", "", ""); + } + } + } else { + bubei.msg("写入" + appName + "Url失败‼️", "", "配置错误, 无法读取URL, "); + } + if ($request.headers) { + var CookieKeyBB = "CookieBB"; + var CookieValueBB = JSON.stringify($request.headers); + if (bubei.getdata(CookieKeyBB) != (undefined || null)) { + if (bubei.getdata(CookieKeyBB) != CookieValueBB) { + var cookie = bubei.setdata(CookieValueBB, CookieKeyBB); + if (!cookie) { + bubei.msg("更新" + appName + "Cookie失败‼️", "", ""); + } else { + bubei.msg("更新" + appName + "Cookie成功🎉", "", ""); + } + } else { + bubei.msg(appName + "Cookie未变化❗️", "", ""); + } + } else { + var cookie = bubei.setdata(CookieValueBB, CookieKeyBB); + if (!cookie) { + bubei.msg("首次写入" + appName + "Cookie失败‼️", "", ""); + } else { + bubei.msg("首次写入" + appName + "Cookie成功🎉", "", ""); + } + } + } else { + bubei.msg("写入" + appName + "Cookie失败‼️", "", "配置错误, 无法读取请求头, "); + } + bubei.done() +} + +function sign() { + var t1 = new Date().getTime() + var t2 = t1 + 1 + URL = URL.replace(/by-sign-in\/\d*/g,"by-sign-in/" + t1).replace(/timestamp=\d*/g,"timestamp=" + t2) + const url = { url: URL, headers: JSON.parse(KEY) } + bubei.get(url, (error, response, data) => { + bubei.log(`${appName}, data: ${data}`) + const title = `${appName}` + let subTitle = '' + let detail = '' + const result = JSON.parse(data) + if (result.result_code == 200) { + subTitle = `签到结果: 成功` + } else { + subTitle = `签到结果: 未知` + detail = `说明: ${result.error_body.user_msg}` + } + bubei.msg(title, subTitle, detail) + bubei.done() + }) +} + +function init() { + isSurge = () => { + return undefined === this.$httpClient ? false : true + } + isQuanX = () => { + return undefined === this.$task ? false : true + } + getdata = (key) => { + if (isSurge()) return $persistentStore.read(key) + if (isQuanX()) return $prefs.valueForKey(key) + } + setdata = (key, val) => { + if (isSurge()) return $persistentStore.write(key, val) + if (isQuanX()) return $prefs.setValueForKey(key, val) + } + msg = (title, subtitle, body) => { + if (isSurge()) $notification.post(title, subtitle, body) + if (isQuanX()) $notify(title, subtitle, body) + } + log = (message) => console.log(message) + get = (url, cb) => { + if (isSurge()) { + $httpClient.get(url, cb) + } + if (isQuanX()) { + url.method = 'GET' + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + } + } + post = (url, cb) => { + if (isSurge()) { + $httpClient.post(url, cb) + } + if (isQuanX()) { + url.method = 'POST' + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + } + } + put = (url, cb) => { + if (isSurge()) { + $httpClient.put(url, cb) + } + if (isQuanX()) { + url.method = 'PUT' + $task.fetch(url).then((resp) => cb(null, {}, resp.body)) + } + } + done = (value = {}) => { + $done(value) + } + return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done } +} \ No newline at end of file diff --git a/zaker/zaker.js b/zaker/zaker.js index 0ef3e35fd..c8c2a5b83 100644 --- a/zaker/zaker.js +++ b/zaker/zaker.js @@ -1,7 +1,7 @@ var appName = 'ZAKER新闻' var zaker = init() -var URL = zaker.getdata("Url") -var KEY = zaker.getdata("Cookie") +var URL = zaker.getdata("UrlZK") +var KEY = zaker.getdata("CookieZK") let isGetCookie = typeof $request !== 'undefined' @@ -14,11 +14,11 @@ if (isGetCookie) { function getcookie() { var url = $request.url; if (url) { - var UrlKey = "Url"; - var UrlValue = url; - if (zaker.getdata(UrlKey) != (undefined || null)) { - if (zaker.getdata(UrlKey) != UrlValue) { - var url = zaker.setdata(UrlValue, UrlKey); + var UrlKeyZK = "UrlZK"; + var UrlValueZK = url; + if (zaker.getdata(UrlKeyZK) != (undefined || null)) { + if (zaker.getdata(UrlKeyZK) != UrlValueZK) { + var url = zaker.setdata(UrlValueZK, UrlKeyZK); if (!url) { zaker.msg("更新" + appName + "Url失败‼️", "", ""); } else { @@ -28,7 +28,7 @@ function getcookie() { zaker.msg(appName + "Url未变化❗️", "", ""); } } else { - var url = zaker.setdata(UrlValue, UrlKey); + var url = zaker.setdata(UrlValueZK, UrlKeyZK); if (!url) { zaker.msg("首次写入" + appName + "Url失败‼️", "", ""); } else { @@ -39,11 +39,11 @@ function getcookie() { zaker.msg("写入" + appName + "Url失败‼️", "", "配置错误, 无法读取URL, "); } if ($request.headers) { - var CookieKey = "Cookie"; - var CookieValue = JSON.stringify($request.headers); - if (zaker.getdata(CookieKey) != (undefined || null)) { - if (zaker.getdata(CookieKey) != CookieValue) { - var cookie = zaker.setdata(CookieValue, CookieKey); + var CookieKeyZK = "CookieZK"; + var CookieValueZK = JSON.stringify($request.headers); + if (zaker.getdata(CookieKeyZK) != (undefined || null)) { + if (zaker.getdata(CookieKeyZK) != CookieValueZK) { + var cookie = zaker.setdata(CookieValueZK, CookieKeyZK); if (!cookie) { zaker.msg("更新" + appName + "Cookie失败‼️", "", ""); } else { @@ -53,7 +53,7 @@ function getcookie() { zaker.msg(appName + "Cookie未变化❗️", "", ""); } } else { - var cookie = zaker.setdata(CookieValue, CookieKey); + var cookie = zaker.setdata(CookieValueZK, CookieKeyZK); if (!cookie) { zaker.msg("首次写入" + appName + "Cookie失败‼️", "", ""); } else {