This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClashWeb.ahk
577 lines (523 loc) · 16.2 KB
/
ClashWeb.ahk
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
SetWorkingDir %A_ScriptDir%
Process,Exist, clash-win64.exe ;
if ErrorLevel
{
}
else
{
gosub, MenuHandlerstartclash
}
Menu, Tray, Icon, clash-logo.ico,1,1
Menu, Tray, NoStandard
#Persistent ; 让脚本持续运行, 直到用户退出.
Menu, tray, Add, 切换节点, OpenWebBoard
Menu, tray, Add, 更新配置, Updateconfig
Menu, tray, Add, 配置管理, SetConfig
Menu, Tray, Add ; 创建分隔线.'
Menu, Submenu, Add, 启动Clash, MenuHandlerstartclash
Menu, Submenu, Add, 重载Clash, MenuHandlerrestartconfig
Menu, Submenu, Add, 关闭Clash, MenuHandlerstopclash
Menu, Submenu, Add, 重启Clash, MenuHandlerrestartclash
Menu, tray, add, Clash, :Submenu
Menu, Submenu2, Add, 开启系统代理, setsys
Menu, Submenu2, Add, 关闭系统代理, dissys
Menu, tray, add, 系统代理, :Submenu2
Menu, Submenu5, Add, 启动TUN, MenuHandlerStartTun
Menu, Submenu5, Add, 默认启动, defaultTun
Menu, Submenu5, Add, 取消默认, cancledefaultTun
Menu, Submenu5, Add, 取消TUN, MenuHandlerDeleteTun
Menu, tray, add, TUN管理, :Submenu5
Menu, Submenu1, Add, 查看IP, ShowIP
Menu, Submenu1, Add, 默认端口, EditDef
Menu, Submenu1, Add, 原版geoIP, updategeoIP
; Menu, Submenu1, Add, 添加规则, updategeoIP
Menu, Submenu1, Add, IPIPgeoIP, updateipgeoIP
Menu, Submenu1, Add, UWP设置, UWPProxy
Menu, tray, add, 其它设置, :Submenu1
Menu, Tray, Add ; 创建分隔线.
Menu, Tray, Click, OnClick
Menu, Tray, Add, 检查状态, OnClick
Menu, Tray, Add, 退出, MenuHandlerexit
Menu, Tray, Default, 检查状态
Menu, Tray, Add ; 创建分隔线.
OnClick: ;任务栏图标双击单击效果
if !LastClick
{
LastClick := 1
LastTC := A_TickCount
SetTimer,SingleClickEvent,-200
}
else if (A_TickCount-LastTC<200)
{
SetTimer,SingleClickEvent,off
gosub,DoubleClickEvent
}
return
SingleClickEvent:
LastClick := 0
Goto, checkclash
return
DoubleClickEvent:
LastClick := 0
Goto, OpenWebBoard
return
nothing:
return
; uploadquan:
; RunWait, %A_ScriptDir%\Bat\uploadquan.bat,,
; return
; *********About Tun *********
MenuHandlerStartTun:
IniWrite, tun, pref.ini, profile, currentState
gosub, MenuHandlerrestartclash
Return
defaultTun:
IniWrite, tun, pref.ini, profile, defaultState
goto, MenuHandlerStartTun
Return
cancledefaultTun:
IniWrite, general, pref.ini, profile, defaultState
goto, MenuHandlerDeleteTun
return
MenuHandlerDeleteTun:
gosub, DeleteTun
goto, MenuHandlerrestartclash
return
StartTun:
IniWrite, tun, pref.ini, profile, currentState
IniRead, configName, pref.ini, profile, configname, Default
RunWait, %A_ScriptDir%\Bat\settunconfig.bat %configName%,,Hide
return
DeleteTun:
IniWrite, general, pref.ini, profile, currentState
IniRead, configName, pref.ini, profile, configname, Default
FileDelete, Profile\selection\tun_%configname%.dat
return
; *********about ConfigSet********
; GuiClose:
; Gui, Destroy
; return
SetConfig:
Gui, Destroy
IniRead, Nt, pref.ini, profile, configname
Gui, Add, Text,, 当前配置为:%Nt%,双击配置文件进行下一步操作
Gui, Add, ListView,r10 w800 Multi AltSubmit gSelectConfigs, 名称|更新日期|大小|订阅地址
Gui, Add, Button, Default w80, 添加
Gui, Add, Button, xp+100 yp w80, 订阅转换
Gui, Add, Button, xp+100 yp w80, 打开目录
Loop, Profile\*.yaml
{
FileReadLine, oUrl, %A_ScriptDir%\Profile\%A_LoopFileName%, 1
cUrl := StrSplit(oUrl, ":http")
cUrl := cUrl[2]
cUrl = http%cUrl%
StringMid, monthmodi, A_LoopFileTimeModified, 5, 2
StringMid, datemodi, A_LoopFileTimeModified, 7, 2
StringMid, hourmodi, A_LoopFileTimeModified, 9, 2
StringMid, minmodi, A_LoopFileTimeModified, 11, 2
TimeModi = %monthmodi%/%datemodi% %hourmodi%:%minmodi%
LV_Add("", A_LoopFileName, TimeModi, A_LoopFileSizeKB, cUrl)
}
LV_ModifyCol() ; 根据内容自动调整每列的大小.
LV_ModifyCol(2,"100 Integer") ; 为了进行排序, 指出列 2 是整数.
; 显示窗口并返回. 每当用户点击一行时脚本会发出通知.
Gui, Show
return
Button添加:
Goto,Url
return
Url:
Gui, Destroy
Gui, Add, Text,, 配置名称,不支持中文(例如:nico):
Gui, Add, Edit,w500 vsubName
Gui, Add, Text,, 订阅链接:
Gui, Add, Edit,w500 vsubUrl
Gui, Add, Button, Default, 保存
Gui, Show
return
Button保存:
Gui, Submit
If (subUrl <> "" And subName <> ""){
Needle := ".yaml"
IfInString, subName, %Needle%
{
}
else
{
subName := subName ".yaml"
}
IniRead, subconverterName, pref.ini, own, sub, Default
RunWait, %A_ScriptDir%\Bat\updateconfig.bat %subconverterName% "%subUrl%" bieyongzhegemingzi_xiexie.yaml,,
FileEncoding, UTF-8-RAW
FileGetSize, configSize, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml,K
If configSize<1
{
MsgBox, 0, , 下载失败
}
else {
FileRead, currentConfig, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml
FileDelete, %A_ScriptDir%\Profile\%subName%
FileAppend, #托管地址:%subUrl%`n, %A_ScriptDir%\Profile\%subName% , UTF-8-RAW
FileAppend, %currentConfig%`n , %A_ScriptDir%\Profile\%subName%, UTF-8-RAW
currentConfig := ""
FileDelete, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml
}
}
Gui, Destroy
goto, SetConfig
return
Button订阅转换:
Run, %A_ScriptDir%\Bat\Subcon.bat,,Hide
Return
Button打开目录:
Run, %A_ScriptDir%\Profile
return
SelectConfigs:
if A_GuiEvent = DoubleClick
{
LV_GetText(NameText, A_EventInfo) ; 从行的第一个字段中获取文本.
LV_GetText(Urltext, A_EventInfo, 4)
If (%A_EventInfo%<>0){
Gui, Destroy
Gui, Add, Text,,
Gui, Add, Text,,
Gui, Add, Text,, 所选文件:%NameText%
Gui, Add, Text,,
Gui, Add, Text,,
Gui, Add, Button, Default w80, 启动
; Gui, Add, Button, xp+90 yp w80, 更新
Gui, Add, Button, xp+90 yp w80, 修改
Gui, Add, Button, xp+90 yp w80, 查看
Gui, Add, Button, xp+90 yp w80, 删除
Gui, Add, Button, xp+90 yp w80, 取消
Gui, Show
}
}
return
Button启动:
Gui, Submit
IniWrite, %NameText%, pref.ini, profile, configname
goto, MenuHandlerrestartconfig
return
Button修改:
Gui, Submit
Gui, Destroy
Gui, Add, Text,, 所选配置
Gui, Add,Edit, w500 va,%NameText%
Gui, Add, Text,, 订阅地址
Gui, Add,Edit, w500 vb,%Urltext%
Gui, Add, Button, Default w80, 确认修改
; Gui, Add, Button, xp+90 yp w80, 订阅/转换
Gui, Add, Button, xp+90 yp w80, 取消
Gui, Show
return
Button确认修改:
Gui, Submit
If (a <> "" And b <> ""){
Needle := ".yaml"
IfInString, a, %Needle%
{
}
else
{
a := a ".yaml"
}
IniRead, subconverterName, pref.ini, own, sub, Default
RunWait, %A_ScriptDir%\Bat\updateconfig.bat %subconverterName% "%b%" bieyongzhegemingzi_xiexie.yaml,,
FileEncoding, UTF-8-RAW
FileGetSize, configSize, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml,K
If configSize<1
{
MsgBox, 0, , 下载失败
}
else {
FileRead, currentConfig, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml
FileDelete, %A_ScriptDir%\Profile\%a%
FileAppend, #托管地址:%b%`n, %A_ScriptDir%\Profile\%a% , UTF-8-RAW
FileAppend, %currentConfig%`n , %A_ScriptDir%\Profile\%a%, UTF-8-RAW
currentConfig := ""
FileDelete, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml
}
; MsgBox, 0,, "%Nt%"`n所选配置:为当前配置,请更换当前配置`n"%NameText%"
}
IniRead, Nt, pref.ini, profile, configname
If (Nt != a)
{
Gui, Destroy
goto, SetConfig
}
else
{
Gui, Destroy
gosub, SetConfig
goto, MenuHandlerrestartconfig
}
return
Button删除:
Gui, Submit
IniRead, Nt, pref.ini, profile, configname
; MsgBox, 0,, "%Nt%"`n所选配置:为当前配置,请更换当前配置`n"%NameText%"
If (Nt != NameText)
{
MsgBox, 4,, 所选配置:%NameText%,是否删除
IfMsgBox, Yes
{
FileDelete, %A_ScriptDir%\Profile\%NameText%
FileDelete, %A_ScriptDir%\Profile\selection\%NameText%.dat
FileDelete, %A_ScriptDir%\Profile\selection\tun_%NameText%.dat
FileDelete, %A_ScriptDir%\Profile\providers
}
}
else
{
MsgBox, 0,, 所选配置:为当前配置,请更换当前配置
IfMsgBox, Yes
{
Gui, Destroy
goto, SetConfig
}
}
Gui, Destroy
goto, SetConfig
return
Button查看:
Gui, Submit
Run, open "%A_ScriptDir%\Profile\%NameText%"
goto,SetConfig
return
Button取消:
goto, SetConfig
return
; about *********
UWPProxy:
RunWait, %A_ScriptDir%\Bat\UWP.bat,,Hide
return
updategeoIP:
RunWait, %A_ScriptDir%\Bat\geoIP.bat
Goto, MenuHandlerrestartclash
return
ShowIP:
RunWait, %A_ScriptDir%\Bat\ShowIP.bat
Return
EditDef:
Run, open "%A_ScriptDir%\Profile\defaultconfig\default.yaml"
Return
updateipgeoIP:
RunWait, %A_ScriptDir%\Bat\ipipgeoIP.bat
Goto, MenuHandlerrestartclash
return
setsys:
RunWait, %A_ScriptDir%\Bat\setsys.bat,,Hide
Goto, checkclash
return
dissys:
; Menu, Tray, UnCheck,系统代理
RunWait, %A_ScriptDir%\Bat\dissys.bat,,Hide
; IniWrite, false, pref.ini, profile, sysState
Goto, checkclash
return
checkclash:
Process,Exist, clash-win64.exe ;
if ErrorLevel
{
ClashVar := "开-✅"
}
else
{
ClashVar := "关-❌"
}
RegRead, proxy,HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyEnable
if ( proxy > 0 )
{
ProxyVar := "开-✅"
}
else
{
ProxyVar := "关-❌"
}
IniRead, State, pref.ini, profile, currentState, Default
if (State = "tun") {
TapVar := "Tun模式"
}
else{
TapVar := "常规模式"
}
IniRead, configName, pref.ini, profile, configname, Default
TrayTip % Format("📢运行状态📢"),Clash状态:%ClashVar%`n系统 代理:%ProxyVar%`n连接 模式:%TapVar%`n当前 配置:%configName%
return
MenuHandlerstartclash:
Process,Exist, clash-win64.exe
if ErrorLevel
{
MsgBox, 0,, clash已启动!
}
else
{
IniRead, configName, pref.ini, profile, configname, Default
RunWait, %A_ScriptDir%\Bat\startclash.bat %configName%,,Hide
FileGetSize, configSize, %A_ScriptDir%\App\message.json,
If configSize
{
FileRead, Message, %A_ScriptDir%\App\message.json
MsgBox, 0, , %Message%`n请检查配置,已使用默认配置
Message := ""
FileDelete, %A_ScriptDir%\App\message.json
}
else
{
IniRead, State, pref.ini, profile, currentState, Default
if (State = "tun")
{
gosub, StartTun
RunWait, %A_ScriptDir%\Bat\restartconfig.bat tun_%configName%,,Hide
FileDelete, %A_ScriptDir%\Profile\tun_%configName%
FileDelete, %A_ScriptDir%\App\message.json
goto, dissys
}
else{
FileDelete, %A_ScriptDir%\App\message.json
goto, setsys
}
}
}
return
MenuHandlerstopclash:
MsgBox, 4,, 是否关闭clash和系统应用
IfMsgBox, Yes
{
IniRead, configName, pref.ini, profile, configname, Default
IniRead, State, pref.ini, profile, currentState, Default
if (State = "tun")
{
; gosub, StartTun
RunWait, %A_ScriptDir%\Bat\stop.bat tun_%configName%,,Hide
}
else{
RunWait, %A_ScriptDir%\Bat\stop.bat %configName%,,Hide
}
IniRead, dState, pref.ini, profile, defaultState, Default
If (dState != "tun"){
gosub, DeleteTun
}
IniWrite, %dState%, pref.ini, profile, currentState
}
return
MenuHandlerrestartclash:
IniRead, configName, pref.ini, profile, configname, Default
IniRead, State, pref.ini, profile, currentState, Default
if (State = "tun")
{
RunWait, %A_ScriptDir%\Bat\stop.bat tun_%configName%,,Hide
}
else{
RunWait, %A_ScriptDir%\Bat\stop.bat %configName%,,Hide
}
goto, MenuHandlerstartclash
return
MenuHandlerrestartconfig:
IniRead, configName, pref.ini, profile, configname, Default
IniRead, State, pref.ini, profile, currentState, Default
if (State = "tun")
{
gosub, StartTun
RunWait, %A_ScriptDir%\Bat\saveSelected.bat tun_%configName%,,Hide
RunWait, %A_ScriptDir%\Bat\restartconfig.bat tun_%configName%,,Hide
FileDelete, %A_ScriptDir%\Profile\tun_%configName%
FileGetSize, configSize, %A_ScriptDir%\App\message.json,
If configSize
{
FileRead, Message, %A_ScriptDir%\App\message.json
MsgBox, 0, , %Message%`n请检查配置,重载失败
Message := ""
FileDelete, %A_ScriptDir%\App\message.json
}
Else{
FileDelete, %A_ScriptDir%\App\message.json
goto, dissys
}
}
else{
RunWait, %A_ScriptDir%\Bat\saveSelected.bat %configName%,,Hide
RunWait, %A_ScriptDir%\Bat\restartconfig.bat %configName%,,Hide
FileGetSize, configSize, %A_ScriptDir%\App\message.json,
If configSize
{
FileRead, Message, %A_ScriptDir%\App\message.json
MsgBox, 0, , %Message%`n请检查配置,重载失败
Message := ""
FileDelete, %A_ScriptDir%\App\message.json
}
Else{
FileDelete, %A_ScriptDir%\App\message.json
goto, setsys
}
}
return
Updateconfig:
IniRead, subconverterName, pref.ini, own, sub, Default
IniRead, configName, pref.ini, profile, configname, Default
FileReadLine, oUrl, %A_ScriptDir%\Profile\%configName%, 1
cUrl := StrSplit(oUrl, ":http")
cUrl := cUrl[2]
cUrl = http%cUrl%
RunWait, %A_ScriptDir%\Bat\updateconfig.bat %subconverterName% "%cUrl%" bieyongzhegemingzi_xiexie.yaml,,
FileEncoding, UTF-8-RAW
FileGetSize, configSize, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml,K
If configSize<1
{
MsgBox, 0, , 下载失败
}
else {
FileRead, currentConfig, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml
FileDelete, %A_ScriptDir%\Profile\%configName%
FileAppend, #托管地址:%cUrl%`n, %A_ScriptDir%\Profile\%configName% , UTF-8-RAW
FileAppend, %currentConfig%`n , %A_ScriptDir%\Profile\%configName%, UTF-8-RAW
currentConfig := ""
FileDelete, %A_ScriptDir%\Profile\bieyongzhegemingzi_xiexie.yaml
goto, MenuHandlerrestartconfig
}
return
OpenWebBoard:
Process,Exist, clash-win64.exe ;
if ErrorLevel
{
Run, %A_ScriptDir%\Bat\OpenWeb.bat,,Hide
}
else
{
ClashVar := "关-❌"
TrayTip % Format("📢打开失败📢"),Clash:%ClashVar%`n请先启动Clash
}
return
MenuHandlerexit:
MsgBox, 4,, 是否退出
IfMsgBox, No
return
IniRead, configName, pref.ini, profile, configname, Default
IniRead, State, pref.ini, profile, currentState, Default
if (State = "tun")
{
RunWait, %A_ScriptDir%\Bat\stop.bat tun_%configName%,,Hide
}
else{
RunWait, %A_ScriptDir%\Bat\stop.bat %configName%,,Hide
}
IniRead, dState, pref.ini, profile, defaultState, Default
If (dState != "tun"){
gosub, DeleteTun
}
IniWrite, %dState%, pref.ini, profile, currentState
Gosub, checkclash
ExitApp