-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathsmartReplace.js
153 lines (150 loc) · 7.08 KB
/
smartReplace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const axios = require("axios");
const fs = require("fs");
async function replaceWithSecrets(content, Secrets, ext) {
if (!Secrets || !Secrets) return content;
const replacements = [];
await init_notify(Secrets, content, replacements);
if (ext && typeof ext == "string") {
if (content.indexOf("require('./jdCookie.js')") > 0) {
replacements.push({ key: "require('./jdCookie.js')", value: `{CookieJD:'${ext}'}` });
}
if (content.indexOf("京东多合一签到") > 0 && content.indexOf("@NobyDa") > 0) {
replacements.push({ key: /var Key = ''/, value: `var Key = '${ext}'` });
}
} else {
if (Secrets.JD_COOKIE && content.indexOf("require('./jdCookie.js')") > 0) {
await download_jdcookie();
//replacements.push({ key: "require('./jdCookie.js')", value: JSON.stringify(Secrets.JD_COOKIE.split("&")) });
}
await downloader(content);
if (Secrets.MarketCoinToBeanCount && !isNaN(Secrets.MarketCoinToBeanCount)) {
let coinToBeanCount = parseInt(Secrets.MarketCoinToBeanCount);
if (coinToBeanCount >= 0 && coinToBeanCount <= 20 && content.indexOf("$.getdata('coinToBeans')") > 0) {
console.log("蓝币兑换京豆操作已注入");
replacements.push({ key: "$.getdata('coinToBeans')", value: coinToBeanCount });
}
}
if (Secrets.JoyFeedCount && !isNaN(Secrets.JoyFeedCount)) {
let feedCount = parseInt(Secrets.JoyFeedCount);
if ([10, 20, 40, 80].indexOf(feedCount) >= 0 && content.indexOf("$.getdata('joyFeedCount')") > 0) {
console.log("宠汪汪喂食操作已注入");
replacements.push({ key: "$.getdata('joyFeedCount')", value: feedCount });
}
}
if (Secrets.Unsubscribe) {
if (Secrets.Unsubscribe.split(",").length != 4) {
console.log("取关参数不正确,请参考readme中的提示填入,记得用英文逗号,隔开");
} else {
let usinfo = Secrets.Unsubscribe.split(",");
replacements.push({
key: "$.getdata('jdUnsubscribePageSize')",
value: isNaN(usinfo[0]) ? 0 : usinfo[0],
});
replacements.push({
key: "$.getdata('jdUnsubscribeShopPageSize')",
value: isNaN(usinfo[1]) ? 50 : usinfo[1],
});
replacements.push({ key: "$.getdata('jdUnsubscribeStopGoods')", value: `'${usinfo[2]}'` });
replacements.push({ key: "$.getdata('jdUnsubscribeStopShop')", value: `'${usinfo[3]}'` });
}
}
if (content.indexOf("function requireConfig()") >= 0 && content.indexOf("jd_bean_sign.js") >= 0) {
replacements.push({
key: "resultPath = err ? '/tmp/result.txt' : resultPath;",
value: `resultPath = err ? './tmp/result.txt' : resultPath;`,
});
replacements.push({
key: "JD_DailyBonusPath = err ? '/tmp/JD_DailyBonus.js' : JD_DailyBonusPath;",
value: `JD_DailyBonusPath = err ? './tmp/JD_DailyBonus.js' : JD_DailyBonusPath;`,
});
replacements.push({
key: "outPutUrl = err ? '/tmp/' : outPutUrl;",
value: `outPutUrl = err ? './tmp/' : outPutUrl;`,
});
}
}
return batchReplace(content, replacements);
}
function batchReplace(content, replacements) {
for (var i = 0; i < replacements.length; i++) {
content = content.replace(replacements[i].key, replacements[i].value);
}
return content;
}
async function init_notify(Secrets, content, replacements) {
if (!Secrets.PUSH_KEY && !Secrets.BARK_PUSH && !Secrets.TG_BOT_TOKEN) {
if (content.indexOf("require('./sendNotify')") > 0) {
replacements.push({
key: "require('./sendNotify')",
value:
"{sendNotify:function(){},serverNotify:function(){},BarkNotify:function(){},tgBotNotify:function(){}}",
});
}
} else {
await download_notify();
if (content.indexOf("京东多合一签到") > 0 && content.indexOf("@NobyDa") > 0) {
console.log("京东多合一签到通知注入成功");
replacements.push({
key: "var LogDetails = false;",
value: `const lxk0301Notify = require('./sendNotify');var LogDetails = false;`,
});
replacements.push({
key: `if (!$nobyda.isNode) $nobyda.notify("", "", Name + one + two + three + four + disa + notify);`,
value: `console.log("通知开始");lxk0301Notify.sendNotify("京东多合一签到", one + two + three + notify);console.log("通知结束");`,
});
}
}
}
async function downloader(content) {
if (content.indexOf("jdFruitShareCodes") > 0) {
await download_jdFruit();
}
if (content.indexOf("jdPetShareCodes") > 0) {
await download_jdPet();
}
if (content.indexOf("jdPlantBeanShareCodes") > 0) {
await download_jdPlant();
}
if (content.indexOf("jdSuperMarketShareCodes") > 0) {
await download_jdMarket();
}
}
async function download_jdcookie() {
let response = await axios.get("https://github.com/lxk0301/jd_scripts/raw/master/jdCookie.js");
let fcontent = response.data;
await fs.writeFileSync("./jdCookie.js", fcontent, "utf8");
console.log("下载京东cookie解析完毕");
}
async function download_notify() {
let response = await axios.get("https://github.com/lxk0301/jd_scripts/raw/master/sendNotify.js");
let fcontent = response.data;
await fs.writeFileSync("./sendNotify.js", fcontent, "utf8");
console.log("下载通知代码完毕");
}
async function download_jdFruit(content) {
let response = await axios.get("https://github.com/lxk0301/jd_scripts/raw/master/jdFruitShareCodes.js");
let fcontent = response.data;
await fs.writeFileSync("./jdFruitShareCodes.js", fcontent, "utf8");
console.log("下载农场分享码代码完毕");
}
async function download_jdPet(content) {
let response = await axios.get("https://github.com/lxk0301/jd_scripts/raw/master/jdPetShareCodes.js");
let fcontent = response.data;
await fs.writeFileSync("./jdPetShareCodes.js", fcontent, "utf8");
console.log("下载萌宠分享码代码完毕");
}
async function download_jdPlant(content) {
let response = await axios.get("https://github.com/lxk0301/jd_scripts/raw/master/jdPlantBeanShareCodes.js");
let fcontent = response.data;
await fs.writeFileSync("./jdPlantBeanShareCodes.js", fcontent, "utf8");
console.log("下载种豆得豆分享码代码完毕");
}
async function download_jdMarket(content) {
let response = await axios.get("https://github.com/lxk0301/jd_scripts/raw/master/jdSuperMarketShareCodes.js");
let fcontent = response.data;
await fs.writeFileSync("./jdSuperMarketShareCodes.js", fcontent, "utf8");
console.log("下载京小超分享码代码完毕");
}
module.exports = {
replaceWithSecrets,
};