Skip to content

Commit 53a8104

Browse files
Update
1 parent eb43674 commit 53a8104

File tree

2 files changed

+61
-54
lines changed

2 files changed

+61
-54
lines changed

jdFruitShareCodes.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
东东农场互助码
3+
此文件为Node.js专用。其他用户请忽略
4+
支持京东N个账号
5+
*/
6+
//云服务器腾讯云函数等NOde.js用户在此处填写京东东农场的好友码。
7+
// 同一个京东账号的好友互助码用@符号隔开,不同京东账号之间用&符号或者换行隔开,下面给一个示例
8+
// 如: 京东账号1的shareCode1@京东账号1的shareCode2&京东账号2的shareCode1@京东账号2的shareCode2
9+
let FruitShareCodes = [
10+
]
11+
12+
// 从日志获取互助码
13+
// const logShareCodes = require('./utils/jdShareCodes');
14+
// if (logShareCodes.FRUITSHARECODES.length > 0 && !process.env.FRUITSHARECODES) {
15+
// process.env.FRUITSHARECODES = logShareCodes.FRUITSHARECODES.join('&');
16+
// }
17+
18+
// 判断github action里面是否有东东农场互助码
19+
if (process.env.FRUITSHARECODES) {
20+
if (process.env.FRUITSHARECODES.indexOf('&') > -1) {
21+
console.log(`您的东东农场互助码选择的是用&隔开\n`)
22+
FruitShareCodes = process.env.FRUITSHARECODES.split('&');
23+
} else if (process.env.FRUITSHARECODES.indexOf('\n') > -1) {
24+
console.log(`您的东东农场互助码选择的是用换行隔开\n`)
25+
FruitShareCodes = process.env.FRUITSHARECODES.split('\n');
26+
} else {
27+
FruitShareCodes = process.env.FRUITSHARECODES.split();
28+
}
29+
} else {
30+
console.log(`由于您环境变量(FRUITSHARECODES)里面未提供助力码,故此处运行将会给脚本内置的码进行助力,请知晓!`)
31+
}
32+
for (let i = 0; i < FruitShareCodes.length; i++) {
33+
const index = (i + 1 === 1) ? '' : (i + 1);
34+
exports['FruitShareCode' + index] = FruitShareCodes[i];
35+
}

jd_fruit.js

+26-54
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const $ = new Env('东东农场');
2828
console.log('\n====================Hello World====================\n');
2929

