1+ const cookieName = '海底捞'
2+ const signurlKey = 'signurl_hdl'
3+ const signheaderKey = 'signheader_hdl'
4+ const signbodyKey = 'signbody_hdl'
5+ const hdl = init ( )
6+
7+ let isGetCookie = typeof $request !== 'undefined'
8+
9+ if ( isGetCookie ) {
10+ getcookie ( )
11+ } else {
12+ sign ( )
13+ }
14+
15+ function getcookie ( ) {
16+ if ( $request && $request . method == 'POST' ) {
17+ const signurlVal = $request . url
18+ const signheaderVal = JSON . stringify ( $request . headers )
19+ const signbodyVal = $request . body
20+
21+ if ( signurlVal ) hdl . setdata ( signurlVal , signurlKey )
22+ if ( signheaderVal ) hdl . setdata ( signheaderVal , signheaderKey )
23+ if ( signbodyVal ) hdl . setdata ( signbodyVal , signbodyKey )
24+ hdl . msg ( cookieName , `获取Cookie: 成功, 请禁用该脚本` , `` )
25+ }
26+ hdl . done ( )
27+ }
28+
29+ function sign ( ) {
30+ const signurlVal = hdl . getdata ( signurlKey )
31+ const signheaderVal = hdl . getdata ( signheaderKey )
32+ const signbodyVal = hdl . getdata ( signbodyKey )
33+ const url = { url : signurlVal , headers : JSON . parse ( signheaderVal ) , body : signbodyVal }
34+ hdl . post ( url , ( error , response , data ) => {
35+ hdl . log ( `${ cookieName } , data: ${ data } ` )
36+ const title = `${ cookieName } `
37+ let subTitle = ''
38+ let detail = ''
39+ const result = JSON . parse ( data )
40+ if ( result . success == true && result . signInfoVO . todaySigned == true ) {
41+ subTitle = `签到结果: 成功`
42+ detail = `签到奖励: ${ result . customInfo . foodNum } 火柴, 连签: ${ result . signInfoVO . continueDay } 天`
43+ } else if ( result . success == false && result . signInfoVO . todaySigned == true ) {
44+ subTitle = `签到结果: 成功 (重复签到)`
45+ detail = `连签: ${ result . signInfoVO . continueDay } 天`
46+ } else {
47+ subTitle = `签到结果: 失败`
48+ detail = `说明: ${ result . message } , 请重新获取`
49+ }
50+ hdl . msg ( title , subTitle , detail )
51+ hdl . done ( )
52+ } )
53+ }
54+
55+ function init ( ) {
56+ isSurge = ( ) => {
57+ return undefined === this . $httpClient ? false : true
58+ }
59+ isQuanX = ( ) => {
60+ return undefined === this . $task ? false : true
61+ }
62+ getdata = ( key ) => {
63+ if ( isSurge ( ) ) return $persistentStore . read ( key )
64+ if ( isQuanX ( ) ) return $prefs . valueForKey ( key )
65+ }
66+ setdata = ( key , val ) => {
67+ if ( isSurge ( ) ) return $persistentStore . write ( key , val )
68+ if ( isQuanX ( ) ) return $prefs . setValueForKey ( key , val )
69+ }
70+ msg = ( title , subtitle , body ) => {
71+ if ( isSurge ( ) ) $notification . post ( title , subtitle , body )
72+ if ( isQuanX ( ) ) $notify ( title , subtitle , body )
73+ }
74+ log = ( message ) => console . log ( message )
75+ get = ( url , cb ) => {
76+ if ( isSurge ( ) ) {
77+ $httpClient . get ( url , cb )
78+ }
79+ if ( isQuanX ( ) ) {
80+ url . method = 'GET'
81+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
82+ }
83+ }
84+ post = ( url , cb ) => {
85+ if ( isSurge ( ) ) {
86+ $httpClient . post ( url , cb )
87+ }
88+ if ( isQuanX ( ) ) {
89+ url . method = 'POST'
90+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
91+ }
92+ }
93+ put = ( url , cb ) => {
94+ if ( isSurge ( ) ) {
95+ $httpClient . put ( url , cb )
96+ }
97+ if ( isQuanX ( ) ) {
98+ url . method = 'PUT'
99+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
100+ }
101+ }
102+ done = ( value = { } ) => {
103+ $done ( value )
104+ }
105+ return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done }
106+ }
0 commit comments