Skip to content

Commit

Permalink
Merge pull request chavyleung#79 from lcandy2/master
Browse files Browse the repository at this point in the history
更新[哔哩哔哩]: 增加银瓜子兑换硬币脚本
  • Loading branch information
gideonsenku authored Mar 16, 2020
2 parents bbb7928 + 4fba31f commit 4973659
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
4 changes: 3 additions & 1 deletion QuantumultX_Local_Task.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
10 0 * * * chavyleung/apktw/apktw.js
# bilibili
2 0 * * * chavyleung/bilibili/bilibili.js
# bilibili 如需银瓜子转硬币,添加下方内容
1 0 * * * chavyleung/bilibili/bilibili.silver2coin.js
# 懂球帝
4 0 * * * chavyleung/dongqiudi/dongqiudi.js
# 威锋网
Expand Down Expand Up @@ -84,4 +86,4 @@
#智行火车
1 0 * * * chavyleung/zxhc/zxhc.js
# 苏宁易购
7 0 * * * chavyleung/suning/suning.js
7 0 * * * chavyleung/suning/suning.js
4 changes: 3 additions & 1 deletion QuantumultX_Remote_Task.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# bilibili
#打开浏览器访问: https://www.bilibili.com 或 https://live.bilibili.com
2 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js
#如需银瓜子转硬币,取消下方注释
;1 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js

# 懂球帝
#打开懂球帝 (打开前先杀掉 APP)
Expand Down Expand Up @@ -172,4 +174,4 @@
# 苏宁易购
# 首页 > 签到有礼
# 首页 > 领取红包
7 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js
7 0 * * * https://raw.githubusercontent.com/chavyleung/scripts/master/suning/suning.js
10 changes: 9 additions & 1 deletion bilibili/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

> 代码已同时兼容 Surge & QuanX, 使用同一份签到脚本即可
> 目前只签 bilibili 直播 (直播!直播!直播!)
> 目前可签 bilibili 直播 (直播!直播!直播!) + 银瓜子转硬币
> 2020.1.11 QuanX 在`190`版本开始, 获取 Cookie 方式需要从`script-response-body`改为`script-request-header`
> 2020.3.16 添加银瓜子转硬币脚本 感谢[@lcandy2](https://github.com/lcandy2) PR
## 配置 (Surge)

```properties
Expand All @@ -15,6 +17,8 @@
[Script]
http-request ^https:\/\/(www|live)\.bilibili\.com\/?.? script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.cookie.js
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.js
# 如需银瓜子转硬币,添加以下内容
cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scripts/master/bilibili/bilibili.silver2coin.js
```

## 配置 (QuanX)
Expand All @@ -31,6 +35,8 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr

[task_local]
1 0 * * * bilibili.js
# 如需银瓜子转硬币,添加以下内容
1 0 * * * bilibili.silver2coin.js
```

## 说明
Expand Down Expand Up @@ -97,3 +103,5 @@ cron "10 0 0 * * *" script-path=https://raw.githubusercontent.com/chavyleung/scr
[@lhie1](https://github.com/lhie1)

[@ConnersHua](https://github.com/ConnersHua)

[@lcandy2](https://github.com/lcandy2)
88 changes: 88 additions & 0 deletions bilibili/bilibili.silver2coin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const cookieName = 'bilibili'
const cookieKey = 'chavy_cookie_bilibili'
const chavy = init()
const cookieVal = chavy.getdata(cookieKey)

sign()

function sign() {
let url = {
url: `https://api.live.bilibili.com/pay/v1/Exchange/silver2coin`,
headers: {
Cookie: cookieVal
}
}
url.headers['Origin'] = 'api.live.bilibili.com'
url.headers['Referer'] = 'http://live.bilibili.com/'
url.headers['Accept'] = 'application/json, text/javascript, */*; q=0.01'
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'

chavy.get(url, (error, response, data) => {
let result = JSON.parse(data)
let title = `${cookieName} 银瓜子转硬币`
// 兑换成功
if (result && result.code == 0) {
let subTitle = `${result.message}`
let detail = `成功兑换: ${result.data.coin} 个硬币\n当前银瓜子: ${result.data.silver} , 当前金瓜子: ${result.data.gold}`
chavy.msg(title, subTitle, detail)
}
// 兑换中止(重复兑换&银瓜子不足)
else if (result && result.code == 403) {
let subTitle = `未成功兑换`
let detail = `${result.message}`
chavy.msg(title, subTitle, detail)
}
// 兑换失败
else {
let subTitle = `兑换失败`
let detail = `说明: ${result.message}`
chavy.msg(title, subTitle, detail)
}
chavy.log(`${cookieName}, data: ${data}`)
})

chavy.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))
}
}
done = (value = {}) => {
$done(value)
}
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
}

0 comments on commit 4973659

Please sign in to comment.