Script/Bilibili-DailyBonus/Manga.js

107 lines
12 KiB
JavaScript
Raw Normal View History

/*
2020-08-29 22:26:49 +08:00
哔哩哔哩漫画签到
2024-03-18 19:42:17 +08:00
脚本兼容QuantumultX, Surge, Loon
2020-08-29 22:26:49 +08:00
电报频道@NobyDa
问题反馈@NobyDa_bot
2024-03-18 19:42:17 +08:00
更新日期2024/03/18
2020-08-29 22:26:49 +08:00
如果转载请注明出处
2020-08-29 22:26:49 +08:00
说明
打开哔哩哔哩漫画后 (AppStore中国区)单击"我的", 如果通知获取cookie成功, 则可以使用此脚本.
2020-08-29 22:26:49 +08:00
脚本将在每天上午9点执行 您可以修改执行时间
~~~~~~~~~~~~~~~~
2020-08-29 22:26:49 +08:00
Surge 4.2.0+ :
[Script]
2020-08-29 22:26:49 +08:00
Bili漫画签到 = type=cron,cronexp=0 9 * * *,wake-system=1,script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Bilibili-DailyBonus/Manga.js
2021-09-22 23:55:44 +08:00
Bili漫画Cookie = type=http-request,pattern=^https:\/\/app\.bilibili\.com\/x\/v2\/account\/myinfo,script-path=https://raw.githubusercontent.com/NobyDa/Script/master/Bilibili-DailyBonus/Manga.js
2020-08-29 22:26:49 +08:00
[MITM]
2021-09-22 23:55:44 +08:00
hostname = app.bilibili.com
~~~~~~~~~~~~~~~~
2020-08-29 22:26:49 +08:00
QX 1.0.10+ :
[task_local]
2020-08-29 22:26:49 +08:00
0 9 * * * https://raw.githubusercontent.com/NobyDa/Script/master/Bilibili-DailyBonus/Manga.js, tag=Bili漫画签到
[rewrite_local]
2020-08-29 22:26:49 +08:00
#获取Bili漫画Cookie
2021-09-22 23:55:44 +08:00
^https:\/\/app\.bilibili\.com\/x\/v2\/account\/myinfo url script-request-header https://raw.githubusercontent.com/NobyDa/Script/master/Bilibili-DailyBonus/Manga.js
2020-08-29 22:26:49 +08:00
[mitm]
2021-09-22 23:55:44 +08:00
hostname = app.bilibili.com
2020-08-29 22:26:49 +08:00
~~~~~~~~~~~~~~~~
*/
2021-09-22 23:55:44 +08:00
const $ = new Env(`哔哩哔哩漫画`);
2021-09-22 23:55:44 +08:00
const cookie = $.getdata("CookieBM") || ''; // 哔哩哔哩漫画Cookie
2021-09-22 23:55:44 +08:00
const barkKey = ''; //Bark APP 通知推送Key
if (typeof $request !== 'undefined') {
2023-04-04 23:54:51 +08:00
GetCookie(cookie)
} else if (!cookie) {
$.msg($.name, ``, `签到Cookie失效/未获取 ⚠️`);
$.done();
} else {
checkin()
}
function checkin() {
const bilibili = {
url: 'https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn',
headers: {
2021-09-22 23:55:44 +08:00
Cookie: cookie,
2023-04-04 23:54:51 +08:00
"User-Agent": "comic-universal/1552 CFNetwork/1406.0.4 Darwin/22.4.0 os/ios model/iPhone 12 mobi_app/iphone_comic build/1552 osVer/16.4 network/2 channel/AppStore"
},
body: "platform=ios"
};
2023-04-04 23:54:51 +08:00
$.post(bilibili, async function (error, response, data) {
2021-09-22 23:55:44 +08:00
if (error && !data) {
$.msgBody = `请求失败!\n${error}`;
2024-03-18 19:42:17 +08:00
} else if (data.includes(`"code":0`)) {
2021-09-22 23:55:44 +08:00
$.msgBody = "签到成功!🎉";
2024-03-18 19:42:17 +08:00
} else if (data.includes(`"code":1`)) {
2023-04-04 23:54:51 +08:00
$.msgBody = "签到失败,今日已签过 ⚠️";
2024-03-18 19:42:17 +08:00
} else if (data.includes(`"invalid_argument"`)) {
2023-04-04 23:54:51 +08:00
$.msgBody = "签到失败Cookie失效已清除 ⚠️";
$.setdata("", "CookieBM");
} else {
2021-09-22 23:55:44 +08:00
$.msgBody = `签到失败 ‼️\n${data}`;
}
if (barkKey) {
await BarkNotify($, barkKey, $.name, $.msgBody);
}
2021-09-22 23:55:44 +08:00
$.msg($.name, ``, $.msgBody);
$.done();
})
}
2023-04-04 23:54:51 +08:00
function GetCookie(oldCookie) {
const req = JSON.stringify($request);
if (!req.includes(`_comic`)) {
$.log($.name, `${$.name}客户端URL请求跳过脚本 ⚠️`);
} else if (!req.includes(`SESSDATA=`)) {
$.msg($.name, ``, `获取Cookie失败关键值缺失 ⚠️`);
} else {
const cookieValue = req.split(/(SESSDATA=.+?;)/)[1];
const setCookie = $.setdata(cookieValue, `CookieBM`);
if (oldCookie) {
$.log($.name, `更新Cookie${setCookie ? `成功 🎉` : `失败 ⚠️`}`);
} else {
2023-04-04 23:54:51 +08:00
$.msg($.name, ``, `获取Cookie${setCookie ? `成功 🎉` : `失败 ⚠️`}`);
}
}
2021-09-22 23:55:44 +08:00
$.done()
}
2021-09-22 23:55:44 +08:00
//Bark APP notify
2023-04-04 23:54:51 +08:00
async function BarkNotify(c, k, t, b) { for (let i = 0; i < 3; i++) { console.log(`🔷Bark notify >> Start push (${i + 1})`); const s = await new Promise((n) => { c.post({ url: 'https://api.day.app/push', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: t, body: b, device_key: k, ext_params: { group: t } }) }, (e, r, d) => r && r.status == 200 ? n(1) : n(d || e)) }); if (s === 1) { console.log('✅Push success!'); break } else { console.log(`❌Push failed! >> ${s.message || s}`) } } };
2021-09-22 23:55:44 +08:00
// https://github.com/chavyleung/scripts/blob/master/Env.min.js
2023-04-04 23:54:51 +08:00
function Env(t, e) { class s { constructor(t) { this.env = t } send(t, e = "GET") { t = "string" == typeof t ? { url: t } : t; let s = this.get; return "POST" === e && (s = this.post), new Promise((e, i) => { s.call(this, t, (t, s, r) => { t ? i(t) : e(s) }) }) } get(t) { return this.send.call(this.env, t) } post(t) { return this.send.call(this.env, t, "POST") } } return new class { constructor(t, e) { this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `\ud83d\udd14${this.name}, \u5f00\u59cb!`) } isNode() { return "undefined" != typeof module && !!module.exports } isQuanX() { return "undefined" != typeof $task } isSurge() { return "undefined" != typeof $httpClient && "undefined" == typeof $loon } isLoon() { return "undefined" != typeof $loon } toObj(t, e = null) { try { return JSON.parse(t) } catch { return e } } toStr(t, e = null) { try { return JSON.stringify(t) } catch { return e } } getjson(t, e) { let s = e; const i = this.getdata(t); if (i) try { s = JSON.parse(this.getdata(t)) } catch { } return s } setjson(t, e) { try { return this.setdata(JSON.stringify(t), e) } catch { return !1 } } getScript(t) { return new Promise(e => { this.get({ url: t }, (t, s, i) => e(i)) }) } runScript(t, e) { return new Promise(s => { let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); i = i ? i.replace(/\n/g, "").trim() : i; let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; const [o, h] = i.split("@"), a = { url: `http://${h}/v1/scripting/evaluate`, body: { script_text: t, mock_type: "cron", timeout: r }, headers: { "X-Key": o, Accept: "*/*" } }; this.post(a, (t, e, i) => s(i)) }).catch(t => this.logErr(t)) } loaddata() { if (!this.isNode()) return {}; { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); if (!s && !i) return {}; { const i = s ? t : e; try { return JSON.parse(this.fs.readFileSync(i)) } catch (t) { return {} } } } } writedata() { if (this.isNode()) { this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) } } lodash_get(t, e, s) { const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); let r = t; for (const t of i) if (r = Object(r)[t], void 0 === r) return s; return r } lodash_set(t, e, s) { return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) } getdata(t) { let e = this.getval(t); if (/^@/.test(t)) { const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; if (r) try { const t = JSON.parse(r); e = t ? this.lodash_get(t, i, "") : e } catch (t) { e = "" } } return e } setdata(t, e) { let s = !1; if (/^@/.test(e)) { const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), h = i ? "null" === o ? null : o || "{}" : "{}"; try { const e = JSON.parse(h); this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) } catch (e) { const o = {}; this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) } } else s = this.setval(t, e); return s } getval(t) { return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? (this.data = this.loaddata(), this.data[t]) : this.data && this.data[t] || null } setval(t, e) { return this.isSurge() || this.isLoon() ? $persistentStore.