Skip to content

Commit 62e8713

Browse files
authored
Add files via upload
1 parent c98e06e commit 62e8713

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

bilibili/bilibili.silver2coin.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Bilibili silver to coin
3+
by Telegram@naindy forked from @chavyleung
4+
Compatible with chavyleung's bilibili.cookie.js
5+
6+
Cookie-Rewrite & MiTM use this https://github.com/chavyleung/scripts/tree/master/bilibili
7+
8+
Surge:
9+
[Script]
10+
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js
11+
12+
QuanX:
13+
[task_local]
14+
1 0 * * * bilibili.silver2coin.js
15+
16+
*/
17+
const cookieName = 'bilibili'
18+
const cookieKey = 'chavy_cookie_bilibili'
19+
const chavy = init()
20+
const cookieVal = chavy.getdata(cookieKey)
21+
22+
sign()
23+
24+
function sign() {
25+
let url = {
26+
url: `https://api.live.bilibili.com/pay/v1/Exchange/silver2coin`,
27+
headers: {
28+
Cookie: cookieVal
29+
}
30+
}
31+
url.headers['Origin'] = 'api.live.bilibili.com'
32+
url.headers['Referer'] = 'http://live.bilibili.com/'
33+
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
34+
url.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'
35+
36+
chavy.get(url, (error, response, data) => {
37+
// {"code":403,"msg":"银瓜子余额不足","message":"银瓜子余额不足","data":[]}
38+
// {"code":403,"msg":"每天最多能兑换 1 个","message":"每天最多能兑换 1 个","data":[]}
39+
// {"code":0,"msg":"兑换成功","message":"兑换成功","data":{"gold":"0","silver":"200","tid":"****","coin":1}}
40+
// {"code":401,"msg":"请登录","message":"请登录","data":[]}
41+
let result = JSON.parse(data)
42+
let title = `${cookieName} silver to coin`
43+
// 签到成功
44+
if (result && result.code == 0) {
45+
let subTitle = `${result.message}`
46+
let detail = `成功兑换: ${result.data.coin} 个硬币\n当前银瓜子: ${result.data.silver} , 当前金瓜子: ${result.data.gold}`
47+
chavy.msg(title, subTitle, detail)
48+
}
49+
// 签到重复
50+
else if (result && result.code == 403) {
51+
let subTitle = `未成功兑换`
52+
let detail = `${result.message}`
53+
chavy.msg(title, subTitle, detail)
54+
}
55+
// 签到失败
56+
else {
57+
let subTitle = `兑换失败`
58+
let detail = `说明: ${result.message}`
59+
chavy.msg(title, subTitle, detail)
60+
}
61+
chavy.log(`${cookieName}, data: ${data}`)
62+
})
63+
64+
chavy.done()
65+
}
66+
function init() {
67+
isSurge = () => {
68+
return undefined === this.$httpClient ? false : true
69+
}
70+
isQuanX = () => {
71+
return undefined === this.$task ? false : true
72+
}
73+
getdata = (key) => {
74+
if (isSurge()) return $persistentStore.read(key)
75+
if (isQuanX()) return $prefs.valueForKey(key)
76+
}
77+
setdata = (key, val) => {
78+
if (isSurge()) return $persistentStore.write(key, val)
79+
if (isQuanX()) return $prefs.setValueForKey(key, val)
80+
}
81+
msg = (title, subtitle, body) => {
82+
if (isSurge()) $notification.post(title, subtitle, body)
83+
if (isQuanX()) $notify(title, subtitle, body)
84+
}
85+
log = (message) => console.log(message)
86+
get = (url, cb) => {
87+
if (isSurge()) {
88+
$httpClient.get(url, cb)
89+
}
90+
if (isQuanX()) {
91+
url.method = 'GET'
92+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
93+
}
94+
}
95+
post = (url, cb) => {
96+
if (isSurge()) {
97+
$httpClient.post(url, cb)
98+
}
99+
if (isQuanX()) {
100+
url.method = 'POST'
101+
$task.fetch(url).then((resp) => cb(null, {}, resp.body))
102+
}
103+
}
104+
done = (value = {}) => {
105+
$done(value)
106+
}
107+
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
108+
}

0 commit comments

Comments
 (0)