forked from xzhhbx/jsbox_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuantumultNoFA.js
335 lines (316 loc) · 10.8 KB
/
QuantumultNoFA.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
说明:
此脚本(QuantumultNoFA)仅用于更新Quantumult的Filter部分,可以免去每次Update都要设置的麻烦
1. 格式:正则(选择部分) = 替换(节点或Policy名)
2. 如果替换部分在Quantumult不存在,则默认是PROXY
例如:
把默认的PROXY统统改为“🍃 Proxy”,可以这么写:
,(?:PROXY|Proxy) = ,🍃 Proxy
*/
$app.autoKeyboardEnabled = true
const CONF = 'https://raw.githubusercontent.com/lhie1/Rules/master/Quantumult/Quantumult.conf'
const CACHEKEY = 'listData'
function urlsaveBase64Encode(url) {
return $text.base64Encode(url).replace(/\-/g, '+').replace(/\\/g, '_').replace(/=+$/, '')
}
const DEFAULT = [{
reg: { text: "选择Google的Policy,不懂就不选" },
rep: { text: "PROXY" }
}, {
reg: { text: "选择微软服务的Policy,不懂就选择DIRECT" },
rep: { text: "DIRECT" }
}, {
reg: { text: "选择PayPal的Policy,不懂就选择DIRECT" },
rep: { text: "DIRECT" }
}, {
reg: { text: "选择Apple的Policy,不懂就选择DIRECT" },
rep: { text: "DIRECT" }
}, {
reg: { text: "选择Netflix的Policy,不懂就不选" },
rep: { text: "PROXY" }
}, {
reg: { text: ",\s*(?:PROXY|Proxy)" },
rep: { text: ",PROXY" }
}, {
reg: { text: ",DIRECT" },
rep: { text: ",DIRECT" }
}, {
reg: { text: ",REJECT" },
rep: { text: ",REJECT" }
}]
let cacheData = $cache.get(CACHEKEY)
$ui.render({
props: {
title: "Quantumult",
navBarHidden: true,
statusBarStyle: 0
},
views: [{
type: "view",
props: {
id: "mainView"
},
layout: $layout.fill,
views: [{
type: 'list',
props: {
reorder: true,
data: cacheData || DEFAULT,
rowHeight: 60,
id: "mainList",
actions: [{
title: "delete",
handler: (sender, indexPath) => {
$cache.set(CACHEKEY, sender.data)
}
}],
footer: {
type: "view",
props: {
height: 65
}
},
template: {
props: {},
views: [{
type: "label",
props: {
id: "reg",
font: $font("bold", 16)
},
layout: (make, view) => {
make.height.equalTo(view.super.height).multipliedBy(0.5);
make.width.equalTo(view.super).offset(-30);
make.left.equalTo(view.super).offset(15);
make.top.equalTo(view.super);
}
}, {
type: "label",
props: {
id: "rep",
font: $font("bold", 16),
textColor: $color("#777")
},
layout: (make, view) => {
make.height.equalTo(view.super.height).multipliedBy(0.5);
make.width.equalTo(view.super).offset(-30);
make.left.equalTo(view.super).offset(15);
make.top.equalTo(view.prev.bottom)
}
}]
}
},
layout: (make, view) => {
make.height.equalTo(view.super).offset(-20)
make.width.equalTo(view.super)
make.centerX.equalTo(view.super)
make.top.equalTo(20)
},
events: {
didSelect: (sender, indexPath, data) => {
let item = sender.object(indexPath)
showAlterDialog(item.reg.text, item.rep.text, (newReg, newRep) => {
console.log(newReg, newRep)
let oldData = sender.data;
oldData[indexPath.row] = {
reg: { text: newReg },
rep: { text: newRep }
}
sender.data = oldData
$cache.set(CACHEKEY, sender.data)
})
},
reorderFinished: function (data) {
$cache.set(CACHEKEY, data)
}
}
}, {
type: 'button',
props: {
icon: $icon("165", $color("#fff"), $size(20, 20)),
id: 'genBtn',
radius: 25
},
layout: (make, view) => {
make.height.width.equalTo(50)
make.bottom.right.equalTo(view.super).offset(-15)
},
events: {
tapped: async _ => {
let pattern = $("mainList").data
try {
await startGen(pattern)
} catch (e) {
console.error(e.stack)
}
}
}
}, {
type: 'button',
props: {
icon: $icon("104", $color("#fff"), $size(20, 20)),
id: 'addBtn',
radius: 25
},
layout: (make, view) => {
make.height.width.equalTo(50)
make.bottom.equalTo(view.super).offset(-15)
make.right.equalTo(view.prev.left).offset(-15)
},
events: {
tapped: sender => {
showAlterDialog('', '', (newReg, newRep) => {
let oldData = $("mainList").data;
oldData.push({
reg: { text: newReg },
rep: { text: newRep }
})
$("mainList").data = oldData;
$cache.set(CACHEKEY, $("mainList").data)
})
}
}
}]
}]
})
function showAlterDialog(reg, rep, callback) {
let view = {
type: "blur",
layout: $layout.fill,
props: {
id: "alertBody",
style: 1,
alpha: 0
},
views: [{
type: "view",
props: {
id: "alterMainView",
bgcolor: $color("#ccc"),
smoothRadius: 10
},
layout: (make, view) => {
make.height.equalTo(250);
make.width.equalTo(view.super).offset(-60);
make.center.equalTo(view.super)
},
events: {
tapped: sender => { }
},
views: [{
type: "label",
props: {
text: "正则表达式",
font: $font("bold", 16)
},
layout: (make, view) => {
make.top.equalTo(view.super).offset(20);
make.left.equalTo(view.super).offset(10);
}
}, {
type: "input",
props: {
id: "alterInputReg",
text: reg,
autoFontSize: true
},
events: {
returned: sender => {
sender.blur()
}
},
layout: (make, view) => {
make.top.equalTo(view.prev.bottom).offset(10);
make.width.equalTo(view.super).offset(-20);
make.centerX.equalTo(view.super)
make.left.equalTo(view.super).offset(10);
make.height.equalTo(40)
}
}, {
type: "label",
props: {
text: "替换文本",
font: $font("bold", 16)
},
layout: (make, view) => {
make.top.equalTo(view.prev.bottom).offset(15);
make.left.equalTo(view.super).offset(10);
}
}, {
type: "input",
props: {
id: "alberInputRep",
text: rep,
autoFontSize: true
},
events: {
returned: sender => {
sender.blur()
}
},
layout: (make, view) => {
make.top.equalTo(view.prev.bottom).offset(10);
make.width.equalTo(view.super).offset(-20);
make.centerX.equalTo(view.super)
make.left.equalTo(view.super).offset(10);
make.height.equalTo(40)
}
}, {
type: 'button',
props: {
icon: $icon("064", $color("#fff"), $size(20, 20)),
id: 'confirmBtn',
radius: 25
},
layout: (make, view) => {
make.height.width.equalTo(50)
make.bottom.equalTo(view.super).offset(-15)
make.right.equalTo(view.super).offset(-15)
},
events: {
tapped: sender => {
callback && callback($("alterInputReg").text, $("alberInputRep").text);
$("alertBody").remove();
}
}
}]
}],
events: {
tapped: sender => {
sender.remove()
}
}
}
$("mainView").add(view)
$ui.animate({
duration: 0.2,
animation: () => {
$("alertBody").alpha = 1
}
})
}
async function startGen(pattern) {
let resp = await $http.get(CONF)
let data = resp.data
let patterns = pattern.map(i => {
return [i.reg.text, i.rep.text]
})
patterns.forEach(i => {
data = data.replace(new RegExp(i[0], 'g'), i[1])
})
console.log(data)
var success = $file.write({
data: $data({ string: data }),
path: "Fndroid.conf"
})
if (success) {
let result = await $http.startServer({})
let url = `http://127.0.0.1:${result.port}/download?path=Fndroid.conf`
let test = await $http.get(url)
const REJECT = 'https://raw.githubusercontent.com/lhie1/Rules/master/Quantumult/Quantumult_URL.conf'
if (test.data) {
let scheme = `quantumult://configuration?filter=${urlsaveBase64Encode(url)}&rejection=${urlsaveBase64Encode(REJECT)}`
$app.openURL(scheme)
}
}
}