2019-12-28 23:03:23 +08:00
/ *
TieBa Daily bonus
The script is made by @ wechatu
Description :
When TieBa app is opened , click "My" , If notification gets cookie success , you can use the check in script . because script will automatically judgment whether the cookie is updated , so you dont need to disable it manually .
script will be performed every day at 9 am . You can modify the execution time .
Note that the following config is only a local script configuration , please put both scripts into Quantumult X / Script , and the cookie script only works for TieBa apps in china apple store
2020-01-12 01:29:13 +08:00
[ rewrite _local ]
# Get TieBa cookie . 【 QX TF188 + 】 :
https ? : \ / \ / c \ . tieba \ . baidu \ . com \ / c \ / s \ / login url script - request - header TieBa _GetCookie _QX . js
2019-12-28 23:03:23 +08:00
# MITM = c . tieba . baidu . com
[ task _local ]
0 9 * * * TieBa _DailyBonus _QX . js
* /
var cookieVal = $prefs . valueForKey ( "CookieTB" ) ;
2019-12-29 16:31:23 +08:00
var useParallel = 0 ; //0自动切换,1串行,2并行(当贴吧数量大于30个以后,并行可能会导致QX崩溃,所以您可以自动切换)
2019-12-28 23:03:23 +08:00
var singleNotifyCount = 20 ; //想签到几个汇总到一个通知里,这里就填几个(比如我有13个要签到的,这里填了5,就会分三次消息通知过去)
var process = {
total : 0 ,
result : [
// {
// bar:'',
// level:0,
// exp:0,
// errorCode:0,
// errorMsg:''
// }
]
} ;
var url _fetch _sign = {
url : "https://tieba.baidu.com/mo/q/newmoindex" ,
headers : {
"Content-Type" : "application/octet-stream" ,
Referer : "https://tieba.baidu.com/index/tbwise/forum" ,
Cookie : cookieVal ,
"User-Agent" : "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16A366"
}
} ;
var url _fetch _add = {
url : "https://tieba.baidu.com/sign/add" ,
method : "POST" ,
headers : {
"Content-Type" : "application/x-www-form-urlencoded" ,
Cookie : cookieVal ,
"User-Agent" : "Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/14B100 UCBrowser/10.7.5.650 Mobile"
} ,
body : ""
} ;
function signTieBa ( ) {
if ( ! cookieVal ) {
$notify ( "贴吧签到" , "签到失败" , "未获取到cookie" ) ;
return ;
}
$task . fetch ( url _fetch _sign ) . then ( response => {
// $notify("贴吧签到", "贴吧列表", response.body);
var body = JSON . parse ( response . body ) ;
var isSuccessResponse = body && body . no == 0 && body . error == "success" && body . data . tbs ;
if ( ! isSuccessResponse ) {
$notify ( "贴吧签到" , "签到失败" , ( body && body . error ) ? body . error : "接口数据获取失败" ) ;
return ;
}
process . total = body . data . like _forum . length ;
if ( body . data . like _forum && body . data . like _forum . length > 0 ) {
2019-12-29 16:31:23 +08:00
if ( useParallel == 1 || ( useParallel == 0 && body . data . like _forum . length >= 30 ) ) {
signBars ( body . data . like _forum , body . data . tbs , 0 ) ;
} else {
2019-12-28 23:03:23 +08:00
for ( const bar of body . data . like _forum ) {
2019-12-29 16:31:23 +08:00
signBar ( bar , body . data . tbs ) ;
}
2019-12-28 23:03:23 +08:00
}
} else {
$notify ( "贴吧签到" , "签到失败" , "请确认您有关注的贴吧" ) ;
return ;
}
} , reason => {
$notify ( "贴吧签到" , "签到失败" , "未获取到签到列表" ) ;
} ) ;
}
function signBar ( bar , tbs ) {
if ( bar . is _sign == 1 ) { //已签到的,直接不请求接口了
process . result . push ( {
bar : ` ${ bar . forum _name } ` ,
level : bar . user _level ,
exp : bar . user _exp ,
errorCode : 9999 ,
errorMsg : "已签到"
} ) ;
checkIsAllProcessed ( ) ;
} else {
url _fetch _add . body = ` tbs= ${ tbs } &kw= ${ bar . forum _name } &ie=utf-8 ` ;
$task . fetch ( url _fetch _add ) . then ( response => {
2019-12-29 16:31:23 +08:00
try {
2019-12-28 23:03:23 +08:00
var addResult = JSON . parse ( response . body ) ;
2019-12-29 16:31:23 +08:00
if ( addResult . no == 0 ) {
process . result . push ( {
bar : bar . forum _name ,
errorCode : 0 ,
errorMsg : ` 获得 ${ addResult . data . uinfo . cont _sign _num } 积分,第 ${ addResult . data . uinfo . user _sign _rank } 个签到 `
} ) ;
} else {
process . result . push ( {
bar : bar . forum _name ,
errorCode : addResult . no ,
errorMsg : addResult . error
} ) ;
}
} catch ( e ) {
2019-12-28 23:03:23 +08:00
$notify ( "贴吧签到" , "贴吧签到数据处理异常" , JSON . stringify ( e ) ) ;
}
checkIsAllProcessed ( ) ;
} , reason => {
process . result . push ( {
bar : bar . forum _name ,
errorCode : 999 ,
errorMsg : '接口错误'
} ) ;
checkIsAllProcessed ( ) ;
} ) ;
}
}
2019-12-29 16:31:23 +08:00
function signBars ( bars , tbs , index ) {
//$notify("贴吧签到", `进度${index}/${bars.length}`, "");
if ( index >= bars . length ) {
//$notify("贴吧签到", "签到已满", `${process.result.length}`);
checkIsAllProcessed ( ) ;
} else {
var bar = bars [ index ] ;
if ( bar . is _sign == 1 ) { //已签到的,直接不请求接口了
process . result . push ( {
bar : ` ${ bar . forum _name } ` ,
level : bar . user _level ,
exp : bar . user _exp ,
errorCode : 9999 ,
errorMsg : "已签到"
} ) ;
signBars ( bars , tbs , ++ index ) ;
} else {
url _fetch _add . body = ` tbs= ${ tbs } &kw= ${ bar . forum _name } &ie=utf-8 ` ;
$task . fetch ( url _fetch _add ) . then ( response => {
try {
var addResult = JSON . parse ( response . body ) ;
if ( addResult . no == 0 ) {
process . result . push ( {
bar : bar . forum _name ,
errorCode : 0 ,
errorMsg : ` 获得 ${ addResult . data . uinfo . cont _sign _num } 积分,第 ${ addResult . data . uinfo . user _sign _rank } 个签到 `
} ) ;
} else {
process . result . push ( {
bar : bar . forum _name ,
errorCode : addResult . no ,
errorMsg : addResult . error
} ) ;
}
} catch ( e ) {
$notify ( "贴吧签到" , "贴吧签到数据处理异常" , JSON . stringify ( e ) ) ;
}
signBars ( bars , tbs , ++ index )
} , reason => {
process . result . push ( {
bar : bar . forum _name ,
errorCode : 999 ,
errorMsg : '接口错误'
} ) ;
signBars ( bars , tbs , ++ index ) ;
} ) ;
}
}
}
2019-12-28 23:03:23 +08:00
function checkIsAllProcessed ( ) {
2019-12-29 16:31:23 +08:00
//$notify("贴吧签到", `最终进度${process.result.length}/${process.total}`, "");
2019-12-28 23:03:23 +08:00
if ( process . result . length != process . total ) return ;
for ( var i = 0 ; i < Math . ceil ( process . total / singleNotifyCount ) ; i ++ ) {
var notify = "" ;
var spliceArr = process . result . splice ( 0 , singleNotifyCount ) ;
var notifySuccessCount = 0 ;
for ( const res of spliceArr ) {
if ( res . errorCode == 0 || res . errorCode == 9999 ) {
notifySuccessCount ++ ;
}
if ( res . errorCode == 9999 ) {
notify += ` 【 ${ res . bar } 】已经签到,当前等级 ${ res . level } ,经验 ${ res . exp }
` ;
} else {
notify += ` 【 ${ res . bar } 】 ${ res . errorCode == 0 ? '签到成功' : '签到失败' } , ${ res . errorCode == 0 ? res . errorMsg : ( '原因:' + res . errorMsg ) }
` ;
}
}
$notify ( "贴吧签到" , ` 签到 ${ spliceArr . length } 个,成功 ${ notifySuccessCount } 个 ` , notify ) ;
}
}
signTieBa ( )