3030
let cookiesArr = [], cookie = '', notify, newShareCodes, allMessage = '';
31-
let sharecodeSelf = [], shareCodes = ['']
31+
let shareCodes = ['']
3232
let message = '', subTitle = '', option = {}, isFruitFinished = false;
3333
const retainWater = 100;//保留水滴大于多少g,默认100g;
3434
let jdNotify = false;//是否关闭通知,false打开通知推送,true关闭通知推送
@@ -38,24 +38,12 @@ const JD_API_HOST = 'https://api.m.jd.com/client.action';
3838
const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://h5.m.jd.com/babelDiy/Zeus/3KSjXqQabiTuD1cJ28QskrpWoBKT/index.html%22%20%7D`;
3939
!(async () => {
4040
await requireConfig();
41-
for (let i = 0; i < cookiesArr.length; i++) {
42-
cookie = cookiesArr[i];
43-
$.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1])
44-
$.index = i + 1;
45-
console.log(`\n开始【京东账号${$.index}${$.UserName}\n`);
46-
await initForFarm();
47-
if ($.farmInfo.farmUserPro) {
48-
console.log('助力码', $.farmInfo.farmUserPro.shareCode);
49-
sharecodeSelf.push($.farmInfo.farmUserPro.shareCode);
50-
await $.wait(1000)
51-
}
52-
}
53-
console.log('内部助力码', sharecodeSelf.length, sharecodeSelf);
5441
for (let i = 0; i < cookiesArr.length; i++) {
5542
if (cookiesArr[i]) {
5643
cookie = cookiesArr[i];
5744
$.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1])
5845
$.index = i + 1;
46+
$.isLogin = true;
5947
console.log(`\n开始【京东账号${$.index}${$.UserName}\n`);
6048
message = '';
6149
subTitle = '';
@@ -505,14 +493,7 @@ async function turntableFarm() {
505493
await initForTurntableFarm();
506494
if ($.initForTurntableFarmRes.code === '0') {
507495
//领取定时奖励 //4小时一次
508-
let {
509-
timingIntervalHours,
510-
timingLastSysTime,
511-
sysTime,
512-
timingGotStatus,
513-
remainLotteryTimes,
514-
turntableInfos
515-
} = $.initForTurntableFarmRes;
496+
let {timingIntervalHours, timingLastSysTime, sysTime, timingGotStatus, remainLotteryTimes, turntableInfos} = $.initForTurntableFarmRes;
516497

517498
if (!timingGotStatus) {
518499
console.log(`是否到了领取免费赠送的抽奖机会----${sysTime > (timingLastSysTime + 60 * 60 * timingIntervalHours * 1000)}`)
@@ -856,11 +837,7 @@ async function getAwardInviteFriend() {
856837
if ($.friendList.friends && $.friendList.friends.length > 0) {
857838
for (let friend of $.friendList.friends) {
858839
console.log(`\n开始删除好友 [${friend.shareCode}]`);
859-
const deleteFriendForFarm = await request('deleteFriendForFarm', {
860-
"shareCode": `${friend.shareCode}`,
861-
"version": 8,
862-
"channel": 1
863-
});
840+
const deleteFriendForFarm = await request('deleteFriendForFarm', {"shareCode": `${friend.shareCode}`, "version": 8, "channel": 1});
864841
if (deleteFriendForFarm && deleteFriendForFarm.code === '0') {
865842
console.log(`删除好友 [${friend.shareCode}] 成功\n`);
866843
}
@@ -942,12 +919,7 @@ async function doFriendsWater() {
942919
//领取给3个好友浇水后的奖励水滴
943920
async function getWaterFriendGotAward() {
944921
await taskInitForFarm();
945-
const {
946-
waterFriendCountKey,
947-
waterFriendMax,
948-
waterFriendSendWater,
949-
waterFriendGotAward
950-
} = $.farmTask.waterFriendTaskInit
922+
const {waterFriendCountKey, waterFriendMax, waterFriendSendWater, waterFriendGotAward} = $.farmTask.waterFriendTaskInit
951923
if (waterFriendCountKey >= waterFriendMax) {
952924
if (!waterFriendGotAward) {
953925
await waterFriendGotAwardForFarm();
@@ -1374,7 +1346,14 @@ function readShareCode() {
13741346

13751347
function shareCodesFormat() {
13761348
return new Promise(async resolve => {
1377-
newShareCodes = sharecodeSelf;
1349+
newShareCodes = [];
1350+
if ($.shareCodesArr[$.index - 1]) {
1351+
newShareCodes = $.shareCodesArr[$.index - 1].split('@');
1352+
} else {
1353+
console.log(`由于您第${$.index}个京东账号未提供shareCode,将采纳本脚本自带的助力码\n`)
1354+
const tempIndex = $.index > shareCodes.length ? (shareCodes.length - 1) : ($.index - 1);
1355+
newShareCodes = shareCodes[tempIndex].split('@');
1356+
}
13781357
const readShareCodeRes = await readShareCode();
13791358
if (readShareCodeRes && readShareCodeRes.code === 200) {
13801359
newShareCodes = [...new Set([...newShareCodes, ...(readShareCodeRes.data || [])])];
@@ -1390,6 +1369,7 @@ function requireConfig() {
13901369
notify = $.isNode() ? require('./sendNotify') : '';
13911370
//Node.js用户请在jdCookie.js处填写京东ck;
13921371
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
1372+
const jdFruitShareCodes = $.isNode() ? require('./jdFruitShareCodes.js') : '';
13931373
//IOS等用户直接用NobyDa的jd cookie
13941374
if ($.isNode()) {
13951375
Object.keys(jdCookieNode).forEach((item) => {
@@ -1404,11 +1384,17 @@ function requireConfig() {
14041384
}
14051385
console.log(`共${cookiesArr.length}个京东账号\n`)
14061386
$.shareCodesArr = [];
1407-
if (!$.isNode()) {
1387+
if ($.isNode()) {
1388+
Object.keys(jdFruitShareCodes).forEach((item) => {
1389+
if (jdFruitShareCodes[item]) {
1390+
$.shareCodesArr.push(jdFruitShareCodes[item])
1391+
}
1392+
})
1393+
} else {
14081394
if ($.getdata('jd_fruit_inviter')) $.shareCodesArr = $.getdata('jd_fruit_inviter').split('\n').filter(item => !!item);
14091395
console.log(`\nBoxJs设置的${$.name}好友邀请码:${$.getdata('jd_fruit_inviter') ? $.getdata('jd_fruit_inviter') : '暂无'}\n`);
1410-
console.log(`您提供了${$.shareCodesArr.length}个账号的农场助力码\n`);
14111396
}
1397+
console.log(`您提供了${$.shareCodesArr.length}个账号的农场助力码\n`);
14121398
resolve()
14131399
})
14141400
}
@@ -1574,11 +1560,7 @@ function Env(t, e) {
15741560
i = i ? i.replace(/\n/g, "").trim() : i;
15751561
let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");
15761562
r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r;
1577-
const [o, h] = i.split("@"), n = {
1578-
url: `http://${h}/v1/scripting/evaluate`,
1579-
body: {script_text: t, mock_type: "cron", timeout: r},
1580-
headers: {"X-Key": o, Accept: "*/*"}
1581-
};
1563+
const [o, h] = i.split("@"), n = {url: `http://${h}/v1/scripting/evaluate`, body: {script_text: t, mock_type: "cron", timeout: r}, headers: {"X-Key": o, Accept: "*/*"}};
15821564
this.post(n, (t, e, i) => s(i))
15831565
}).catch(t => this.logErr(t))
15841566
}
@@ -1587,8 +1569,7 @@ function Env(t, e) {
15871569
if (!this.isNode()) return {};
15881570
{
15891571
this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path");
1590-
const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile),
1591-
s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e);
1572+
const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e);
15921573
if (!s && !i) return {};
15931574
{
15941575
const i = s ? t : e;
@@ -1604,8 +1585,7 @@ function Env(t, e) {
16041585
writedata() {
16051586
if (this.isNode()) {
16061587
this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path");
1607-
const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile),
1608-
s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data);
1588+
const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data);
16091589
s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r)
16101590
}
16111591
}
@@ -1709,15 +1689,7 @@ function Env(t, e) {
17091689

17101690
time(t, e = null) {
17111691
const s = e ? new Date(e) : new Date;
1712-
let i = {
1713-
"M+": s.getMonth() + 1,
1714-
"d+": s.getDate(),
1715-
"H+": s.getHours(),
1716-
"m+": s.getMinutes(),
1717-
"s+": s.getSeconds(),
1718-
"q+": Math.floor((s.getMonth() + 3) / 3),
1719-
S: s.getMilliseconds()
1720-
};
1692+
let i = {"M+": s.getMonth() + 1, "d+": s.getDate(), "H+": s.getHours(), "m+": s.getMinutes(), "s+": s.getSeconds(), "q+": Math.floor((s.getMonth() + 3) / 3), S: s.getMilliseconds()};
17211693
/(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length)));
17221694
for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length)));
17231695
return t

0 commit comments

Comments
 (0)