2020-07-02 11:50:39 +08:00
const cookieName = '百词斩'
const cookieKey = 'senku_cookie_bcz'
const shareKey = 'senku_key_bcz'
const senku = init ( )
const cookieVal = senku . getdata ( cookieKey )
const shareVal = senku . getdata ( shareKey )
let signinfo = { }
senku . log ( )
check ( )
2020-07-02 11:51:49 +08:00
2020-07-02 11:50:39 +08:00
function check ( cb ) {
2020-07-02 11:51:49 +08:00
const url = { url : ` https://group.baicizhan.com/group/apply_reward ` , headers : { Cookie : cookieVal } }
url . headers [ 'Content-Type' ] = ` text/plain;charset=utf-8 `
url . headers [ 'User-Agent' ] = ` Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.10(0x17000a21) NetType/4G Language/zh_CN `
const key = { share _key : shareVal }
url . body = JSON . stringify ( key )
senku . log ( url . body )
senku . post ( url , ( error , response , data ) => {
signinfo = JSON . parse ( data )
senku . log ( JSON . stringify ( signinfo ) )
const title = ` ${ cookieName } `
let subTitle = ` `
let detail = ''
if ( signinfo . code == 1 ) {
if ( signinfo . data . is _new ) {
subTitle += ` 成功 `
detail = ` 获取铜板数 ${ signinfo . data . reward [ 2 ] } `
} else {
subTitle += ` 今天的铜板已经领取,但是单词还是可以继续背的 `
}
} else {
detail = ` 状态: 还玩手机?快去背单词 `
subTitle += '失败'
}
senku . msg ( title , subTitle , detail )
senku . done ( )
} )
2020-07-02 11:50:39 +08:00
}
function init ( ) {
2020-07-02 11:51:49 +08:00
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 )
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:51:49 +08:00
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 ) )
}
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:51:49 +08:00
post = ( url , cb ) => {
if ( isSurge ( ) ) {
$httpClient . post ( url , cb )
}
if ( isQuanX ( ) ) {
url . method = 'POST'
$task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
}
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:51:49 +08:00
done = ( value = { } ) => {
$done ( value )
2020-07-02 11:50:39 +08:00
}
2020-07-02 11:51:49 +08:00
return { isSurge , isQuanX , msg , log , getdata , setdata , get , post , done }
2020-07-02 11:50:39 +08:00
}