1
+ var appName = '不背单词'
2
+ var bubei = init ( )
3
+ var URL = bubei . getdata ( "UrlBB" )
4
+ var KEY = bubei . getdata ( "CookieBB" )
5
+
6
+ let isGetCookie = typeof $request !== 'undefined'
7
+
8
+ if ( isGetCookie ) {
9
+ getcookie ( )
10
+ } else {
11
+ sign ( )
12
+ }
13
+
14
+ function getcookie ( ) {
15
+ var url = $request . url ;
16
+ if ( url ) {
17
+ var UrlKeyBB = "UrlBB" ;
18
+ var UrlValueBB = url ;
19
+ if ( bubei . getdata ( UrlKeyBB ) != ( undefined || null ) ) {
20
+ if ( bubei . getdata ( UrlKeyBB ) != UrlValueBB ) {
21
+ var url = bubei . setdata ( UrlValueBB , UrlKeyBB ) ;
22
+ if ( ! url ) {
23
+ bubei . msg ( "更新" + appName + "Url失败‼️" , "" , "" ) ;
24
+ } else {
25
+ bubei . msg ( "更新" + appName + "Url成功🎉" , "" , "" ) ;
26
+ }
27
+ } else {
28
+ bubei . msg ( appName + "Url未变化❗️" , "" , "" ) ;
29
+ }
30
+ } else {
31
+ var url = bubei . setdata ( UrlValueBB , UrlKeyBB ) ;
32
+ if ( ! url ) {
33
+ bubei . msg ( "首次写入" + appName + "Url失败‼️" , "" , "" ) ;
34
+ } else {
35
+ bubei . msg ( "首次写入" + appName + "Url成功🎉" , "" , "" ) ;
36
+ }
37
+ }
38
+ } else {
39
+ bubei . msg ( "写入" + appName + "Url失败‼️" , "" , "配置错误, 无法读取URL, " ) ;
40
+ }
41
+ if ( $request . headers ) {
42
+ var CookieKeyBB = "CookieBB" ;
43
+ var CookieValueBB = JSON . stringify ( $request . headers ) ;
44
+ if ( bubei . getdata ( CookieKeyBB ) != ( undefined || null ) ) {
45
+ if ( bubei . getdata ( CookieKeyBB ) != CookieValueBB ) {
46
+ var cookie = bubei . setdata ( CookieValueBB , CookieKeyBB ) ;
47
+ if ( ! cookie ) {
48
+ bubei . msg ( "更新" + appName + "Cookie失败‼️" , "" , "" ) ;
49
+ } else {
50
+ bubei . msg ( "更新" + appName + "Cookie成功🎉" , "" , "" ) ;
51
+ }
52
+ } else {
53
+ bubei . msg ( appName + "Cookie未变化❗️" , "" , "" ) ;
54
+ }
55
+ } else {
56
+ var cookie = bubei . setdata ( CookieValueBB , CookieKeyBB ) ;
57
+ if ( ! cookie ) {
58
+ bubei . msg ( "首次写入" + appName + "Cookie失败‼️" , "" , "" ) ;
59
+ } else {
60
+ bubei . msg ( "首次写入" + appName + "Cookie成功🎉" , "" , "" ) ;
61
+ }
62
+ }
63
+ } else {
64
+ bubei . msg ( "写入" + appName + "Cookie失败‼️" , "" , "配置错误, 无法读取请求头, " ) ;
65
+ }
66
+ bubei . done ( )
67
+ }
68
+
69
+ function sign ( ) {
70
+ var t1 = new Date ( ) . getTime ( )
71
+ var t2 = t1 + 1
72
+ URL = URL . replace ( / b y - s i g n - i n \/ \d * / g, "by-sign-in/" + t1 ) . replace ( / t i m e s t a m p = \d * / g, "timestamp=" + t2 )
73
+ const url = { url : URL , headers : JSON . parse ( KEY ) }
74
+ bubei . get ( url , ( error , response , data ) => {
75
+ bubei . log ( `${ appName } , data: ${ data } ` )
76
+ const title = `${ appName } `
77
+ let subTitle = ''
78
+ let detail = ''
79
+ const result = JSON . parse ( data )
80
+ if ( result . result_code == 200 ) {
81
+ subTitle = `签到结果: 成功`
82
+ } else {
83
+ subTitle = `签到结果: 未知`
84
+ detail = `说明: ${ result . error_body . user_msg } `
85
+ }
86
+ bubei . msg ( title , subTitle , detail )
87
+ bubei . done ( )
88
+ } )
89
+ }
90
+
91
+ function init ( ) {
92
+ isSurge = ( ) => {
93
+ return undefined === this . $httpClient ? false : true
94
+ }
95
+ isQuanX = ( ) => {
96
+ return undefined === this . $task ? false : true
97
+ }
98
+ getdata = ( key ) => {
99
+ if ( isSurge ( ) ) return $persistentStore . read ( key )
100
+ if ( isQuanX ( ) ) return $prefs . valueForKey ( key )
101
+ }
102
+ setdata = ( key , val ) => {
103
+ if ( isSurge ( ) ) return $persistentStore . write ( key , val )
104
+ if ( isQuanX ( ) ) return $prefs . setValueForKey ( key , val )
105
+ }
106
+ msg = ( title , subtitle , body ) => {
107
+ if ( isSurge ( ) ) $notification . post ( title , subtitle , body )
108
+ if ( isQuanX ( ) ) $notify ( title , subtitle , body )
109
+ }
110
+ log = ( message ) => console . log ( message )
111
+ get = ( url , cb ) => {
112
+ if ( isSurge ( ) ) {
113
+ $httpClient . get ( url , cb )
114
+ }
115
+ if ( isQuanX ( ) ) {
116
+ url . method = 'GET'
117
+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
118
+ }
119
+ }
120
+ post = ( url , cb ) => {
121
+ if ( isSurge ( ) ) {
122
+ $httpClient . post ( url , cb )
123
+ }
124
+ if ( isQuanX ( ) ) {
125
+ url . method = 'POST'
126
+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
127
+ }
128
+ }
129
+ put = ( url , cb ) => {
130
+ if ( isSurge ( ) ) {
131
+ $httpClient . put ( url , cb )
132
+ }
133
+ if ( isQuanX ( ) ) {
134
+ url . method = 'PUT'
135
+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
136
+ }
137
+ }
138
+ done = ( value = { } ) => {
139
+ $done ( value )
140
+ }
141
+ return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, put, done }
142
+ }
0 commit comments