forked from ZVBY/MyActions-shuye72
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartReplace.js
283 lines (274 loc) · 10.7 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
const axios = require("axios");
const fs = require("fs");
const replacements = [];
var remoteContent;
async function init(content) {
remoteContent = content;
await inject();
return batchReplace(remoteContent);
}
//#region 注入代码
async function inject() {
await inject_jd();
}
async function inject_jd() {
if (!process.env.JD_COOKIE) return;
if (remoteContent.indexOf("function requireConfig()") >= 0 && remoteContent.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;`,
});
}
ignore_jd();
await downloader_jd();
await downloader_notify();
await downloader_user_agents();
}
function ignore_jd() {
// 京东JOY禁用部分Cookie,以避免被频繁通知需要去种植啥的
if (process.env.IGNORE_COOKIE_JDJOYPET) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_JDJOYPET);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "if (jdCookieNode[item]) {",
value: `if (jdCookieNode[item] && ${JSON.stringify(ignore_names)}.indexOf(item) == -1) {`,
});
console.log(`IGNORE_COOKIE_JDJOYPET已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_JDJOYPET填写有误,不禁用任何Cookie");
}
}
// 京喜农场禁用部分Cookie,以避免被频繁通知需要去种植啥的
if (process.env.IGNORE_COOKIE_JXNC) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_JXNC);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "if (jdCookieNode[item]) {",
value: `if (jdCookieNode[item] && ${JSON.stringify(ignore_names)}.indexOf(item) == -1) {`,
});
console.log(`IGNORE_COOKIE_JXNC已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_JXNC填写有误,不禁用任何Cookie");
}
}
// 京喜工厂禁用部分Cookie,以避免被频繁通知需要去种植啥的
if (process.env.IGNORE_COOKIE_JXGC) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_JXGC);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "cookiesArr.push(jdCookieNode[item])",
value: `if (jdCookieNode[item] && ${JSON.stringify(ignore_names)}.indexOf(item) == -1) cookiesArr.push(jdCookieNode[item])`,
});
console.log(`IGNORE_COOKIE_JXGC已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_JXGC填写有误,不禁用任何Cookie");
}
}
// 京东种豆得豆禁用部分Cookie,以避免黑号报错跳出的
if (process.env.IGNORE_COOKIE_ZDDD) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_ZDDD);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "cookiesArr.push(jdCookieNode[item])",
value: `if (jdCookieNode[item] && ${JSON.stringify(ignore_names)}.indexOf(item) == -1) cookiesArr.push(jdCookieNode[item])`,
});
console.log(`IGNORE_COOKIE_ZDDD已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_ZDDD填写有误,不禁用任何Cookie");
}
}
// 口袋书店禁用部分Cookie
if (process.env.IGNORE_COOKIE_NIAN) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_NIAN);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "cookiesArr.push(jdCookieNode[item])",
value: `if (jdCookieNode[item] && ${JSON.stringify(
ignore_names
)}.indexOf(item) == -1) cookiesArr.push(jdCookieNode[item])`,
});
console.log(`IGNORE_COOKIE_NIAN已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_NIAN填写有误,不禁用任何Cookie");
}
}
// 京东农场禁用部分Cookie
if (process.env.IGNORE_COOKIE_JDNC) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_JDNC);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "cookiesArr.push(jdCookieNode[item])",
value: `if (jdCookieNode[item] && ${JSON.stringify(
ignore_names
)}.indexOf(item) == -1) cookiesArr.push(jdCookieNode[item])`,
});
console.log(`IGNORE_COOKIE_JDNC已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_JDNC填写有误,不禁用任何Cookie");
}
}
// 京东工厂禁用部分Cookie
if (process.env.IGNORE_COOKIE_JDGC) {
try {
var ignore_indexs = JSON.parse(process.env.IGNORE_COOKIE_JDGC);
var ignore_names = [];
ignore_indexs.forEach((it) => {
if (it == 1) {
ignore_names.push("CookieJD");
} else {
ignore_names.push("CookieJD" + it);
}
});
replacements.push({
key: "cookiesArr.push(jdCookieNode[item])",
value: `if (jdCookieNode[item] && ${JSON.stringify(ignore_names)}.indexOf(item) == -1) cookiesArr.push(jdCookieNode[item])`,
});
console.log(`IGNORE_COOKIE_JDGC已生效,将为您禁用${ignore_names}`);
} catch (e) {
console.log("IGNORE_COOKIE_JDGC填写有误,不禁用任何Cookie");
}
}
}
function batchReplace() {
for (var i = 0; i < replacements.length; i++) {
remoteContent = remoteContent.replace(replacements[i].key, replacements[i].value);
}
// console.log(remoteContent);
return remoteContent;
}
//#endregion
//#region 文件下载
async function downloader_jd() {
if (/require\(['"`]{1}.\/jdCookie.js['"`]{1}\)/.test(remoteContent))
await download("https://github.com/shuye73/MyActions/raw/main/jdCookie.js", "./jdCookie.js", "京东Cookies");
if (remoteContent.indexOf("jdFruitShareCodes") > 0) {
await download(
"https://github.com/shuye73/MyActions/raw/main/jdFruitShareCodes.js",
"./jdFruitShareCodes.js",
"东东农场互助码"
);
}
if (remoteContent.indexOf("jdPetShareCodes") > 0) {
await download(
"https://github.com/shuye73/MyActions/raw/main/jdPetShareCodes.js",
"./jdPetShareCodes.js",
"京东萌宠"
);
}
if (remoteContent.indexOf("jdPlantBeanShareCodes") > 0) {
await download(
"https://github.com/shuye73/MyActions/raw/main/jdPlantBeanShareCodes.js",
"./jdPlantBeanShareCodes.js",
"种豆得豆互助码"
);
}
if (remoteContent.indexOf("jdSuperMarketShareCodes") > 0)
await download(
"https://github.com/shuye73/MyActions/raw/main/jdSuperMarketShareCodes.js",
"./jdSuperMarketShareCodes.js",
"京小超互助码"
);
if (remoteContent.indexOf("jdFactoryShareCodes") > 0) {
await download(
"https://github.com/shuye73/MyActions/raw/main/jdFactoryShareCodes.js",
"./jdFactoryShareCodes.js",
"东东工厂互助码"
);
}
if (remoteContent.indexOf("jdDreamFactoryShareCodes") > 0) {
await download(
"https://github.com/shuye73/MyActions/raw/main/jdDreamFactoryShareCodes.js",
"./jdDreamFactoryShareCodes.js",
"京喜工厂互助码"
);
}
if (remoteContent.indexOf("new Env('京喜农场')") > 0) {
await download(
"https://github.com/shuye73/MyActions/raw/main/jdJxncTokens.js",
"./jdJxncTokens.js",
"京喜农场Token"
);
await download(
"https://github.com/shuye73/MyActions/raw/main/jdJxncShareCodes.js",
"./jdJxncShareCodes.js",
"京喜农场分享码"
);
await download(
"https://github.com/shuye73/MyActions/raw/main/USER_AGENTS.js",
"./USER_AGENTS.js",
"USER_AGENTS"
);
}
}
async function downloader_notify() {
await download("https://github.com/shuye73/MyActions/raw/main/sendNotify.js", "./sendNotify.js", "统一通知");
}
async function downloader_user_agents() {
await download("https://github.com/shuye73/MyActions/raw/main/USER_AGENTS.js", "./USER_AGENTS.js", "云端UA");
}
async function download(url, path, target) {
let response = await axios.get(url);
let fcontent = response.data;
await fs.writeFileSync(path, fcontent, "utf8");
console.log(`下载${target}完毕`);
}
//#endregion
module.exports = {
inject: init,
};