-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathFeiRuoNet.uc.js
3752 lines (3724 loc) · 192 KB
/
FeiRuoNet.uc.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
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name FeiRuoNet.uc.js
// @description 网络交互信息定义
// @author feiruo
// @License Version: MPL 2.0/GPL 3.0/LGPL 2.1
// @compatibility Firefox 16
// @charset UTF-8
// @include chrome://browser/content/browser.xul
// @id [9AA866B3]
// @inspect window.FeiRuoNet
// @startup window.FeiRuoNet.init();
// @shutdown window.FeiRuoNet.uninit();
// @optionsURL about:config?filter=FeiRuoNet.
// @config window.FeiRuoNet.OpenPref('Preferences');
// @homepageURL https://www.feiruo.pw/UserChromeJS/FeiRuoNet.html
// @homepageURL https://github.com/feiruo/userChromeJS/tree/master/FeiRuoNet
// @downloadURL https://github.com/feiruo/userChromeJS/raw/master/FeiRuoNet/FeiRuoNet.uc.js
// @note Begin 2015-10-15
// @note 网络交互信息定义,查看、自定义与网站之间的交互信息。
// @note 显示网站IP地址和所在国家国旗,支持IPV6,标示https安全等级,帮助识别网站真实性。
// @note 修改浏览器标识(UA)、Cookies、Referer,伪装IP,等Http头信息。
// @note 破解反盗链,破解限制等,酌情善用。
// @note 左键点击图标查看详细信息,中键打开GET/POST界面,右键弹出菜单。
// @note 更多功能需要【_FeiRuoNet.js】、【_FeiRuoNetMenu.js】、【FeiRuoNetLib.js】、【QQWry.dat】、【ip4.cdb】、【ip6.cdb】、【_FeiRuoNetProxy.json】、【_GFWList.txt】配置文件。
// @note 仅供个人测试、研究,不得用于商业或非法用途,作者不承担因使用此脚本对自己和他人造成任何形式的损失或伤害之任何责任。
// @version 0.1.0 2016.10.31 10:30 Add Proxy Local and Refresh DNS, Fix for E10S and more。
// @version 0.0.9 2016.10.13 20:30 Fix for more。
// @version 0.0.8 2016.08.03 15:30 修改代理机制,兼容其他代理功能扩展脚本(Autoproxy、pan扩展等)。
// @version 0.0.7 2016.04.11 16:00 优化IP数据库读取缓存机制,国旗和地址使用同源,添加状态提示,自定义图标格式,自定义图标条件。
// @version 0.0.6 2016.04.09 15:00 菜单部分不再内置,需要Anobtn支持,增加家在状态,优化Tip逻辑,多窗口逻辑,减少资源消耗。
// @version 0.0.5 2016.03.20 15:00 增加GFWlist支持,优化加速智能代理逻辑,直接监听请求结果,错误直接代理。
// @version 0.0.4 2016.03.24 19:00 去除代理,fix bugs。
// @version 0.0.3 2016.03.15 15:00 完善头部、代理逻辑,取消使用CPOW。
// @version 0.0.2 2016.02.28 17:00 修复反盗链,修正查询,修正编辑。
// @version 0.0.1 2015.10.20 17:00 Building。
// ==/UserScript==
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 2.0/GPL 3.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the userChromeJS utilities.
*
* The Initial Developer of the Original Code is
* feiruo <[email protected]>
*
* Portions created by the Initial Developer are Copyright (C) 2015
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
location == "chrome://browser/content/browser.xul" && (function(CSS) {
let {
classes: Cc,
interfaces: Ci,
utils: Cu,
results: Cr
} = Components;
if (!window.Services) Cu.import("resource://gre/modules/Services.jsm");
if (!window.AddonManager) Cu.import("resource://gre/modules/AddonManager.jsm");
if (!window.UserAgentOverrides) Cu.import("resource://gre/modules/UserAgentOverrides.jsm");
if (!window.FileUtils) Cu.import("resource://gre/modules/FileUtils.jsm");
if (!window.XPCOMUtils) Cu.import("resource://gre/modules/XPCOMUtils.jsm");
if (!window.Promise) Cu.import("resource://gre/modules/Promise.jsm");
if (!window.NetUtil) Cu.import("resource://gre/modules/NetUtil.jsm");
if (!window.Downloads) Cu.import("resource://gre/modules/Downloads.jsm");
// 刷新dns: FeiRuoNet.RefreshDNS();
// 当前页启用/禁用代理: FeiRuoNet.SetNewProxy();
// 全局禁用/智能/开启: FeiRuoNet.ProxyModeSwitch();
if (window.FeiRuoNet) {
window.FeiRuoNet.onDestroy();
delete window.FeiRuoNet;
}
const IoSrv = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
const WinM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
const HttpSrv = Cc['@mozilla.org/network/protocol;1?name=http'].getService(Ci.nsIHttpProtocolHandler);
const ProxySrv = Cc['@mozilla.org/network/protocol-proxy-service;1'].getService(Ci.nsIProtocolProxyService);
const DnsService = Cc["@mozilla.org/network/dns-service;1"].createInstance(Ci.nsIDNSService);
const EventQueue = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager).currentThread;
const ETLDService = Cc["@mozilla.org/network/effective-tld-service;1"].getService(Ci.nsIEffectiveTLDService);
const FileInputStream = Components.Constructor("@mozilla.org/network/file-input-stream;1", "nsIFileInputStream", "init");
const ConverterInputStream = Components.Constructor("@mozilla.org/intl/converter-input-stream;1", "nsIConverterInputStream", "init");
const FileOutputStream = Components.Constructor("@mozilla.org/network/file-output-stream;1", "nsIFileOutputStream", "init");
const ConverterOutputStream = Components.Constructor("@mozilla.org/intl/converter-output-stream;1", "nsIConverterOutputStream", "init");
var FeiRuoNet = {
Prefs: Services.prefs.getBranch("userChromeJS.FeiRuoNet."),
DEFAULT_FlagS: "chrome://branding/content/icon16.png",
DBAK_FLAG_PATH: "http://www.razerzone.com/asset/images/icons/flags/",
DefaultFaviconVisibility: $("page-proxy-favicon") ? $("page-proxy-favicon").style.visibility : "visible",
FireFoxVer: (parseInt(Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).version.substr(0, 3) * 10, 10) / 10),
get MenuFile() {
let aFile = FileUtils.getFile("UChrm", ["lib", '_FeiRuoNetMenu.js']);
try {
this.MenuFile_ModifiedTime = aFile.lastModifiedTime;
} catch (e) {}
delete this.MenuFile;
return this.MenuFile = aFile;
},
get ConfFile() {
let aFile = FileUtils.getFile("UChrm", ["lib", '_FeiRuoNet.js']);
try {
this.ConfFile_ModifiedTime = aFile.lastModifiedTime;
} catch (e) {}
delete this.ConfFile;
return this.ConfFile = aFile;
},
get ProxyFile() {
let aFile = FileUtils.getFile("UChrm", ["lib", '_FeiRuoNetProxy.json']);
try {
this.ProxyFile_ModifiedTime = aFile.lastModifiedTime;
} catch (e) {}
delete this.ProxyFile;
return this.ProxyFile = aFile;
},
get GFWListFile() {
let aFile = FileUtils.getFile("UChrm", ["lib", '_GFWList.txt']);
try {
this.GFWListFile_ModifiedTime = aFile.lastModifiedTime;
} catch (e) {}
delete this.GFWListFile;
return this.GFWListFile = aFile;
},
get IsUsingUA() {
if (gPrefService.getPrefType("general.useragent.override") != 0) return gPrefService.getCharPref("general.useragent.override");
return null;
},
get CurrentURI() {
var topWindowOfType = WinM.getMostRecentWindow("navigator:browser");
if (topWindowOfType) return topWindowOfType.document.getElementById("content").currentURI;
return null;
},
get Content() {
var title = gBrowser.selectedTab.label || gBrowser.selectedBrowser.contentTitle;
var url = gBrowser.currentURI.spec || gBrowser.selectedBrowser.currentURI.spec;
var cont;
if (gMultiProcessBrowser) {
function listener(message) {
cont = message.objects.cont;
}
// var script = "data:application/javascript," + encodeURIComponent('sendAsyncMessage("FeiRuoNet:FeiRuoNet-e10s-content-message", {}, {cont: content,})');
var script = "data:application/javascript," + encodeURIComponent('sendAsyncMessage("FeiRuoNet:FeiRuoNet-e10s-content-message", {}, {cont: content,})');
gBrowser.selectedBrowser.messageManager.addMessageListener("FeiRuoNet:FeiRuoNet-e10s-content-message", listener);
gBrowser.selectedBrowser.messageManager.loadFrameScript(script, true);
// gBrowser.selectedBrowser.messageManager.broadcastAsyncMessage("FeiRuoNet:FeiRuoNet-e10s-content-message", listener);
// gBrowser.selectedBrowser.messageManager.removeMessageListener("FeiRuoNet:FeiRuoNet-e10s-content-message", listener);
// gBrowser.selectedBrowser.messageManager.removeDelayedFrameScript(script);
} else {
cont = window.content || gBrowser.selectedBrowser._contentWindow || gBrowser.selectedBrowser.contentWindowAsCPOW;
}
delete this.Content;
return this.Content = window.content || gBrowser.selectedBrowser._contentWindow || gBrowser.selectedBrowser.contentWindowAsCPOW;
},
get DirectProxy() {
delete this.DirectProxy;
return this.DirectProxy = ProxySrv.newProxyInfo('direct', '', -1, 0, 0, null) || null;
},
Initialization: function() {
var StartupTime = new Date();
this.Debug = this.GetPrefs(0, "Debug", false);
this.CacheReset(true);
this.IsMain = this.CheckMain();
if (this.IsMain) {
this.ReloadProxy(true);
}
this.init();
this.Services.init();
window.addEventListener("unload", function() {
FeiRuoNet.onDestroy();
}, false);
},
init: function() {
this.CreatePopup(true);
this.LoadSetting();
this.Rebuild();
},
uninit: function() {
this.Rebuild_UAChanger();
this.ReloadProxy();
this.CreatePopup();
this.CreateIcon();
if (this.GetWindow('Preferences')) this.GetWindow('Preferences').close();
this.UrlbarSafetyLevel = false;
},
onDestroy: function() {
this.Services.onDestroy();
this.AddStyle(false, 'Global');
this.SaveAutoProxyList();
this.CacheReset();
if (this.MutationObs) this.MutationObs.disconnect();
if (this.IsMain) this.uninit();
Services.appinfo.invalidateCachesOnRestart();
Services.obs.notifyObservers(null, "startupcache-invalidate", "");
},
CheckMain: function() {
var enumerator = WinM.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
if (win.FeiRuoNet && win.FeiRuoNet.IsMain) {
return false;
}
}
return true;
},
CacheReset: function(isAlert) {
var enumerator = WinM.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
if (win.FeiRuoNet && win.FeiRuoNet.IsMain) {
this.Caches = win.Caches;
this.DataBase = win.DataBase;
this.AutoProxy = win.AutoProxy;
}
}
if (!this.AutoProxy) {
this.AutoProxy = [];
this.AutoProxy.ProxyFilters = [];
this.AutoProxy.AutoProxyList = [];
this.AutoProxy.Filter = Filter;
this.AutoProxy.ActiveFilter = ActiveFilter;
this.AutoProxy.RegExpFilter = RegExpFilter;
this.AutoProxy.BlockingFilter = BlockingFilter;
this.AutoProxy.WhitelistFilter = WhitelistFilter;
this.AutoProxy.Matcher = Matcher;
this.AutoProxy.CombinedMatcher = CombinedMatcher;
}
if (!this.Caches) this.Caches = new Caches(['DNS', 'Onece', 'Query', 'IPInfo', 'Headers', 'HostInfo']);
if (!this.DataBase) {
this.DataBase = new Caches();
['CountryFlag', 'CountryName', 'QQwryDate', 'FlagFoxDB'].forEach(item => {
if (this.DataBase[item] && (item == 'QQwryDate' || item == 'FlagFoxDB')) this.DataBase[item].Clear();
this.DataBase[item] = {
__proto__: null
};
});
if (!isAlert) return;
var LibData = FeiRuoNet.LoadFile(FileUtils.getFile("UChrm", ["lib", 'FeiRuoNetLib.js']));
this.DataBase.CountryName = (LibData && LibData.CountryName) || {};
this.DataBase.CountryFlag = (LibData && LibData.CountryFlag) || {};
var QQWryFile = FileUtils.getFile("UChrm", ["lib", 'QQWry.dat']);
if (QQWryFile && QQWryFile.exists() && QQWryFile.isFile() && LibData) {
this.DataBase.QQwryDate = new QQwryDate(LibData.GBKCode, QQWryFile);
}
var IPDBmetadata = (LibData && LibData.IPDBmetadata) || {};
IPDBmetadata.countryIDs = (IPDBmetadata.countryIDs || "").match(new RegExp(".{1," + 2 + "}", "g"));
this.DataBase.FlagFoxDB = new FlagFoxDB(IPDBmetadata);
}
},
/*****************************************************************************************/
CreateIcon: function(IconPos) {
if (this.Icon_Pos === IconPos) return;
var icon = $("FeiRuoNet_icon");
if (icon) icon.parentNode.removeChild(icon);
delete icon;
if (this.Icon_Pos === 0 && $("page-proxy-favicon")) $("page-proxy-favicon").style.visibility = this.DefaultFaviconVisibility;
if (typeof IconPos == 'undefined') return false;
if (typeof IconPos == "number") this.Icon_Pos = IconPos;
var IconType = this.IconSstatusBarPanel ? 'statusbarpanel' : 'image';
if (this.Icon_Pos === 0) {
this.icon = $C(IconType, {});
$('identity-box').appendChild(this.icon);
} else if (this.Icon_Pos === 1) {
this.icon = $C(IconType, {});
$('urlbar-icons').appendChild(this.icon);
} else if (this.Icon_Pos === 2) {
this.icon = $C('toolbarbutton', {
class: 'toolbarbutton-1 chromeclass-toolbar-additional',
type: 'menu',
removable: true,
id: "FeiRuoNet_icon",
});
ToolbarManager.addWidget(window, this.icon, true);
}
this.icon.setAttribute('id', 'FeiRuoNet_icon');
this.icon.setAttribute('context', 'FeiRuoNet_Popup');
this.icon.setAttribute('tooltip', 'FeiRuoNet_Tooltip');
this.icon.setAttribute('onclick', 'if (event.button != 2) FeiRuoNet.IconClick(event);');
if (this.IconSstatusBarPanel) this.icon.setAttribute('class', 'statusbarpanel-iconic');
return true;
},
CreatePopup: function(enable) {
var Popup = $("FeiRuoNet_Popup");
if (Popup) Popup.parentNode.removeChild(Popup);
this.Popup = null;
delete Popup;
if (!enable) return;
this.Popup = $C("menupopup", {
id: "FeiRuoNet_Popup",
position: "bottomcenter topright",
onpopupshowing: "FeiRuoNet.PopupShowing(event);"
});
this.Popup.appendChild($C("menuitem", {
id: "FeiRuoNet_Copy",
label: "复制信息",
oncommand: "FeiRuoNet.CopyStr();",
image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAyklEQVQ4jZ3TQW7CMBCF4e8OlbKqwpKL9CBcBMVcqmuUHiAnQEKQrto70IUnKIAJSUeahT32b795No9RocNlRv4U9lvhjBYNUiEb7ANSBPSxcCqaZ4B3HLB9AUgDoIpTV6ixxgYfMR5qb88Anay5H+URp7u5zzvIFXCRG5awK2TCF77jJkVAM0NvPwVILwC7ANSjuasLcwEnubHbWN8uBRxldw5xm7NswCIJa/mdDNZWSwF1qfhfF24Ae9Mfp5U1FwG/5n3dTmgexx+GCF9o0H+IuAAAAABJRU5ErkJggg=="
}));
this.Popup.appendChild($C("menuitem", {
id: "FeiRuoNet_Rebuild",
label: "刷新信息",
oncommand: "FeiRuoNet.ShowFlag.LocationChange(true);",
image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA/ElEQVQ4jZXTMU5CQRDG8R8WFCAdvXAGb0IDB/AE9tDQeAIaO5tXcwAOYIiJtvR4ASKJCQSLnZcsz6fJfsm84s3Mf3e+3eW3uphigxeMWmr+VA9POOIV45JmeMQZ35iUNo+wwwXvGJYCpjgFoEKnpeY+4koDafZlNF+wQh+3GWiMt4grb9aSYfsM8IktnjNQleWr+AcecMiSdXxhFjULydw6d8YcN+IzbylYRPMsYM0FDrE4/2yxH2NsY6w6v4+x17kXbSZ1MtAqAyzD+IGGWo8pQPUOT9KRF2mIjwDscFcKmEjX+yxd9yKNJcOO0kPrlTSPpCe9kebuNgt+AGaeUCmcWxTfAAAAAElFTkSuQmCC"
}));
this.Popup.appendChild($C("menuitem", {
id: "FeiRuoNet_RefreshDNS",
label: "刷新DNS缓存",
onclick: "FeiRuoNet.RefreshDNS(event);",
tooltiptext: "左键:同时刷新页面。\n右键:仅刷新DNS缓存。",
image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABZElEQVQ4jXXSPUhXYRQG8J9fKSGFQzgYIggiGCUo6ZKBIkI0RQq5tRUViOCkg5tgoItGY9jSlhAtYeEQKLkEbuqgjWqgVoMfqcM9f7le7v+BA5fnfc7znue9h3y0oAv38QzP8QJ9KCnSc4FebGAPn/ALp1GbuB26XKMaLOIsagvv8D/FzaMHpXkGr1LCM3xAI36kuF3cKzb+I6yGcBsdMeprHEZNBncRoRK30Im7aMMERkN0NYx6JA/binEMFgxKMYwD/MMsKlCeM+EAfsaEqxHPNXxMZfyDBznNJZjOvNGMEP9Nkct4HFNk0YT1lHYN6rESxL5kD7Kows34fhkXHmCqIBjEEb5gKGoYT1CGh5iTbOMYPuMtagsG1XiDr5mMK2jAQoY/iQsuoQ7fM8JldON3hl/CjZyonkp2f0/yN76F8D2OI/cO+vOaSXaiUbJMbWgOvh0jkkW7gyvFDIqhDNfzDs4BDaxkbFlpu6cAAAAASUVORK5CYII="
}));
this.ProxyMenuitem = $C("menuitem", {
id: "FeiRuoNet_AutoProxy_Config",
label: "AutoProxy",
class: "FeiRuoNet menuitem-iconic",
onclick: "FeiRuoNet.ProxyIconClick(event);"
});
this.Popup.appendChild(this.ProxyMenuitem);
var UserAgentMenu = $C("menu", {
id: "FeiRuoNet_UserAgent_Config",
label: "UserAgent",
class: "FeiRuoNet menu-iconic",
hidden: "true"
});
UserAgentMenu.appendChild($C("menupopup", {
id: "FeiRuoNet_UserAgent_Popup"
}));
this.Popup.appendChild(UserAgentMenu);
this.SetMenuitem = $C("menuitem", {
id: "FeiRuoNet_SetPref",
label: "脚本设置",
class: "FeiRuoNet menuitem-iconic",
image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABYElEQVQ4jY3TO0/VQRAF8F9yTUB6QMCCZ6KJBq4JNIQKCkoopAWMsabhC1ho5SOYaO2j0AQ+gYKPS/BeaDD0kPhJLP7nbzZA0ElOsjvnzOzOziyX2yjO8Ds4i++/bRgdzAUdjFwVMIkNDASP8QuDwXF8Nb+RGHAdb3GC72jhIxZxLViMbx/fon2XWKv4inHcx6OaQH8A3eFWot3DmmT8jImipF48y21aeI6+gp9IzA+Ywmu0k7mBF9jBDKaxjZfhxqN9k1hULepgLI90gHvFic34BqJtR6tM0D6XYKrgJ/FT1ZFa+3cu7mALR6mtkf2n3KKZ9auihMPs79aPuIvbxYn9SbIfbOFGwd/CF1XbPVC1ZARL2XdFOIihrLuwjuVod/EQevBeNXmt1P8BC6ohamA+moNojqPpqa/UxCZuBk8iKkf5abihaMsuXbBh1UvPBm3/+EznbRSnqm9c49Lv/AcsoU6W+qo3pgAAAABJRU5ErkJggg==",
onclick: "FeiRuoNet.MenuItemClick(event);",
tooltiptext: "左键:打开设置窗口。\n中键:重载配置和菜单。\n右键:编辑配置。"
});
this.Popup.appendChild(this.SetMenuitem);
this.Popup.appendChild($C("menuseparator", {
id: "FeiRuoNet_Sepalator2",
hidden: "true"
}));
this.Tooltip = $C("tooltip", {
id: "FeiRuoNet_Tooltip",
onpopupshowing: "FeiRuoNet.TooltipShowing(event);"
});
$('mainPopupSet').appendChild(this.Tooltip);
$('mainPopupSet').appendChild(this.Popup);
this.AddStyle('Global', CSS);
},
TooltipShowing: function(event) {
if (event.target != FeiRuoNet.Tooltip || event.target != event.currentTarget) return;
while (FeiRuoNet.Tooltip.firstChild) FeiRuoNet.Tooltip.removeChild(FeiRuoNet.Tooltip.firstChild);
var grid = window.document.createElement("grid");
var rows = window.document.createElement("rows");
function addLabeledLine(labelID, lineValue) {
var row = window.document.createElement("row");
var label = window.document.createElement("label");
label.setAttribute("value", labelID.replace(" ", ''));
if (!!lineValue) {
var value = window.document.createElement("label");
value.setAttribute("value", lineValue.replace(" ", ''));
row.appendChild(label);
row.appendChild(value);
rows.appendChild(row);
} else rows.appendChild(label);
}
function ToFormat(str, isAlert) {
if (!str || str == "" || /^( )$/i.test(str)) return;
if (!isAlert && TipShow.C) addLabeledLine(TipShow.C);
if (str.indexOf('\n') != -1) {
var arr = str.split('\n');
arr.forEach(i => {
if (!!i && !/^( )$/i.test(i) && i != "") {
var n = i.indexOf(':');
if (n == -1) n = i.indexOf(':');
if (n != -1) addLabeledLine(i.substring(0, n + 1), i.substring(n + 1));
else addLabeledLine(i);
}
})
} else addLabeledLine(str);
}
var aLocation = FeiRuoNet.CurrentURI,
TipShow = FeiRuoNet.TipShow,
conv = FeiRuoNet.ConvStr(aLocation.scheme);
if (!conv) {
var host = aLocation.asciiHostPort || aLocation.HostPort || aLocation.hostPort || aLocation.host;
var obj = FeiRuoNet.Caches.Query[host] || {};
if (obj.Host && obj.Host != obj.IP) addLabeledLine(TipShow.Host, host);
addLabeledLine(TipShow.IP, obj.IP);
var ServerInfo = FeiRuoNet.GetHeaders(host);
if (ServerInfo && ServerInfo.length > 0) {
ServerInfo.forEach(info => {
addLabeledLine(info.label, info.value);
});
}
if (obj.IPAddrInfo && obj.IPAddrInfo !== "") ToFormat(obj.IPAddrInfo, true)
if (obj.ErrorStr && obj.ErrorStr != "") {
ToFormat(obj.ErrorStr);
} else {
FeiRuoNet.Caches.Query[host].ProxyTimes = 0;
}
FeiRuoNet.Caches.Query[host].ErrorStr = "";
var thx = [];
if (obj.IPAddrInfoThx) thx.push(FeiRuoNet.GetDomain(obj.IPAddrInfoThx, true))
if (obj.FlagThx && obj.FlagThx !== obj.IPAddrInfoThx) thx.push(obj.FlagThx)
if (FeiRuoNet.CustomInfos && obj.CustomInfo) {
for (var i in obj.CustomInfo) {
thx.push(FeiRuoNet.GetDomain(i, true));
if (typeof obj.CustomInfo[i] == 'string') ToFormat(obj.CustomInfo[i]);
else {
ToFormat(obj.CustomInfo[i].Port[FeiRuoNet.CurrentURI.Port]);
}
}
}
if (FeiRuoNet.Caches.Onece) {
for (var i in FeiRuoNet.Caches.Onece) {
thx.push(FeiRuoNet.GetDomain(i, true));
ToFormat(FeiRuoNet.Caches.Onece[i]);
}
}
if (thx.join('\n') !== "") {
if (TipShow.D) addLabeledLine(TipShow.D);
addLabeledLine(TipShow.Thk, new String(thx));
}
} else {
addLabeledLine(TipShow.Host, aLocation.spec);
addLabeledLine(conv.str);
}
grid.appendChild(rows);
FeiRuoNet.Tooltip.appendChild(grid);
},
PopupShowing: function(event) {
if (event.target != FeiRuoNet.Popup || event.target != event.currentTarget) return;
var URI = FeiRuoNet.CurrentURI;
var URL = URI.spec;
var UAItem = $("FeiRuoNet_UserAgent_Config");
UAItem.hidden = !FeiRuoNet.EnableUAChanger || !FeiRuoNet.UARules;
if (FeiRuoNet.UARules) {
$$(".FeiRuoNet_UsingUA").forEach(function(e) {
e.classList.remove('FeiRuoNet_UsingUA')
});
var idx;
for (var j in FeiRuoNet.UARules) {
if ((new RegExp(j)).test(URL)) {
idx = FeiRuoNet.UARules[j]
}
}
if (!FeiRuoNet.UAMenuSrc(idx, UAItem)) {
var UAList = FeiRuoNet.UAList,
IsUsingUA = FeiRuoNet.IsUsingUA;
for (var i = 0; i < UAList.length; i++) {
if (UAList[i].ua != "" && UAList[i].ua != IsUsingUA) continue;
if (UAList[i].ua == "" && !UAList[i].ua != !IsUsingUA) continue;
idx = i;
break;
}
if (!FeiRuoNet.UAMenuSrc(idx, UAItem)) {
UAItem.setAttribute("label", "未知UserAgent");
UAItem.setAttribute("tooltiptext", IsUsingUA);
UAItem.setAttribute("image", FeiRuoNet.Unknown_UAImage);
}
}
}
if (!this.MenuCreated && window.AnoBtn_BuildPopup) {
if (!this.PopupBuild) this.PopupBuild = new AnoBtn_BuildPopup('FeiRuoNet');
this.PopupBuild.Remove();
$("FeiRuoNet_Sepalator2").hidden = true;
if (!!this.MenuData && this.MenuData.Menus && this.MenuData.Menus.length > 0) {
$("FeiRuoNet_Sepalator2").hidden = false;
this.PopupBuild.Build(this.MenuData.Menus);
this.MenuCreated = true;
}
}
var ProxyItem = $('FeiRuoNet_AutoProxy_Config');
ProxyItem.setAttribute("onclick", "FeiRuoNet.ProxyIconClick(event);");
if (FeiRuoNet.ProxyMode == 0) {
ProxyItem.setAttribute("label", "代理功能关闭");
return;
} else if (!FeiRuoNet.ProxyScheme.test(URI.scheme)) {
ProxyItem.setAttribute("label", "此处禁用代理");
return;
} else {
var obj = FeiRuoNet.Caches.Query[URI.asciiHostPort || URI.HostPort || URI.hostPort || URI.host] || {};
if (!FeiRuoNet.ProxyLocal && /^((192\.168|172\.([1][6-9]|[2]\d|3[01]))(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2}|10(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){3})$/i.test(obj.IP))
return ProxyItem.setAttribute("label", "局域网禁用代理");
var topDomain = FeiRuoNet.GetDomain(URL);
var matchs = FeiRuoNet.AutoProxy.DefaultMatcher.matchesAny(URL, topDomain);
if (matchs && matchs instanceof FeiRuoNet.AutoProxy.WhitelistFilter) {
ProxyItem.setAttribute("label", topDomain + "在白名单");
// ProxyItem.setAttribute("label", "此站例外");
return;
} else if (matchs && matchs instanceof FeiRuoNet.AutoProxy.BlockingFilter) {
ProxyItem.setAttribute("value", true);
ProxyItem.filter = matchs;
ProxyItem.setAttribute("label", "在" + topDomain + "禁用");
// ProxyItem.setAttribute("label", "此站禁代");
return;
}
ProxyItem.setAttribute("value", "blocked");
ProxyItem.newfilter = [URL, topDomain];
ProxyItem.setAttribute("label", "对" + topDomain + "启用");
// ProxyItem.setAttribute("label", "代理此站");
}
},
LoadSetting: function(type) {
if (!type || type === "Icon_Pos") this.CreateIcon(this.GetPrefs(1, "Icon_Pos")) && type && FeiRuoNet.ShowFlag.LocationChange();
if (!type || type === "IconSstatusBarPanel") {
var IconSstatusBarPanel = this.GetPrefs(0, "IconSstatusBarPanel");
if (this.IconSstatusBarPanel != IconSstatusBarPanel) {
this.IconSstatusBarPanel = IconSstatusBarPanel;
this.CreateIcon(true);
if (type) FeiRuoNet.ShowFlag.LocationChange();
}
}
if (!type || type === "ApiIdx") {
var ApiIdx = this.GetPrefs(1, "ApiIdx");
if (this.ApiIdx == ApiIdx) return;
FeiRuoNet.ApiIdx = ApiIdx;
if (!!type) FeiRuoNet.ShowFlag.SetApi(this.Interfaces[FeiRuoNet.ApiIdx]) && FeiRuoNet.ShowFlag.LocationChange('Flags');
}
if (!type || type === "Inquiry_Delay") this.Inquiry_Delay = this.GetPrefs(1, "Inquiry_Delay", 1000);
if (!type || type === "BAK_FLAG_PATH") this.BAK_FLAG_PATH = this.GetPrefs(2, "BAK_FLAG_PATH", this.DBAK_FLAG_PATH);
if (!type || type === "BAK_FLAG_PATH_Format") this.BAK_FLAG_PATH_Format = this.GetPrefs(2, "BAK_FLAG_PATH_Format", 'gif');
if (!type || type === "IconShow") this.IconShow = new RegExp(this.GetPrefs(2, "IconShow", '^((ht|f)tps?|file|data|about|chrome)'), 'i');
if (!type || type === "ModifyHeader") this.ModifyHeader = this.GetPrefs(0, "ModifyHeader", true);
if (!type || type === "Debug") this.Debug = this.GetPrefs(0, "Debug");
if (!type || type === "CustomQueue") this.CustomQueue = this.GetPrefs(1, "CustomQueue", 0);
if (!type || type === "UrlbarSafetyLevel") this.UrlbarSafetyLevel = this.GetPrefs(0, "UrlbarSafetyLevel", true);
if (!type || type === "EnableUAChanger") this.EnableUAChanger = this.GetPrefs(0, "EnableUAChanger", true);
if (!type || type === "EnableRefChanger") this.EnableRefChanger = this.GetPrefs(0, "EnableRefChanger", true);
if (!type || type === "EnableProxyByError") this.EnableProxyByError = this.GetPrefs(0, "EnableProxyByError", true);
if (!type || type === "ProxyLocal") this.ProxyLocal = this.GetPrefs(0, "ProxyLocal", false);
if (!type || type === "ProxyTimes") this.ProxyTimes = this.GetPrefs(1, "ProxyTimes", 5);
if (!type || type === "ProxyTimer") this.ProxyTimer = this.GetPrefs(1, "ProxyTimer", 3500);
if (!type || type === "GFWListUrl") this.GFWListUrl = unescape(this.GetPrefs(2, "GFWListUrl", "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"));
if (!type || type === "ProxyScheme") this.ProxyScheme = new RegExp(this.GetPrefs(2, "ProxyScheme", '^(http|https|ftp|wss)$'), 'i');
if (!type || type === "ProxyServers") {
var ProxyServers = unescape(this.GetPrefs(2, "ProxyServers", "ShadowSocks|127.0.0.1|1080|socks|1;GoAgent|127.0.0.1|8087|http|1")).split(";");
if (!ProxyServers[0]) return;
this.ProxyServers = [];
for (var i in ProxyServers) {
var arr = ProxyServers[i].split("|"),
obj = {};
obj.name = arr[0];
obj.host = arr[1];
obj.port = arr[2];
obj.type = arr[3];
obj.remoteDNS = arr[4] ? arr[4] : 0;
obj.ProxyServer = ProxySrv.newProxyInfo(obj.type, obj.host, obj.port, obj.remoteDNS, this.ProxyTimer, null);
this.ProxyServers.push(obj);
}
}
if (!type || type === "DefaultProxy") {
this.DefaultProxy = this.GetPrefs(1, "DefaultProxy", 0);
this.ProxyModeIcon();
}
if (!type || type === "ProxyMode") {
this.ProxyMode = this.GetPrefs(1, "ProxyMode", 1);
this.ProxyModeIcon();
}
},
/*****************************************************************************************/
Rebuild: function(isAlert) {
this.MenuCreated = false;
this.MenuData = this.LoadFile(this.MenuFile, isAlert) || [];
var ConfData = this.LoadFile(this.ConfFile, isAlert) || {};
this.Icons = ConfData.Icons || {};
this.ServerInfo = ConfData.ServerInfo || [];
this.HeadRules = ConfData.HeadRules || {};
this.UASites = ConfData.UASites || {};
this.UAList = ConfData.UAList || [];
this.RefererChange = ConfData.RefererChange || [];
this.CustomInfos = ConfData.CustomInfos || [];
this.Interfaces = ConfData.Interfaces || [];
this.FeiRuoFunc = ConfData.FeiRuoFunc || function() {};
var TipShow = ConfData.TipShow || {};
this.DEFAULT_Flag = this.Icons.DEFAULT_Flag ? this.Icons.DEFAULT_Flag : this.DEFAULT_FlagS;
this.Unknown_Flag = this.Icons.Unknown_Flag ? this.Icons.Unknown_Flag : this.DEFAULT_Flag;
this.File_Flag = this.Icons.File_Flag ? this.Icons.File_Flag : this.DEFAULT_Flag;
this.Base64_Flag = this.Icons.Base64_Flag ? this.Icons.Base64_Flag : this.File_Flag;
this.LocahHost_Flag = this.Icons.LocahHost_Flag ? this.Icons.LocahHost_Flag : this.DEFAULT_Flag;
this.Mozilla_Flag = this.Icons.Mozilla_Flag ? this.Icons.Mozilla_Flag : this.DEFAULT_Flag;
this.Loading_Flag = this.Icons.Loading_Flag ? this.Icons.Loading_Flag : this.DEFAULT_Flag;
this.LAN_Flag = this.Icons.LAN_Flag ? this.Icons.LAN_Flag : this.DEFAULT_Flag;
this.Unknown_UAImage = this.Icons.Unknown_UAImage ? this.Icons.Unknown_UAImage : this.DEFAULT_Flag;
if (this.Interfaces && this.Interfaces[0]) {
this.Interfaces.forEach(function(api) {
if (api.isFlag) {
FeiRuoNet.ShowFlag.FlagApi = api.Api;
FeiRuoNet.ShowFlag.FlagFunc = api.Func;
}
})
}
this.TipShow = {
Host: TipShow.tipArrHost || "Host:",
IP: TipShow.tipArrIP || "IP:",
C: TipShow.tipArrSepC || "",
D: TipShow.tipArrSepEnd || "",
Thk: TipShow.tipArrThanks || "Thk:"
}
FeiRuoNet.ShowFlag.SetApi(this.Interfaces[this.ApiIdx] ? this.Interfaces[this.ApiIdx] : this.Interfaces[0]);
this.Rebuild_UAChanger(true);
FeiRuoNet.ShowFlag.LocationChange();
if (isAlert) alert('配置已经重新载入!');
},
Rebuild_UAChanger: function(isAlert) {
if (!this.UAList || !this.EnableUAChanger || (this.UAList && this.UAList.length == 0)) return;
$$("menuitem[id^='FeiRuoNet_UserAgent_']").forEach(e => {
e.parentNode.removeChild(e);
});
$$("menuseparator[id^='FeiRuoNet_UserAgent_']").forEach(e => {
e.parentNode.removeChild(e);
});
if (!isAlert) return;
this.UAList.unshift('{}');
var tmp = {};
tmp.label = Services.appinfo.name + Services.appinfo.version /*.split(".")[0] */ ;
tmp.ua = "";
tmp.image = this.Icons.DEFAULT_UA ? this.Icons.DEFAULT_UA : this.DEFAULT_Flag;
this.UAList.unshift(tmp);
var UANameIdxHash = [],
UAList = this.UAList,
menu = $("FeiRuoNet_UserAgent_Popup"),
menuitem;
if (UAList.length >= 2) {
for (let i = 0; i < UAList.length; i++) {
UANameIdxHash[UAList[i].label] = i;
if (UAList[i].label === "separator" || (!UAList[i].label && !UAList[i].id && !UAList[i].ua)) {
menuitem = $C("menuseparator", {
id: "FeiRuoNet_UserAgent_" + i,
class: "FeiRuoNet_UserAgent_menuseparator",
});
} else {
menuitem = $C("menuitem", {
label: UAList[i].label || ("UA_" + i),
id: "FeiRuoNet_UserAgent_" + i,
image: UAList[i].image || this.Unknown_UAImage,
tooltiptext: UAList[i].ua || "",
oncommand: "FeiRuoNet.SetUserAgent('" + i + "');"
});
var cls = menuitem.classList;
cls.add("FeiRuoNet_UserAgent_item");
cls.add("menuitem-iconic");
if (UAList[i].ua == this.IsUsingUA || (UAList[i].ua == "" && !UAList[i].ua == !this.IsUsingUA)) {
this.UAPerfAppVersion = this.Services.UaAppVersion(i);
this.Default_UAIdx = i;
}
}
menu.appendChild(menuitem);
menuitem = null;
}
this.UARules = {};
for (var j in this.UASites) {
this.UARules[j] = UANameIdxHash[this.UASites[j]] ? UANameIdxHash[this.UASites[j]] : this.Default_UAIdx;
}
$("FeiRuoNet_UserAgent_Config").hidden = false;
} else {
this.EnableUAChanger = false;
$("FeiRuoNet_UserAgent_Config").hidden = true;
}
},
/*****************************************************************************************/
MenuItemClick: function(event) {
if (event.target != FeiRuoNet.SetMenuitem || event.target != event.currentTarget) return;
event.stopPropagation();
event.preventDefault();
if (event.button == 0) FeiRuoNet.OpenPref('Preferences');
else if (event.button == 1) FeiRuoNet.Rebuild(true);
if (event.button == 2) FeiRuoNet.EditFile(0);
},
IconClick: function(event) {
if (event.target != FeiRuoNet.icon) return;
if (event.target != event.currentTarget) return;
if (event.button == 0) {
FeiRuoNet.CopyStr();
event.stopPropagation();
event.preventDefault();
} else if (event.button == 1) {
FeiRuoNet.ShowFlag.LocationChange(true);
}
if (event.button == 2) {
//$("FeiRuoNet_Popup").showPopup();
//event.stopPropagation();
//event.preventDefault();
}
},
ProxyIconClick: function(event) {
if (event.target != FeiRuoNet.ProxyMenuitem) return;
event.stopPropagation();
event.preventDefault();
switch (event.button) {
case 0:
if (FeiRuoNet.ProxyScheme.test(FeiRuoNet.CurrentURI.scheme) && FeiRuoNet.ProxyMode != 0) FeiRuoNet.SetUrlProxy(event);
break;
case 1:
break;
case 2:
FeiRuoNet.ProxyModeSwitch();
break;
}
},
SetUserAgent: function(val) {
if (val == 0) {
if (gPrefService.getPrefType("general.useragent.override") == 0 && gPrefService.getPrefType("general.platform.override") == 0) return;
gPrefService.clearUserPref("general.useragent.override");
gPrefService.clearUserPref("general.platform.override");
FeiRuoNet.Services.UAPerfAppVersion = false;
} else {
gPrefService.setCharPref("general.useragent.override", FeiRuoNet.UAList[val].ua);
FeiRuoNet.Services.UAPerfAppVersion = FeiRuoNet.Services.UaAppVersion(val);
var platform = FeiRuoNet.Services.getPlatformString(FeiRuoNet.UAList[val].ua);
if (platform && platform != "") gPrefService.setCharPref("general.platform.override", platform);
else gPrefService.clearUserPref("general.platform.override");
}
ShowStatus("浏览器标识(UserAgent)已切换至 [" + FeiRuoNet.UAList[val].label + "]");
FeiRuoNet.Default_UAIdx = val;
return;
},
UAMenuSrc: function(idx, UAItem) {
if ((idx != 0 && !idx) || !UAItem) return false;
$("FeiRuoNet_UserAgent_" + idx).classList.add("FeiRuoNet_UsingUA");
UAItem.setAttribute("label", FeiRuoNet.UAList[idx].label);
UAItem.setAttribute("image", FeiRuoNet.UAList[idx].image);
return true;
},
ProxyModeIcon: function() {
var ProxyItem = $('FeiRuoNet_AutoProxy_Config'),
PS = this.ProxyServers[this.DefaultProxy];
var tips = "[" + PS.name + "]" + PS.ProxyServer.host + ":" + PS.ProxyServer.port;
switch (this.ProxyMode) {
case 0:
ProxyItem.setAttribute("image", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAyVBMVEUAAADOAADOAADPAADNAADPAADLAQHQAADOAABIPz/OAADNAADOAADPAADNAADNAAC3DQ2/BgatEBDOAABrLi7LAQFDQUHPAADNAAAAaGjLAACMHx9kMTG0DAyoExM3R0fABga3Cwu/BwfNAADNAABEQkK9CAhLPT3VAABOPT3NAAAuS0tPPDw/RESoERE8RUVLPT3NAADXAADQAAA4R0duMTF0KyvFBgbNAABCQkI4RkbMAACjFBTBBQXGAwPbAADVAACoEhJoMDBwWI2hAAAAOHRSTlMAwlAJ8u/p/uP+5Lm3tSopDP799O3HwqotFxb9+vrs5+Lhz8zLx8G6uKKIhX1gVk9LST47MzAqE7JymfQAAAC+SURBVBjTbY/XksIwFENlx3ZC2oalLdt7p7drpxD4/48il7xyHs9oRhIaPJloXyfSQ0sq8qrslhWJGzBXgf9wb509HihIOS8ofxw+WevcHQkPkPnzZ/395WyjCpJArKbZwD90XCP6VQyoENiJ/XXHDSdz0wPIjIFbNn9AQIDufszOpvgHjAaSsr8GsHmpB95KRdzyCuanqEfv3JIJ/5fFeDsi3sFLKVoAWL5RmLbbBSkTGtV+ad9GPdKxzHCJE6b2FKK428+EAAAAAElFTkSuQmCC");
ProxyItem.setAttribute("tooltiptext", "当前代理: 无");
break;
case 1:
ProxyItem.setAttribute("image", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAXVBMVEUAAABCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkIBBsBYAAAAHnRSTlMAyw3sKOi0XN8D+vJZ5LmHQxrZ0MCveWBKlpGATzNsa7UnAAAAlElEQVQY02WPSRbDIAxDBQ4QIPPcSfc/Zs2jWfXvbEu2DMUG7+h8sKg0hhXT1LrlTVs61jAtD/lp1BW4HKddWQmAzwHxxUISekD6sudoye28RAC6GUonHIGegEvmDWA2fMboBNgpn3pswpS9arlCidseMTCUURpRPBaj5qhJhwvANGjS+5fsepfvX9TVeaH4ruj/+QKxzgqWH12ujAAAAABJRU5ErkJggg==");
ProxyItem.setAttribute("tooltiptext", "当前代理: 智能代理\n " + tips);
break;
case 2:
ProxyItem.setAttribute("image", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAZlBMVEUAAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADNAADJczcGAAAAIXRSTlMAyg3rtOZcKQP68+5ZJuDeuYdD2c7Ar31gSheWkXhPMx+30RQHAAAAlUlEQVQY02XPRRbDMAwE0DHGkIa5OPe/ZO24WfUvpXkCJNJqRaWtRHETLESFrGp5aXNFCvrxHn8ZCViOz01OLCygg4VbmXlFDSiT564tOW+7UgDVgaSO7IGGgPHiBeAQfDhnIrAwvsuyAUPQKcsJiZsXh442t3yP5CPRn3egatjtAIaOTXX9EowxgeKGQtbnt3XO//sCaoULwYAmMdEAAAAASUVORK5CYII=");
ProxyItem.setAttribute("tooltiptext", "当前代理: 全局代理\n " + tips);
break;
}
},
ProxyModeSwitch: function() {
var ProxyItem = $('FeiRuoNet_AutoProxy_Config');
switch (this.ProxyMode) {
case 0:
this.Prefs.setIntPref('ProxyMode', 1);
break;
case 1:
this.Prefs.setIntPref('ProxyMode', 2);
break;
case 2:
this.Prefs.setIntPref('ProxyMode', 0);
break;
}
setTimeout(function() {
ShowStatus(ProxyItem.getAttribute("tooltiptext"));
}, 100)
},
RefreshDNS: function(event) {
Downloads.getSummary(Downloads.ALL).then(summary => {
if (summary.allHaveStopped || confirm("有下载目前正在进行中。\n如果你刷新DNS现在下载会中断!你想继续吗?")) {
try {
IoSrv.offline = true;
Services.cache2.clear();
IoSrv.offline = false;
this.ShowFlag.LocationChange(true);
if (!event || (event && event.button != 2))
WinM.getMostRecentWindow("navigator:browser").getBrowser().reload();
} catch (e) {
ShowStatus("Error flushing DNS: " + e);
}
}
}).catch(exception => {
ShowStatus(exception);
})
},
/*****************************************************************************************/
UpdateGFWList: function() {
function errorCallback(result) {
log(result);
ShowStatus(result);
if (result == 'UPDATE_SUCCESS') {
ShowStatus("订阅规则更新成功!");
FeiRuoNet.ReloadProxy();
}
}
log("正在更新GFWList,请等待...");
ShowStatus("正在更新GFWList,请等待...", 5000);
let url = this.GFWListUrl
var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
let me = this;
request.onerror = function(event) {
setTimeout(function() {
errorCallback(request.statusText);
}, 0);
var error = request.statusText;
return error;
};
request.onload = function(event) {
try {
self._rawData = request.responseText;
if (!self._rawData) {
var error = '返回了一个空文件!';
setTimeout(function() {
errorCallback(error);
}, 0);
return;
}
self._rawData = self._rawData.replace(/[\r\n]/g, '');
self._rawData = WinM.getMostRecentWindow("").atob(self._rawData);
FeiRuoNet.StrToFile(FeiRuoNet.GFWListFile, self._rawData);
setTimeout(function() {
errorCallback('UPDATE_SUCCESS');
}, 0);
} catch (e) {
setTimeout(function() {
errorCallback(e.toString());
}, 0);
}
};
request.open("GET", url);
request.send(null);
},
SaveAutoProxyList: function() {
var aFile = this.ProxyFile;
this.AutoProxyListAct('Arrange');
const PR_WRONLY = 0x02;
const PR_CREATE_FILE = 0x08;
const PR_TRUNCATE = 0x20;
var rjson = {
CreatedBy: 'FeiRuoNetAutoProxy',
'注释': 'DisbledFilter并非白名单!!!仅为不代理效列表,可随时切换!',
'优先级': 'GFWList白名单 >> DisbledFilter >> ProxyFilters & GFWList',
DisbledFilter: [],
ProxyFilters: []
};
for (var i = 0; i < FeiRuoNet.AutoProxy.AutoProxyList.length; i++) {
if (FeiRuoNet.AutoProxy.AutoProxyList[i].disabled) rjson.DisbledFilter.push(FeiRuoNet.AutoProxy.AutoProxyList[i].text);
else rjson.ProxyFilters.push(FeiRuoNet.AutoProxy.AutoProxyList[i].text);
}
var fileStream = new FileOutputStream(aFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0);
var stream = new ConverterOutputStream(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
stream.writeString(JSON.stringify(rjson, null, 4));
stream.close();
},
ArrangeAutoProxyList: function(type, domain) {
var obj = {},
Info = [];
var Arr = FeiRuoNet.AutoProxy.AutoProxyList || [];
Arr.forEach(function(i) {
if (!obj[i.text]) {
obj[i.text] = true;
Info.push(i);
}
});
FeiRuoNet.AutoProxy.AutoProxyList = Info;
},
AutoProxyListAct: function(type, domain) {
var obj = {},
Info = [];
var Arr = FeiRuoNet.AutoProxy.AutoProxyList || [];
Arr.forEach(function(i) {
if (!obj[i.text]) {
switch (type) {
case 'Arrange':
obj[i.text] = true;
Info.push(i);
break;
case 'Remove':
if (domain && i.text != domain && !obj[i.text]) {
obj[i.text] = true;
Info.push(i);
}
break;
case 'RemoveDisable':
if (domain && !i._disabled && i.text == domain && !obj[i.text]) {
obj[i.text] = true;
Info.push(i);
}
break;
}
}
});
FeiRuoNet.AutoProxy.AutoProxyList = Info;
},
ReloadProxy: function(isAlert) {
try {
ProxySrv.unregisterFilter(FeiRuoNet.Services.ProxyFilter);
} catch (e) {}
FeiRuoNet.AutoProxy.DefaultMatcher && FeiRuoNet.AutoProxy.DefaultMatcher.clear();
if (!isAlert) return;
FeiRuoNet.AutoProxy.DefaultMatcher = new CombinedMatcher();
this.ImportFilters('ProxyFile');
this.ImportFilters('GFWListFile');
ProxySrv.registerFilter(FeiRuoNet.Services.ProxyFilter, 0);
},
CanNotProxy: function(amatch) {
if (amatch.disabled) return true;
else if (amatch instanceof FeiRuoNet.AutoProxy.WhitelistFilter) return true;
else return false;
},
SetNewProxy: function(URL, status) {
var URI = FeiRuoNet.CurrentURI || (gBrowser && gBrowser.selectedBrowser && gBrowser.selectedBrowser.currentURI);
if (!URI) return;
URL = URL || URI.spec;
var ishave, domain = FeiRuoNet.GetDomain(URL);
var ishave = false;
if (!!status) {
if (!URI || !/^((ht|f)tps?|about|chrome)/i.test(URI.scheme) || !URI.asciiHost) return;
var host = URI.asciiHostPort || URI.HostPort || URI.hostPort || URI.host;
if (FeiRuoNet.Caches.Query[host].ProxyTimes > FeiRuoNet.ProxyTimes) return;
FeiRuoNet.Caches.Query[host].ProxyTimes = FeiRuoNet.Caches.Query[host].ProxyTimes + 1;
}
if (!status) {
for (let i = 0; i < FeiRuoNet.AutoProxy.ProxyFilters.length; i++) {
if (FeiRuoNet.AutoProxy.ProxyFilters[i].matches(URL, domain)) {
if (FeiRuoNet.AutoProxy.ProxyFilters[i] instanceof FeiRuoNet.AutoProxy.WhitelistFilter) {
ishave = true;
break;
} else if (FeiRuoNet.AutoProxy.ProxyFilters[i].disabled) {
FeiRuoNet.AutoProxy.ProxyFilters[i].disabled = false;
if (FeiRuoNet.AutoProxy.ProxyFilters[i] instanceof FeiRuoNet.AutoProxy.RegExpFilter && !FeiRuoNet.AutoProxy.DefaultMatcher.hasFilter(FeiRuoNet.AutoProxy.ProxyFilters[i])) {
FeiRuoNet.AutoProxy.DefaultMatcher.add(FeiRuoNet.AutoProxy.ProxyFilters[i]);
FeiRuoNet.AutoProxy.AutoProxyList.push(FeiRuoNet.AutoProxy.ProxyFilters[i]);
FeiRuoNet.SaveAutoProxyList(true);
// FeiRuoNet.AutoProxyListAct('RemoveDisable', FeiRuoNet.AutoProxy.ProxyFilters[i].text);
}
ishave = true;
break;
} else {
FeiRuoNet.AutoProxy.ProxyFilters[i].disabled = 'true';
if (FeiRuoNet.AutoProxy.ProxyFilters[i].disabled && FeiRuoNet.AutoProxy.ProxyFilters[i] instanceof FeiRuoNet.AutoProxy.RegExpFilter && FeiRuoNet.AutoProxy.DefaultMatcher.hasFilter(FeiRuoNet.AutoProxy.ProxyFilters[i])) {
FeiRuoNet.AutoProxy.DefaultMatcher.remove(FeiRuoNet.AutoProxy.ProxyFilters[i]);
FeiRuoNet.AutoProxy.AutoProxyList.push(FeiRuoNet.AutoProxy.ProxyFilters[i]);
FeiRuoNet.SaveAutoProxyList(true);
}
ishave = true;
break;
}
}
}
}
if (!ishave) {
let filter = FeiRuoNet.AutoProxy.Filter.fromText(FeiRuoNet.AutoProxy.Filter.normalize(domain));
if (filter && filter instanceof FeiRuoNet.AutoProxy.RegExpFilter) {
FeiRuoNet.AutoProxy.ProxyFilters.push(filter);
if (!FeiRuoNet.AutoProxy.DefaultMatcher.hasFilter(filter)) {
FeiRuoNet.AutoProxy.DefaultMatcher.add(filter);
FeiRuoNet.AutoProxy.AutoProxyList.push(filter);
FeiRuoNet.SaveAutoProxyList(true);
}
}
}
FeiRuoNet.ShowFlag.LocationChange(true);
},
SetUrlProxy: function(event) {
var URI = FeiRuoNet.CurrentURI;
var tag = (event && event.target);
if (!FeiRuoNet.ProxyScheme.test(URI.scheme) || FeiRuoNet.ProxyMode == 0) {
return ShowStatus('不可代理!');
}
var obj = FeiRuoNet.Caches.Query[URI.asciiHostPort || URI.HostPort || URI.hostPort || URI.host] || {};
if (!FeiRuoNet.ProxyLocal && /^((192\.168|172\.([1][6-9]|[2]\d|3[01]))(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2}|10(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){3})$/i.test(obj.IP))
return ShowStatus("局域网禁用代理");
if (!tag) return FeiRuoNet.SetNewProxy(URI.spec);
if (!tag) tag = $('FeiRuoNet_AutoProxy_Config');
if (tag.value != "blocked") {
if (tag.filter) {
for (let i = 0; i < FeiRuoNet.AutoProxy.ProxyFilters.length; i++) {
if (FeiRuoNet.AutoProxy.ProxyFilters[i] == tag.filter) {
FeiRuoNet.AutoProxy.ProxyFilters[i].disabled = tag.value;
if (FeiRuoNet.AutoProxy.ProxyFilters[i].disabled && FeiRuoNet.AutoProxy.ProxyFilters[i] instanceof FeiRuoNet.AutoProxy.RegExpFilter && FeiRuoNet.AutoProxy.DefaultMatcher.hasFilter(FeiRuoNet.AutoProxy.ProxyFilters[i])) {
FeiRuoNet.AutoProxy.DefaultMatcher.remove(FeiRuoNet.AutoProxy.ProxyFilters[i]);