1
1
/*
2
- * 由ZCY01二次修改:脚本默认不运行
3
- * 由 X1a0He 修复
4
2
* 如需运行请自行添加环境变量:JD_TRY,值填 true 即可运行
5
3
* 脚本兼容: Node.js
6
4
* X1a0He留
7
- * 由于没有兼容Qx,原脚本已失效,建议原脚本的兼容Qx注释删了
8
5
* 脚本是否耗时只看args_xh.maxLength的大小
9
6
* 上一作者说了每天最多300个商店,总上限为500个,jd_unsubscribe.js我已更新为批量取关版
10
7
* 请提前取关至少250个商店确保京东试用脚本正常运行
@@ -22,17 +19,33 @@ $.isPush = true;
22
19
$ . isLimit = false ;
23
20
$ . isForbidden = false ;
24
21
$ . wrong = false ;
22
+ $ . totalPages = 0 ;
25
23
$ . giveupNum = 0 ;
26
24
$ . successNum = 0 ;
27
25
$ . completeNum = 0 ;
28
26
$ . getNum = 0 ;
29
27
$ . try = true ;
28
+ $ . sentNum = 0 ;
29
+ $ . cookiesArr = [ ]
30
+ $ . innerKeyWords =
31
+ [
32
+ "幼儿园" , "教程" , "英语" , "辅导" , "培训" ,
33
+ "孩子" , "小学" , "成人用品" , "套套" , "情趣" ,
34
+ "自慰" , "阳具" , "飞机杯" , "男士用品" , "女士用品" ,
35
+ "内衣" , "高潮" , "避孕" , "乳腺" , "肛塞" , "肛门" ,
36
+ "宝宝" , "玩具" , "芭比" , "娃娃" , "男用" ,
37
+ "女用" , "神油" , "足力健" , "老年" , "老人" ,
38
+ "宠物" , "饲料" , "丝袜" , "黑丝" , "磨脚" ,
39
+ "脚皮" , "除臭" , "性感" , "内裤" , "跳蛋" ,
40
+ "安全套" , "龟头" , "阴道" , "阴部"
41
+ ]
30
42
//下面很重要,遇到问题请把下面注释看一遍再来问
31
43
let args_xh = {
32
44
/*
33
45
* 商品原价,低于这个价格都不会试用,意思是
34
46
* A商品原价49元,试用价1元,如果下面设置为50,那么A商品不会被加入到待提交的试用组
35
47
* B商品原价99元,试用价0元,如果下面设置为50,那么B商品将会被加入到待提交的试用组
48
+ * C商品原价99元,试用价1元,如果下面设置为50,那么C商品将会被加入到待提交的试用组
36
49
* 默认为0
37
50
* */
38
51
jdPrice : process . env . JD_TRY_PRICE * 1 || 0 ,
@@ -49,12 +62,16 @@ let args_xh = {
49
62
* 可设置环境变量:JD_TRY_TABID,用@进行分隔
50
63
* 默认为 1 到 5
51
64
* */
52
- tabId : process . env . JD_TRY_TABID && process . env . JD_TRY_TABID . split ( '@' ) . map ( Number ) || [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ,
65
+ tabId : process . env . JD_TRY_TABID && process . env . JD_TRY_TABID . split ( '@' ) . map ( Number ) || [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ,
53
66
/*
54
67
* 试用商品标题过滤,黑名单,当标题存在关键词时,则不加入试用组
68
+ * 当白名单和黑名单共存时,黑名单会自动失效,优先匹配白名单,匹配完白名单后不会再匹配黑名单,望周知
69
+ * 例如A商品的名称为『旺仔牛奶48瓶特价』,设置了匹配白名单,白名单关键词为『牛奶』,但黑名单关键词存在『旺仔』
70
+ * 这时,A商品还是会被添加到待提交试用组,白名单优先于黑名单
71
+ * 已内置对应的 成人类 幼儿类 宠物 老年人类关键词,请勿重复添加
55
72
* 可设置环境变量:JD_TRY_TITLEFILTERS,关键词与关键词之间用@分隔
56
73
* */
57
- titleFilters : process . env . JD_TRY_TITLEFILTERS && process . env . JD_TRY_TITLEFILTERS . split ( '@' ) || [ "幼儿园" , "教程" , "英语" , "辅导" , "培训" , "孩子" , "小学" , "成人用品" , "套套" , "情趣" , "自慰" , "阳具" , "飞机杯" , "男士用品" , "女士用品" , "内衣" , "高潮" , "避孕" ] ,
74
+ titleFilters : process . env . JD_TRY_TITLEFILTERS && process . env . JD_TRY_TITLEFILTERS . split ( '@' ) || [ ] ,
58
75
/*
59
76
* 试用价格(中了要花多少钱),高于这个价格都不会试用,小于等于才会试用,意思就是
60
77
* A商品原价49元,现在试用价1元,如果下面设置为10,那A商品将会被添加到待提交试用组,因为1 < 10
@@ -106,97 +123,117 @@ let args_xh = {
106
123
* */
107
124
printLog : process . env . JD_TRY_PLOG || true ,
108
125
/*
109
- * 白名单
126
+ * 白名单,是否打开,如果下面为true,那么黑名单会自动失效
127
+ * 白名单和黑名单无法共存,白名单永远优先于黑名单
110
128
* 可通过环境变量控制:JD_TRY_WHITELIST,默认为false
111
129
* */
112
130
whiteList : process . env . JD_TRY_WHITELIST || false ,
113
131
/*
114
132
* 白名单关键词,当标题存在关键词时,加入到试用组
133
+ * 例如A商品的名字为『旺仔牛奶48瓶特价』,白名单其中一个关键词是『牛奶』,那么A将会直接被添加到待提交试用组,不再进行另外判断
134
+ * 就算设置了黑名单也不会判断,希望这种写得那么清楚的脑瘫问题就别提issues了
115
135
* 可通过环境变量控制:JD_TRY_WHITELIST,用@分隔
116
136
* */
117
137
whiteListKeywords : process . env . JD_TRY_WHITELISTKEYWORDS && process . env . JD_TRY_WHITELISTKEYWORDS . split ( '@' ) || [ ] ,
138
+ /*
139
+ * 每多少个账号发送一次通知,默认为4
140
+ * 可通过环境变量控制 JD_TRY_SENDNUM
141
+ * */
142
+ sendNum : process . env . JD_TRY_SENDNUM * 1 || 4 ,
118
143
}
119
144
//上面很重要,遇到问题请把上面注释看一遍再来问
120
145
! ( async ( ) => {
121
- console . log ( '京东试用只建议懂如何配置的跑,不只是脚本配置,京东试用规则本身也比较复杂.这也是为什么默认不跑. 云函数也是,可能会跑很久.如果你问的问题不是脚本的代码问题,我十分不建议跑' )
146
+ console . log ( 'X1a0He留:遇到问题请把脚本内的注释看一遍再来问,谢谢' )
147
+ console . log ( 'X1a0He留:遇到问题请把脚本内的注释看一遍再来问,谢谢' )
148
+ console . log ( 'X1a0He留:遇到问题请把脚本内的注释看一遍再来问,谢谢' )
122
149
await $ . wait ( 500 )
150
+ // 如果你要运行京东试用这个脚本,麻烦你把环境变量 JD_TRY 设置为 true
123
151
if ( process . env . JD_TRY && process . env . JD_TRY === 'true' ) {
124
- await requireConfig ( )
125
- if ( ! $ . cookiesArr [ 0 ] ) {
126
- $ . msg ( $ . name , '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取' , 'https://bean.m.jd.com/' , {
127
- "open-url" : "https://bean.m.jd.com/"
128
- } )
129
- return
130
- }
131
- for ( let i = 0 ; i < $ . cookiesArr . length ; i ++ ) {
132
- if ( $ . cookiesArr [ i ] ) {
133
- $ . cookie = $ . cookiesArr [ i ] ;
134
- $ . UserName = decodeURIComponent ( $ . cookie . match ( / p t _ p i n = ( .+ ?) ; / ) && $ . cookie . match ( / p t _ p i n = ( .+ ?) ; / ) [ 1 ] )
135
- $ . index = i + 1 ;
136
- $ . isLogin = true ;
137
- $ . nickName = '' ;
138
- await totalBean ( ) ;
139
- console . log ( `\n开始【京东账号${ $ . index } 】${ $ . nickName || $ . UserName } \n` ) ;
140
- if ( ! $ . isLogin ) {
141
- $ . msg ( $ . name , `【提示】cookie已失效` , `京东账号${ $ . index } ${ $ . nickName || $ . UserName } \n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action` , {
142
- "open-url" : "https://bean.m.jd.com/bean/signIndex.action"
143
- } ) ;
144
- await $ . notify . sendNotify ( `${ $ . name } cookie已失效 - ${ $ . UserName } ` , `京东账号${ $ . index } ${ $ . UserName } \n请重新登录获取cookie` ) ;
145
- continue
146
- }
147
- $ . totalTry = 0
148
- $ . totalSuccess = 0
149
- $ . nowTabIdIndex = 0 ;
150
- $ . nowPage = 1 ;
151
- $ . nowItem = 1 ;
152
- trialActivityIdList = [ ]
153
- trialActivityTitleList = [ ]
154
- $ . isLimit = false ;
155
- // 获取tabList的,不知道有哪些的把这里的注释解开跑一遍就行了
156
- // await try_tabList();
157
- // return;
158
- $ . isForbidden = false
159
- $ . wrong = false
160
- size = 1
161
- while ( trialActivityIdList . length < args_xh . maxLength && $ . isForbidden === false && $ . wrong === false ) {
162
- if ( $ . nowTabIdIndex === args_xh . tabId . length ) {
163
- console . log ( `tabId组已遍历完毕,不在获取商品\n` ) ;
164
- break ;
165
- } else {
166
- await try_feedsList ( args_xh . tabId [ $ . nowTabIdIndex ] , $ . nowPage ++ ) //获取对应tabId的试用页面
167
- }
168
- if ( trialActivityIdList . length < args_xh . maxLength ) {
169
- console . log ( `间隔等待中,请等待 2 秒\n` )
170
- await $ . wait ( 2000 ) ;
171
- }
152
+ await requireConfig ( )
153
+ if ( ! $ . cookiesArr [ 0 ] ) {
154
+ $ . msg ( $ . name , '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取' , 'https://bean.m.jd.com/' , {
155
+ "open-url" : "https://bean.m.jd.com/"
156
+ } )
157
+ return
158
+ }
159
+ for ( let i = 0 ; i < $ . cookiesArr . length ; i ++ ) {
160
+ if ( $ . cookiesArr [ i ] ) {
161
+ $ . cookie = $ . cookiesArr [ i ] ;
162
+ $ . UserName = decodeURIComponent ( $ . cookie . match ( / p t _ p i n = ( .+ ?) ; / ) && $ . cookie . match ( / p t _ p i n = ( .+ ?) ; / ) [ 1 ] )
163
+ $ . index = i + 1 ;
164
+ $ . isLogin = true ;
165
+ $ . nickName = '' ;
166
+ await totalBean ( ) ;
167
+ console . log ( `\n开始【京东账号${ $ . index } 】${ $ . nickName || $ . UserName } \n` ) ;
168
+ if ( ! $ . isLogin ) {
169
+ $ . msg ( $ . name , `【提示】cookie已失效` , `京东账号${ $ . index } ${ $ . nickName || $ . UserName } \n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action` , {
170
+ "open-url" : "https://bean.m.jd.com/bean/signIndex.action"
171
+ } ) ;
172
+ await $ . notify . sendNotify ( `${ $ . name } cookie已失效 - ${ $ . UserName } ` , `京东账号${ $ . index } ${ $ . UserName } \n请重新登录获取cookie` ) ;
173
+ continue
174
+ }
175
+ $ . totalTry = 0
176
+ $ . totalSuccess = 0
177
+ $ . nowTabIdIndex = 0 ;
178
+ $ . nowPage = 1 ;
179
+ $ . nowItem = 1 ;
180
+ trialActivityIdList = [ ]
181
+ trialActivityTitleList = [ ]
182
+ $ . isLimit = false ;
183
+ // 获取tabList的,不知道有哪些的把这里的注释解开跑一遍就行了
184
+ // await try_tabList();
185
+ // return;
186
+ $ . isForbidden = false
187
+ $ . wrong = false
188
+ size = 1
189
+ while ( trialActivityIdList . length < args_xh . maxLength && $ . isForbidden === false ) {
190
+ if ( $ . nowTabIdIndex === args_xh . tabId . length ) {
191
+ console . log ( `tabId组已遍历完毕,不在获取商品\n` ) ;
192
+ break ;
193
+ } else {
194
+ await try_feedsList ( args_xh . tabId [ $ . nowTabIdIndex ] , $ . nowPage ) //获取对应tabId的试用页面
172
195
}
173
- if ( $ . isForbidden === false && $ . isLimit === false ) {
174
- console . log ( `稍后将执行试用申请 ,请等待 2 秒\n` )
196
+ if ( trialActivityIdList . length < args_xh . maxLength ) {
197
+ console . log ( `间隔等待中 ,请等待 2 秒\n` )
175
198
await $ . wait ( 2000 ) ;
176
- for ( let i = 0 ; i < trialActivityIdList . length && $ . isLimit === false ; i ++ ) {
177
- if ( $ . isLimit ) {
178
- console . log ( "试用上限" )
179
- break
180
- }
181
- await try_apply ( trialActivityTitleList [ i ] , trialActivityIdList [ i ] )
182
- console . log ( `间隔等待中,请等待 ${ args_xh . applyInterval } ms\n` )
183
- await $ . wait ( args_xh . applyInterval ) ;
199
+ }
200
+ }
201
+ if ( $ . isForbidden === false && $ . isLimit === false ) {
202
+ console . log ( `稍后将执行试用申请,请等待 2 秒\n` )
203
+ await $ . wait ( 2000 ) ;
204
+ for ( let i = 0 ; i < trialActivityIdList . length && $ . isLimit === false ; i ++ ) {
205
+ if ( $ . isLimit ) {
206
+ console . log ( "试用上限" )
207
+ break
184
208
}
185
- console . log ( "试用申请执行完毕..." )
186
- // await try_MyTrials(1, 1) //申请中的商品
187
- $ . giveupNum = 0 ;
188
- $ . successNum = 0 ;
189
- $ . getNum = 0 ;
190
- $ . completeNum = 0 ;
191
- await try_MyTrials ( 1 , 2 ) //申请成功的商品
192
- // await try_MyTrials(1, 3) //申请失败的商品
193
- await showMsg ( )
209
+ await try_apply ( trialActivityTitleList [ i ] , trialActivityIdList [ i ] )
210
+ console . log ( `间隔等待中,请等待 ${ args_xh . applyInterval } ms\n` )
211
+ await $ . wait ( args_xh . applyInterval ) ;
194
212
}
213
+ console . log ( "试用申请执行完毕..." )
214
+ // await try_MyTrials(1, 1) //申请中的商品
215
+ $ . giveupNum = 0 ;
216
+ $ . successNum = 0 ;
217
+ $ . getNum = 0 ;
218
+ $ . completeNum = 0 ;
219
+ await try_MyTrials ( 1 , 2 ) //申请成功的商品
220
+ // await try_MyTrials(1, 3) //申请失败的商品
221
+ await showMsg ( )
195
222
}
196
223
}
197
- if ( $ . isForbidden === false && $ . isLimit === false ) {
198
- await $ . notify . sendNotify ( `${ $ . name } ` , notifyMsg ) ;
224
+ }
225
+ if ( $ . isNode ( ) ) {
226
+ if ( $ . index % args_xh . sendNum === 0 ) {
227
+ $ . sentNum ++ ;
228
+ console . log ( `正在进行第 ${ $ . sentNum } 次发送通知,发送数量:${ args_xh . sendNum } ` )
229
+ await $ . notify . sendNotify ( `${ $ . name } ` , `${ notifyMsg } ` )
230
+ notifyMsg = "" ;
231
+ } else if ( ( $ . cookiesArr . length - ( $ . sentNum * args_xh . sendNum ) ) < args_xh . sendNum ) {
232
+ console . log ( `正在进行最后一次发送通知,发送数量:${ ( $ . cookiesArr . length - ( $ . sentNum * args_xh . sendNum ) ) } ` )
233
+ await $ . notify . sendNotify ( `${ $ . name } ` , `${ notifyMsg } ` )
234
+ notifyMsg = "" ;
199
235
}
236
+ }
200
237
} else {
201
238
console . log ( `\n您未设置运行【京东试用】脚本,结束运行!\n` )
202
239
}
@@ -214,9 +251,7 @@ function requireConfig(){
214
251
//Node.js用户请在jdCookie.js处填写京东ck;
215
252
const jdCookieNode = require ( './jdCookie.js' ) ;
216
253
Object . keys ( jdCookieNode ) . forEach ( ( item ) => {
217
- if ( jdCookieNode [ item ] ) {
218
- $ . cookiesArr . push ( jdCookieNode [ item ] )
219
- }
254
+ if ( jdCookieNode [ item ] ) $ . cookiesArr . push ( jdCookieNode [ item ] )
220
255
} )
221
256
if ( process . env . JD_DEBUG && process . env . JD_DEBUG === 'false' ) console . log = ( ) => { } ;
222
257
} else {
@@ -229,6 +264,7 @@ function requireConfig(){
229
264
else args_xh . printLog = process . env . JD_TRY_PLOG === 'true' ;
230
265
if ( typeof process . env . JD_TRY_PASSZC === "undefined" ) args_xh . passZhongCao = true ;
231
266
else args_xh . passZhongCao = process . env . JD_TRY_PASSZC === 'true' ;
267
+ for ( let keyWord of $ . innerKeyWords ) args_xh . titleFilters . push ( keyWord )
232
268
console . log ( `共${ $ . cookiesArr . length } 个京东账号\n` )
233
269
console . log ( '=====环境变量配置如下=====' )
234
270
console . log ( `jdPrice: ${ typeof args_xh . jdPrice } , ${ args_xh . jdPrice } ` )
@@ -286,14 +322,6 @@ function try_tabList(){
286
322
//获取商品列表并且过滤 By X1a0He
287
323
function try_feedsList ( tabId , page ) {
288
324
return new Promise ( ( resolve , reject ) => {
289
- if ( page > $ . totalPages ) {
290
- console . log ( "请求页数错误" )
291
- $ . wrong = true ;
292
- return ;
293
- } else if ( $ . nowTabIdIndex > args_xh . tabId . length ) {
294
- console . log ( `不再获取商品,边缘越界,提交试用中...` )
295
- return ;
296
- }
297
325
const body = JSON . stringify ( {
298
326
"tabId" : `${ tabId } ` ,
299
327
"page" : page ,
@@ -315,11 +343,8 @@ function try_feedsList(tabId, page){
315
343
let tempKeyword = `` ;
316
344
if ( data . success ) {
317
345
$ . totalPages = data . data . pages
318
- if ( $ . nowTabIdIndex > args_xh . tabId . length ) {
319
- console . log ( `不再获取商品,边缘越界,提交试用中...` )
320
- } else {
321
- console . log ( `第 ${ size ++ } 次获取试用商品成功,tabId:${ args_xh . tabId [ $ . nowTabIdIndex ] } 的 第 ${ page } /${ $ . totalPages } 页` )
322
- }
346
+ $ . nowPage === $ . totalPages ? $ . nowPage = 1 : $ . nowPage ++ ;
347
+ console . log ( `第 ${ size ++ } 次获取试用商品成功,tabId:${ args_xh . tabId [ $ . nowTabIdIndex ] } 的 第 ${ page } /${ $ . totalPages } 页` )
323
348
console . log ( `获取到商品 ${ data . data . feedList . length } 条` )
324
349
for ( let item of data . data . feedList ) {
325
350
if ( item . applyNum === null ) {
@@ -354,7 +379,7 @@ function try_feedsList(tabId, page){
354
379
args_xh . printLog ? console . log ( `检测 tabId:${ args_xh . tabId [ $ . nowTabIdIndex ] } 的 第 ${ page } /${ $ . totalPages } 页 第 ${ $ . nowItem ++ + 1 } 个商品\n${ item . skuTitle } ` ) : ''
355
380
if ( args_xh . whiteList ) {
356
381
if ( args_xh . whiteListKeywords . some ( fileter_word => item . skuTitle . includes ( fileter_word ) ) ) {
357
- args_xh . printLog ? console . log ( `商品通过 ,将加入试用组,trialActivityId为${ item . trialActivityId } \n` ) : ''
382
+ args_xh . printLog ? console . log ( `商品白名单通过 ,将加入试用组,trialActivityId为${ item . trialActivityId } \n` ) : ''
358
383
trialActivityIdList . push ( item . trialActivityId )
359
384
trialActivityTitleList . push ( item . skuTitle )
360
385
}
@@ -439,6 +464,8 @@ function try_apply(title, activityId){
439
464
} else if ( data . code === "-131" ) {
440
465
console . log ( data . message ) // 申请次数上限。
441
466
$ . isLimit = true ;
467
+ } else if ( data . code === "-113" ) {
468
+ console . log ( data . message ) // 操作不要太快哦!
442
469
} else {
443
470
console . log ( "申请失败" , data )
444
471
}
@@ -608,8 +635,6 @@ function jsonParse(str){
608
635
}
609
636
}
610
637
611
- // 来自 @chavyleung 大佬
612
- // https://raw.githubusercontent.com/chavyleung/scripts/master/Env.js
613
638
function Env ( name , opts ) {
614
639
class Http {
615
640
constructor ( env ) {
0 commit comments