优化代码

This commit is contained in:
黄志军
2021-11-13 01:41:22 +08:00
parent 191ff4e18b
commit ace15397b5
3 changed files with 60 additions and 14 deletions
+42 -5
View File
@@ -30,8 +30,8 @@ let postTime = 11
let postDay = 1
let cookiesArr = [], cookie = '', jdPlantBeanShareArr = [], isBox = false, notify, newShareCodes, option, subTitle;
let message = ""
let dingtalk1 = "https://oapi.dingtalk.com/robot/send?access_token=18444b555747aad3381bc1d1e3dea72b03158e152a846f818d82a1ca946bd430"
let dingtalk2 = "https://oapi.dingtalk.com/robot/send?access_token=04ab95f07aa0397e7167c6ea3a331bc7fcddbc4cda4a482b1e7e76755f97f6a0"
let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=18444b555747aad3381bc1d1e3dea72b03158e152a846f818d82a1ca946bd430"
let dingtalk1 = "https://oapi.dingtalk.com/robot/send?access_token=04ab95f07aa0397e7167c6ea3a331bc7fcddbc4cda4a482b1e7e76755f97f6a0"
let roleMap = {
"jd_4521b375ebb5d": "锟子怪",
"jd_542c10c0222bc": "康子怪",
@@ -110,10 +110,10 @@ let num;
$.log('', `${$.name}, 失败! 原因: ${e}!`, '')
}).finally(() => {
that.log(message)
postToDingTalk(message,dingtalk1)
postToDingTalk(message)
date = new Date()
if (date.getDay() == postDay && date.getHours() == postTime) {
postToDingTalk(message,dingtalk2)
postToDingTalk1(message)
}
$.done();
@@ -794,7 +794,7 @@ function Env(t, e) { "undefined" != typeof process && JSON.stringify(process.env
//我加的函数
function postToDingTalk(messgae,dingtalk) {
function postToDingTalk(messgae) {
const message1 = "" + messgae
that.log(messgae)
@@ -831,6 +831,43 @@ function postToDingTalk(messgae,dingtalk) {
}, "json")
}
function postToDingTalk1(messgae) {
const message1 = "" + messgae
that.log(messgae)
const body = {
"msgtype": "markdown",
"markdown": {
"title": "种豆得豆",
"text": message1
},
"at": {
"atMobiles": [],
"isAtAll": false
}
}
$.post(toDingtalk(dingtalk1 , JSON.stringify(body)), (data, status, xhr) => {
try {
that.log(resp)
that.log(data)
if (err) {
that.log(JSON.stringify(err));
$.logErr(err);
} else {
if (safeGet(data)) {
$.duckRes = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
}, "json")
}
function toDingtalk(urlmain, bodyMain) {
return {
+17 -8
View File
@@ -14,12 +14,17 @@
=========================Loon=============================
[Script]
cron "5 6-18/6 * * *" script-path=jd_fruit.js,tag=东东农场
=========================Surge============================
东东农场 = type=cron,cronexp="5 6-18/6 * * *",wake-system=1,timeout=3600,script-path=jd_fruit.js
=========================小火箭===========================
东东农场 = type=cron,script-path=jd_fruit.js, cronexpr="5 6-18/6 * * *", timeout=3600, enable=true
jd免费水果 搬的https://github.com/liuxiaoyucc/jd-helper/blob/a6f275d9785748014fc6cca821e58427162e9336/fruit/fruit.js
export DO_TEN_WATER_AGAIN="" 默认再次浇水
*/
const $ = new Env('东东农场');
let cookiesArr = [], cookie = '', jdFruitShareArr = [], isBox = false, notify, newShareCodes, allMessage = '';
@@ -43,6 +48,7 @@ let roleMap = {
"jd_66ea783827d30": "军子",
"jd_4311ac0ff4456": "居子"
}
//目前改成先号内互助 有多余次数互助池子
let message = '', subTitle = '', option = {}, isFruitFinished = false;
const retainWater = 100;//保留水滴大于多少g,默认100g;
@@ -66,6 +72,7 @@ const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%2
$.isLogin = true;
$.nickName = '';
await TotalBean();
username = $.UserName
if (roleMap[username] != undefined) {
username = roleMap[username]
@@ -74,6 +81,7 @@ const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%2
//加上名称
message = message + "<font color=\'#778899\' size=2>【羊毛姐妹】<font color=\'#FFA500\' size=3>" + username + " </font> </font> \n\n "
console.log(`\n开始【京东账号${$.index}${$.nickName || $.UserName}\n`);
if (!$.isLogin) {
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, { "open-url": "https://bean.m.jd.com/bean/signIndex.action" });
@@ -88,6 +96,7 @@ const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%2
//await shareCodesFormat();
await jdFruit();
}
message += "----\n\n"
that.log(message)
}
@@ -120,13 +129,10 @@ const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%2
$.log('', `${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
that.log(message)
postToDingTalk(message)
$.done();
postToDingTalk(message)
})
async function jdFruit() {
subTitle = `【京东账号${$.index}${$.nickName || $.UserName}`;
try {
@@ -155,9 +161,9 @@ async function jdFruit() {
//已下单购买, 但未开始种植新的水果
option['open-url'] = urlSchema;
$.msg($.name, ``, `【京东账号${$.index}${$.nickName || $.UserName}\n【提醒⏰】您忘了种植新的水果\n请去京东APP或微信小程序选购并种植新的水果\n点击弹窗即达`, option);
mes = "<font color=\'#778899\' size=2> " + getManName + ",你好\n\n【提醒⏰】您忘了种植新的水果\n请去京东APP或微信小程序选购并种植新的水果</font>"
postToDingTalk2(mes)
if ($.isNode()) {
mes = "<font color=\'#778899\' size=2> " + getManName + ",你好\n\n【提醒⏰】您忘了种植新的水果\n请去京东APP或微信小程序选购并种植新的水果</font>"
postToDingTalk2(mes)
await notify.sendNotify(`${$.name} - 您忘了种植新的水果`, `京东账号${$.index} ${$.nickName || $.UserName}\n【提醒⏰】您忘了种植新的水果\n请去京东APP或微信小程序选购并种植新的水果`);
}
return
@@ -179,6 +185,7 @@ async function jdFruit() {
} else {
console.log(`初始化农场数据异常, 请登录京东 app查看农场0元水果功能是否正常,农场初始化数据: ${JSON.stringify($.farmInfo)}`);
message = message + "<font color=\'#778899\' size=2> " + `初始化农场数据异常, 请登录动动 app查看农场0元水果功能是否正常,农场初始化数据: ${JSON.stringify($.farmInfo)}` + "</font>\n\n";
}
} catch (e) {
console.log(`任务执行异常,请检查执行日志 ‼️‼️`);
@@ -301,6 +308,7 @@ async function predictionFruit() {
$.farmInfo.farmUserPro.treeTotalEnergy) * 100).toFixed(2)}` + "%,已浇水" + `${$.farmInfo.farmUserPro.treeEnergy / 10}` + "次,还需" + `${($.farmInfo.farmUserPro.treeTotalEnergy - $.farmInfo.farmUserPro.treeEnergy) / 10}` + "次 </font> \n\n"
if ($.farmInfo.toFlowTimes > ($.farmInfo.farmUserPro.treeEnergy / 10)) {
message += "<font color=\'#BA55D3\' size=2>【水果🍉进度】" + `【开花进度】再浇水${$.farmInfo.toFlowTimes - $.farmInfo.farmUserPro.treeEnergy / 10}次开花\n\n` + "</font>\n\n"
} else if ($.farmInfo.toFruitTimes > ($.farmInfo.farmUserPro.treeEnergy / 10)) {
@@ -655,7 +663,7 @@ async function getExtraAward() {
}
} else {
console.log("已经领取过5好友助力额外奖励");
message += "<font color=\'#BA55D3\' size=2>【水果🍉进度】" + `【额外奖励】已被领取过\n` + "</font>\n\n";
message += "<font color=\'#BA55D3\' size=2>" + `【额外奖励】已被领取过\n` + "</font>\n\n";
}
} else {
console.log("助力好友未达到5个");
@@ -738,7 +746,7 @@ async function masterHelpShare() {
// helpSuccessPeoples = $.getdata(helpSuccessPeoplesKey);
// }
if (helpSuccessPeoples && helpSuccessPeoples.length > 0) {
message += "<font color=\'#778899\' size=2> " + `【您助力的好友👬】${helpSuccessPeoples.substr(0, helpSuccessPeoples.length - 1)}\n` + "</font>\n\n";
// message += `【您助力的好友👬】${helpSuccessPeoples.substr(0, helpSuccessPeoples.length - 1)}\n`;
}
if (salveHelpAddWater > 0) {
// message += `【助力好友👬】获得${salveHelpAddWater}g💧\n`;
@@ -1554,6 +1562,7 @@ function Env(t, e) { "undefined" != typeof process && JSON.stringify(process.env
//我加的函数
function postToDingTalk(messgae) {
const message1 = "" + messgae
+1 -1
View File
@@ -477,7 +477,7 @@ function try_MyTrials(page, selected) {
count++
}
if (item.text.text.includes('试用资格将保留10天')) {
message1 = "<font color=\'#8552a1\' size=1>" + `${getManName}` + "</font>\n\n"
message1 = "<font color=\'#8552a1\' size=1>" + getManName + "</font>\n\n"
message1 = "<font color=\'#4B0082\' size=1>" + `,你的商品待领取,请尽快领取` + "</font>\n\n"
message1 += "<font color=\'#ef5b9c\' size=1>" + `成功获取:${item.trialName}` + "</font>\n\n"
message1 += "<font color=\'#4B0082\' size=1>" + `剩余时间:${remaining(item.leftTime)}` + "</font>\n\n"