-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearchEngineJump.user.js
2336 lines (2145 loc) · 94.8 KB
/
searchEngineJump.user.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 SearchEngineJumpPlus 搜索引擎快捷跳转+
// @author NLF & 锐经(修改) & iqxin(修改) & MUTED64(修改)
// @contributor MUTED64
// @description Fork版本搜索引擎跳转脚本,优化一些使用体验
// @version 5.31.15
// @created 2011-07-02
// @lastUpdated 2023-06-13
// @namespace https://greasyfork.org/en/scripts/454280-searchenginejumpplus
// @homepage https://github.com/MUTED64/SearchEngineJumpPlus
// @require https://greasyfork.org/scripts/408009-togbk/code/toGBK.js?version=832799
// @require https://greasyfork.org/scripts/456710-searchenginejumpplusenginelist/code/SearchEngineJumpPlusEngineList.js?version=1177377
// @require https://greasyfork.org/scripts/456711-searchenginejumpplusrules/code/SearchEngineJumpPlusRules.js?version=1204556
// @resource GLOBAL_STYLE https://greasyfork.org/scripts/455977-searchenginejumpplusglobalstyle/code/SearchEngineJumpPlusGlobalStyle.user.css
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFSElEQVR4nMWXX4hdVxXGf2vfe89kJg61ia0DYzMTMWnoQ0FJtKmtJsFixT8DBSmYtGMLgq0PCqMEKwmxYzSGyUPBB7XRNi0FC6JtwYovgcS0klJD8SHakoExYhLQFkwn9/aeOfv7fDi3SStJ5o4muN4O7L32b33rz94H/s8WS10cvR3yVQaY++wnkESkwDK2sMy1EwXDtzRRziBhu+dGDG48smSA5kUP//wmAFIkrNwiGMOsBzYAQwTzEEeBY8BJO1fYtF+4laGPv/i/Afz1C1sAYwngZiKmsDcDI0DrHUtL4DRwMGAmUnVcCtpHPsrQbS/1DZDe+VFHblKziIjYBjwD3Iu5ARBwBjgJnAkwMAa+z+ZZqXEX8VZg0T784aUDzH3uk0DtVQvlVsMjwGpMB3gauAu8ieB2YDPwxR5gF/gQ+MeoNUFzACI4d+imvgDOp0BVRWo2AW62eRi8wvY/wNtrgGhDL+7a/gIcBLYBu4HrsPdSzr8K/JlcLk2BaCQstS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Avlakq5eiiX3eLtSXnFAABe3j1c/0PgTp1z77NUKmesjHMulKuttq9X/eq+sgAAx35wTZ0OqWNrWqr2KVelqoqcF3DOL1r5dStfHQCoW03K9ApuWrnam/PCnHN+StZDRHSK1jLgCnXBpeymr/8dS+SFbmH7eiu/TkQnNRrkqmL20XVXFwBg7QOzRASSsDJFaxndssPso+uu9tH92b8BowSyPc/iZtEAAAAASUVORK5CYII=
// @license MIT
// @noframes
// @match *://**/*
// @exclude *://mega.nz/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @grant GM_deleteValue
// @grant GM_setClipboard
// @grant GM_registerMenuCommand
// @grant GM_openInTab
// @grant GM_getResourceText
// @grant GM_info
// @grant window.onurlchange
// @run-at document-idle
// ==/UserScript==
(function () {
"use strict";
startScript();
listenUrlChange();
// For some websites with iframe and some websites need delay to load
function startScript() {
if (window.self != window.top) return;
console.info(
`\n%c ${GM_info.script.name} v${GM_info.script.version} \n%c 问题反馈(GitHub):\t\thttps://github.com/MUTED64/SearchEngineJumpPlus/issues/new\t\t\t\t\t\t\t\n%c 问题反馈(GreasyFork):\thttps://greasyfork.org/scripts/454280-searchenginejumpplus-搜索引擎快捷跳转/feedback\t\n`,
"color:#eee;background:#444;padding:6px 0;border-radius:6px 6px 0 0;",
"color:#444;background:#eee;padding:6px 0;border-radius:0 6px 0 0",
"color:#444;background:#eee;padding:6px 0;border-radius:0 0 6px 6px;"
);
const delayList = [
/^https?:\/\/google\.infinitynewtab\.com\/\?q/,
/^https?:\/\/www\.zhihu\.com\/search\?/,
/^https?:\/\/www\.iciba\.com\/word\?/,
/^https?:\/\/neeva\.com\/search\?/i,
/^https?:\/\/s\.taobao\.com\/search/,
/^https?:\/\/y\.qq\.com\/n\/ryqq\/search/i,
/^https?:\/\/www\.quora\.com\/search\?/i,
/^https?:\/\/search\.bilibili\.com\/*/,
/^https?:\/\/github\.com/i,
/^https?:\/\/(www\.)?baidu\.com/i,
];
const needDelay = delayList.some(
(delaySite) => location.href.search(delaySite) !== -1
);
if (needDelay) {
setTimeout(function () {
const isRunning = document.querySelector("sejspan");
if (isRunning) {
return;
} else {
mainLogic();
}
}, 1000);
} else {
mainLogic();
}
}
// For SPA websites with javascript router
function listenUrlChange() {
if (window.onurlchange === null) {
let lastURL = decodeURI(location.href).replaceAll(" ", "+");
window.addEventListener("urlchange", (e) => {
const newURL = decodeURI(e.url).replaceAll(" ", "+");
if (lastURL === newURL) return;
lastURL = newURL;
document.querySelectorAll("sejspan")?.forEach((i) => i.remove());
startScript();
});
}
}
function mainLogic() {
const rules = searchEngineJumpPlusRules;
let engineList = searchEngineJumpPlusEngines;
// 有些图标需要重复使用
const icon = {
edit: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAACDklEQVR4nJXVzUtUURjH8Y/mSNKkki2iwiApxHQ1q/6C+gusoCB6oxbRRqFNL4sWtRKqhVSLIDe1CqpNiwjKIilKLKKFEr2Z2qI0xxHN0+LOm+PMOPOc1T2H7/f5ncO991BdNer30zmxKrl0xV2zKJjRoy6aqkkvbbdVLPuUq+8+5uGXnVILki7qsxgtNDtrTNLcijHvrdYsft0/wQ8DZgSzeqMUDW4IJceYHcvwCd1ies0KZvWI1TnhIH6574Olgg0E74zmhZ902j304by4Cxp5LPjtQNmjy3XPVK2rgmCBCcGgdVXhdBgUBCMEwVMNVeIvBMFLifKC8vgrndFBlRJUhJcWFMd3ZfGuzFRxwWrdu3KTxQQVhi8lqApfKVhf0d4bc2/OckG9Pkur7r3TEw+1FRO0GxdM2Vc2/HHBgr1If935UTfigbt5+C27MeSo9+m5GJYitlCwWR2G8oQZ/FgWX1aFgnZMG852v5nFR4rhMn+2dDVJYFpKqy0SDksUhF9FsE0bWgyIa9bIanihoEUcDTrSz4ueOVMOLxQkzVkrZcaoNz755rmpcnihYNghm3w26Ys/5cGcIKgRBJDyqCIquj8C1PqKZvHK+qVrJ5bMRwmGterU64pkkZupWO3RjXkzUZj9+jVZMGK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eXm5ubn5+fo6Ojp6enq6urr6+vs7Ozt7e3u7u7v7+/w8PDx8fHy8vLz8/P09PT19fX29vb39/f4+Pj5+fn6+vr7+/v8/Pz9/f3+/v7///8dej9TAAAAU3RSTlMAAABm7P/sZgAAABPO////zhQAAB/i/////////+IfAAAe4fvk4AAAAAAd/+Q3GxwAFR85FQBjz+LPY+v////r6//////rZM/h4c9jABUdHRUAAP0EcPoAAAEuSURBVHic7ZRnc8IwDIbdEUZHGB0kDsMOMcOMttBBB93Qvcj//y9VjB0Czh13/dz3ixT5OVmSYyMktLK6tm74oYxEMpVGUW1sbm2bM8DMZHP5OWBnd2+/YNnYAWHbKhRL5cocQKjrWFWPuSDmVS3HpUQu1eoNQkiTM9xqd7oHoG6n3cKMNyHcqNfQ4VGPUsr7nh0FbK/PIdw7PkGnZwOZNrqF9AfnF+jyaigLixYp/eH1Dbq9u4eAHyOAHh5HaPz0DCnjANjm5fUNvX98QoGCxyo5Fjmh0K/vH2hzAi0KnqnymMgJrU6gzemQBM+DZpX1/XBYUyAYTTAuZTUg+Aw8Zf+BvwJLR730sPTjXgD0H2YB0BUClXKpGAeE1y+fy2ZMfX12gdOpZMLQAfkE/AL7e5vGZF+dOQAAAABJRU5ErkJggg==",
setting: `<svg style="width: 16px;" class="icon" id="sej-setting-button" viewBox="0 0 512 512"><path d="M262.29 192.31a64 64 0 1057.4 57.4 64.13 64.13 0 00-57.4-57.4zM416.39 256a154.34 154.34 0 01-1.53 20.79l45.21 35.46a10.81 10.81 0 012.45 13.75l-42.77 74a10.81 10.81 0 01-13.14 4.59l-44.9-18.08a16.11 16.11 0 00-15.17 1.75A164.48 164.48 0 01325 400.8a15.94 15.94 0 00-8.82 12.14l-6.73 47.89a11.08 11.08 0 01-10.68 9.17h-85.54a11.11 11.11 0 01-10.69-8.87l-6.72-47.82a16.07 16.07 0 00-9-12.22 155.3 155.3 0 01-21.46-12.57 16 16 0 00-15.11-1.71l-44.89 18.07a10.81 10.81 0 01-13.14-4.58l-42.77-74a10.8 10.8 0 012.45-13.75l38.21-30a16.05 16.05 0 006-14.08c-.36-4.17-.58-8.33-.58-12.5s.21-8.27.58-12.35a16 16 0 00-6.07-13.94l-38.19-30A10.81 10.81 0 0149.48 186l42.77-74a10.81 10.81 0 0113.14-4.59l44.9 18.08a16.11 16.11 0 0015.17-1.75A164.48 164.48 0 01187 111.2a15.94 15.94 0 008.82-12.14l6.73-47.89A11.08 11.08 0 01213.23 42h85.54a11.11 11.11 0 0110.69 8.87l6.72 47.82a16.07 16.07 0 009 12.22 155.3 155.3 0 0121.46 12.57 16 16 0 0015.11 1.71l44.89-18.07a10.81 10.81 0 0113.14 4.58l42.77 74a10.8 10.8 0 01-2.45 13.75l-38.21 30a16.05 16.05 0 00-6.05 14.08c.33 4.14.55 8.3.55 12.47z" fill="none" stroke="var(--font-color-qxin)" stroke-linecap="round" stroke-linejoin="round" stroke-width="42"/></svg>`,
};
const scriptSettingData = {
status: 1,
message:
"$相关说明$(status: 这个在将来或许很重要)..." +
"(version: 若有新功能加入,靠这个版本号识别)..." +
"(addSearchItems: 允许更新时,添加新的搜索网站到你的搜索列表)..." +
"(modifySearchItems: 允许更新时,修改你的搜索列表中的项目)..." +
"(closeBtn: 设置页面右上角的“关闭”按钮是否显示。true显示,false隐藏)..." +
"(newtab: 新标签页打开。0为默认设置,1为新标签页打开)..." +
"(foldlist: 折叠当前搜索分类列表。true为折叠,false为展开。)..." +
"(setBtnOpacity: 设置按钮的透明度,值为0-1之间的数,0为透明,1为完全显示,中间值半透明。注:-1为直接关闭按钮,关闭之前请确定自己知道如何再次打开它)..." +
"(debug: debug模式,开启后,控制台会输出一些信息,“关闭并保存”按钮将不会在刷新页面)..." +
"(fixedTop: 将搜索栏固定到顶端。 true开启,false关闭)..." +
"(fixedTopUpward: 固定顶端后,搜索栏下拉不会出现,只有上拉时才出现。 true开启,false关闭)..." +
"(baiduOffset: 在百度页面鼠标划过的菜单会出现位移,若有使用其他的style样式,可以修改这个来修复二级菜单的偏移)..." +
"(getIcon: 自己添加搜索后获取图标的方式。0为自动,能连接谷歌的情况下用谷歌获取,无法连接的情况下,域名加favicon.ico获取;1为域名加favicon获取,2为使用谷歌获取,3为使用dnspot的服务获取(不建议使用)。或者添加网址,关键字使用%s代替,未测试)..." +
"(allOpen:一键搜索,点击相关分类后,打开该分类下的所有搜索)..." +
"(HideTheSameLink:隐藏同站链接。默认开启,百度页面会隐藏百度搜索。如果想在同一个搜索网站,但是想通过不同语言来搜索, 可以选择false来实现)..." +
"(center:是否居中显示,主要是为了兼容脚本 ac 百度 : 0 不居中,强制在左。 1, 强制居中 。 2,自动判断)..." +
"(icon: 图标的显示方式, 0 关闭文字, 只保留图标, 1 显示网站图标,2 显示抽象图标。当脚本中不存在抽象图标时,显示网站图标)..." +
"(transtion: 是否有动画效果, true为开启所有动画效果,false关闭所有动画(包括模糊效果)。)" +
"(selectSearch: 划词搜索功能, true为开启划词搜索,false关闭)" +
"(engineDetails: 第一个值为分类列表标题名称,第二个值与enginelist相关联,必须匹配,第三个值true为显示列表,false为禁用列表。排列顺序与跳转栏上的显示顺序相同,可以用它将分类列表按自己喜欢排序)..." +
"(engineList: 各个搜索的相关信息)" +
"(rules: 已弃用--将搜索样式插入到目标网页,同脚本中的rules设置相同,优先级高于脚本中自带的规则。自带了360搜索,可仿写)...",
version: GM_info.script.version,
addSearchItems: true,
modifySearchItems: true,
closeBtn: true,
newtab: 0,
foldlist: true,
setBtnOpacity: 0.7,
debug: false,
fixedTop: true,
fixedTopUpward: false,
baiduOffset: -120,
getIcon: 0,
allOpen: false,
HideTheSameLink: true,
center: 2,
icon: 1,
transtion: true,
selectSearch: true,
engineDetails: [
["网页", "web", true],
["翻译", "translate", true],
["知识", "knowledge", true],
["图片", "image", true],
["视频", "video", true],
["音乐", "music", true],
["学术", "scholar", false],
["社交", "sociality", true],
["购物", "shopping", true],
["下载", "download", false],
["新闻", "news", false],
["常用", "mine", false],
],
engineList: engineList,
};
// --------------------可设置项结束------------------------
class Settings {
#storedSettingData = GM_getValue("searchEngineJumpData");
#scriptSettingData = scriptSettingData;
settingData;
constructor() {
this.initSettings();
}
#isVersionOutdated(storedSettingVersion, currentVersion) {
storedSettingVersion = storedSettingVersion.toString();
currentVersion = currentVersion.toString();
const arr1 = storedSettingVersion.split(".");
const arr2 = currentVersion.split(".");
const length1 = arr1.length;
const length2 = arr2.length;
const minlength = Math.min(length1, length2);
let i = 0;
for (i; i < minlength; i++) {
let a = parseInt(arr1[i]);
let b = parseInt(arr2[i]);
if (a > b) {
return false; // 版本超前
} else if (a < b) {
return true; // 版本过时
}
}
if (length1 > length2) {
for (let j = i; j < length1; j++) {
if (parseInt(arr1[j]) != 0) {
return false; // 版本超前
}
}
return false; // 版本相同
} else if (length1 < length2) {
for (let j = i; j < length2; j++) {
if (parseInt(arr2[j]) != 0) {
return true; // 版本过时
}
}
return false; // 版本相同
}
return false; // 版本相同
}
#checkSettingDataIntegrity() {
for (const value in this.#scriptSettingData) {
if (!this.settingData.hasOwnProperty(value)) {
console.warn(`属性不存在:${value}`);
this.settingData[value] = this.#scriptSettingData[value];
GM_setValue("searchEngineJumpData", this.settingData);
}
}
}
#checkUpdate() {
if (
this.#isVersionOutdated(
this.#storedSettingData.version,
this.#scriptSettingData.version
)
) {
this.settingData.version = this.#scriptSettingData.version;
this.settingData.message = this.#scriptSettingData.message;
// 5.29.9 更新
if (
this.settingData.setBtnOpacity === "0.2" &&
this.#isVersionOutdated(this.#storedSettingData.version, "5.29.9")
) {
this.settingData.setBtnOpacity = "0.7";
}
// 5.30.2 更新
if (
this.#isVersionOutdated(this.#storedSettingData.version, "5.30.2")
) {
this.deleteOutdatedSearchItems(["https://so.letv.com/s?wd=%s"]);
this.modifyOutdatedSearchItems(
"https://s.weibo.com/weibo/%s",
"https://s.weibo.com/weibo/?q=%s"
);
}
// 5.30.4 更新
if (
this.#isVersionOutdated(this.#storedSettingData.version, "5.30.4")
) {
this.modifyOutdatedSearchItems(
"https://www.startpage.com/do/asearch$post$query",
"https://www.startpage.com/sp/search$post$query"
);
}
// 5.31.1 更新
if (
this.#isVersionOutdated(this.#storedSettingData.version, "5.31.1")
) {
this.modifyOutdatedSearchItemsTarget("https://zh.moegirl.org/%s");
this.modifyOutdatedSearchItemsTarget(
"https://tieba.baidu.com/f?kw=%s&ie=utf-8"
);
this.modifyOutdatedSearchItemsTarget(
"https://github.com/search?utf8=✓&q=%s"
);
}
// 5.31.8 更新
if (
this.#isVersionOutdated(this.#storedSettingData.version, "5.31.8")
) {
this.modifyOutdatedSearchItems(
"https://cn.bing.com/search?q=%s",
"https://www.bing.com/search?q=%s"
);
}
// 5.31.11 更新
if (
this.#isVersionOutdated(this.#storedSettingData.version, "5.31.11")
) {
this.addSearchItem(
{
name: "小红书",
url: "https://www.xiaohongshu.com/search_result/?keyword=%s",
favicon:
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAXSSURBVGhD7ZprbBRVFMf/O1ta+qDQUh5CKS+hVQMVFBAiNjUBixJRUT4YE8UPPj5VjSlEjaIJiFWgpUaBgOURsFIVtNFQo5IoUouNBYq2gKVvoZXtA0rpdndbz+m5Q6ez27JEozvJ/pLp3HvuzOw99zzumUltMJAUGpH0YuyEl+6LHJkWHxIWbwf6jf/feICeerezvvCK49Cm5rqNFV0dFWqob6LpMfHp60dOyRxqt4cqUUDT6fF0rXacy8huqc/mPi26KJE1elpWiKb19q0AzzWNPKe1291a3Hmp2MbuVJpw5wmrWMIMW2ZWbUmyfe2oKevmhQ+fq+SWgy0TqmlhtuqpC2onhoRNUHJLUuN21tnciandgZadbhTOZhzdllaCYR001bY8QUUCjaAigUZQkUAjqEigYetJTO1R7YEJo8L4ptGkNuntaAHaLqsBH4wdBdx+q7QrKoHqemlfDzs9O3W+tBsdQNm1dya/8E+RGUlA/gfSztoBbNkrbV+sywAeSaPqh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eZsNfD+LomHtBQlVHCQpi7wVuJG8FBdxW5q5Bv6fd1TDFy/aIwgt7qHCr5OqkBLTgLtV9SAAd7AuLAcRmf2ZRdtjIeLgKSppKRpNc1UkPtx4mB30ZMFL5g+2UhK6QvnyKLy7n7qjMhN+Ff9WgDfrmVBgooEGkFFAo2gIoFGUJFAQ3P3fiiyNqyDVuPqoprb2rAOGv+DiupbFtbBlhgakXgiYW5ZmN2mPhFaC6enx5Vce2yG3eFxOa7C07E4MlZ9/rAWqx2VqwraHQW974xFVy8Vtfd42lOGxqSGaDbv98gAhC3BSmxortvA/WuTZmXy25v2azabPdYeGhdt14Zrfn+9/m/g7FTlclbnXW7MW9lY/iRbQkaAvwEWveocTKmI8QAAAABJRU5ErkJggg==",
},
"sociality"
);
}
console.info(
`\n%c ${GM_info.script.name} 设置已更新 \n%c 本地设置版本号:\t\t${
this.#storedSettingData.version
}\t\t\t\t\t\t\t\n%c 当前版本号:\t\t\t${
this.settingData.version
}\t\t\t\t\t\t\t\n`,
"color:#eee;background:#444;padding:6px 0;border-radius:6px 6px 0 0;",
"color:#444;background:#eee;padding:6px 0;border-radius:0 6px 0 0",
"color:#444;background:#eee;padding:6px 0;border-radius:0 0 6px 6px;"
);
GM_setValue("searchEngineJumpData", this.settingData);
}
}
initSettings() {
if (this.#storedSettingData) {
this.settingData = Object.assign({}, this.#storedSettingData);
this.#checkSettingDataIntegrity();
this.#checkUpdate();
} else {
this.settingData = this.#scriptSettingData;
GM_setValue("searchEngineJumpData", this.settingData);
}
this.initEngineCategories();
}
initEngineCategories() {
this.settingData.engineList.engineCategories = [];
for (
let engineCategoryIndex = 0;
engineCategoryIndex < this.settingData.engineDetails.length;
engineCategoryIndex++
) {
if (this.settingData.engineDetails[engineCategoryIndex][2]) {
this.settingData.engineList.engineCategories[engineCategoryIndex] =
this.settingData.engineDetails[engineCategoryIndex];
} else {
this.settingData.engineList.engineCategories[-engineCategoryIndex] =
this.settingData.engineDetails[engineCategoryIndex];
}
}
}
getMatchedRule() {
for (const rule of [...rules]) {
if (rule.url.test(location.href)) {
return rule;
}
}
return null;
}
addSearchItem(newItem, category) {
this.settingData.engineList[category].push(newItem);
}
// 更新已过期的搜索链接
modifyOutdatedSearchItems(oldURL, newURL) {
for (const value in this.settingData.engineList) {
var item = this.settingData.engineList[value];
for (let i = 0; i < item.length; i++) {
if (item[i].url === oldURL) {
item[i].url = newURL;
}
}
}
}
// 更新搜索target 不为 _blank
modifyOutdatedSearchItemsTarget(url) {
for (const value in this.settingData.engineList) {
var item = this.settingData.engineList[value];
for (let i = 0; i < item.length; i++) {
if (item[i].url === url) {
delete item[i].blank;
}
}
}
}
deleteOutdatedSearchItems(urlList) {
for (const value in this.settingData.engineList) {
var item = this.settingData.engineList[value];
for (let i = 0; i < item.length; i++) {
if (urlList.includes(item[i].url)) {
console.warn("删除搜索引擎:" + item[i].name);
item.splice(i, 1);
}
}
}
}
// 更新图标
modifyOutdatedSearchItemsIcon(url, newIcon) {
for (let i = 0; i < this.settingData.engineList.length; i++) {
if (this.settingData.engineList[i].url == url) {
//用户可能自己更改网站名称,所以此处用url来匹配
this.settingData.engineList[i].favicon = newIcon;
}
}
}
// 更新本地 rule
modifyOutdatedSearchItemsRule(name, value) {
var oldRule = this.settingData.rules;
for (let item in oldRule) {
if (oldRule[item].name == name) {
console.log("匹配成功, 更新 rule : ", name);
oldRule[item] = value;
}
}
}
}
class DropDownList {
zIndex = 100000001;
hidden = true;
showDelay = 233;
hideDelay = 233;
aShownClass = "sej-drop-list-trigger-shown";
constructor(a, list) {
this.a = a;
this.list = list;
this.init();
}
init() {
var a = this.a;
var list = this.list;
var self = this;
// 关闭动画
if (!settingData.transtion) {
this.showDelay = 0;
this.hideDelay = 0;
}
// 进入显示
a.addEventListener("mouseenter", function () {
clearTimeout(self.hideTimerId);
if (self.hidden) {
self.showTimerId = setTimeout(function () {
self.show();
}, self.showDelay);
} else {
var style = list.style;
style.top = parseFloat(list.style.top) - 6 + "px";
style.zIndex = this.zIndex + 1;
style.opacity = 1;
}
});
// 离开隐藏
a.addEventListener("mouseleave", function () {
clearTimeout(self.showTimerId);
if (!self.hidden) {
list.style.top = parseFloat(list.style.top) + 6 + "px";
list.style.opacity = 0.04;
self.hideTimerId = setTimeout(function () {
self.hide();
}, self.hideDelay);
}
});
list.addEventListener("mouseenter", function () {
clearTimeout(self.hideTimerId);
var style = list.style;
style.zIndex = this.zIndex + 1;
style.opacity = 1;
style.top = parseFloat(list.style.top) - 6 + "px";
});
list.addEventListener("mouseleave", function () {
list.style.opacity = 0.04;
list.style.top = parseFloat(list.style.top) + 6 + "px";
self.hideTimerId = setTimeout(function () {
self.hide();
}, self.hideDelay);
});
}
show() {
if (!this.hidden) return;
this.hidden = false;
var scrolled = this.#getScrolled();
var aBCRect = this.a.getBoundingClientRect();
var thisBCRect = this.a.parentNode.getBoundingClientRect();
var style = this.list.style;
var top = scrolled.y + aBCRect.bottom;
var left = scrolled.x + aBCRect.left;
style.top = top + 6 + "px";
style.left = left + "px";
style.zIndex = this.zIndex - 1;
style.display = "block";
// 二级搜索居中显示
style.left =
left -
(this.list.getBoundingClientRect().width - aBCRect.width) / 2 +
"px";
setTimeout(function () {
style.opacity = 1;
style.top = top + "px";
}, 30);
this.a.classList.add(this.aShownClass);
}
hide() {
if (this.hidden) return;
this.hidden = true;
var style = this.list.style;
style.display = "none";
style.opacity = 0.2;
this.a.classList.remove(this.aShownClass);
}
// 获取已滚动的距离
#getScrolled(container) {
if (container) {
return {
x: container.scrollLeft,
y: container.scrollTop,
};
}
return {
x:
"scrollX" in window
? window.scrollX
: "pageXOffset" in window
? window.pageXOffset
: document.documentElement.scrollLeft || document.body.scrollLeft,
y:
"scrollY" in window
? window.scrollY
: "pageYOffset" in window
? window.pageYOffset
: document.documentElement.scrollTop || document.body.scrollTop,
};
}
}
class SettingButton {
settingButtonElement;
constructor(jumpBarContainer, settingData) {
this.parentJumpBarContainer = jumpBarContainer;
this.settingData = settingData;
this.#addButtonToJumpBar();
this.settingButtonElement?.addEventListener("click", () =>
this.#activateSettingButton()
);
GM_registerMenuCommand("设置菜单", () => this.#activateSettingButton());
}
#addButtonToJumpBar() {
if (this.settingData.setBtnOpacity >= 0) {
this.settingButtonElement = document.createElement("span");
this.settingButtonElement.id = "setBtn";
this.settingButtonElement.title = "设置菜单";
GM_addStyle(`#setBtn{opacity: ${this.settingData.setBtnOpacity};}`);
this.settingButtonElement.innerHTML = icon.setting;
this.parentJumpBarContainer.appendChild(this.settingButtonElement);
}
}
#activateSettingButton() {
if (!this.settingPanel) {
document.querySelector("#settingLayerMask")?.remove();
this.settingPanel = new SettingPanel();
}
this.settingPanel.show();
}
}
class JumpBar {
engineButtonTemplate =
'<a class="sej-engine" target="$blank$" data-iqxincategory="$category$" encoding="$encoding$" gbk="$gbk$" url="$url$"><img src="$favicon$" class="sej-engine-icon" />$name$</a>';
dropDownLists = [];
container;
inputTarget;
insertTarget;
insertPositionLabel;
matchedRule;
engineList;
settingData;
constructor(engineList, settingData, matchedRule) {
this.engineList = engineList;
this.settingData = settingData;
this.matchedRule = matchedRule;
const inited = this.#initContainer();
if (inited === false) return;
this.#initEngines();
this.#addEnginesToDOM();
this.#addStyle();
if (this.settingData.fixedTop && this.matchedRule) {
const originalContainerDistanceTop =
this.container.getBoundingClientRect().top + window.scrollY;
// 判断是否需要只在向上滚动时显示
if (this.settingData.fixedTopUpward) {
window.onwheel = document.onwheel = (e) => {
e.wheelDelta > 0
? this.#fixedToTop(
this.matchedRule.fixedTop,
this.matchedRule.fixedTopColor,
originalContainerDistanceTop
)
: {};
};
} else {
window.onscroll = () => {
this.#fixedToTop(
this.matchedRule.fixedTop,
this.matchedRule.fixedTopColor,
originalContainerDistanceTop
);
};
}
}
document.querySelectorAll("sejspan a.sej-engine").forEach((engine) => {
engine.addEventListener("mousedown", (e) => {
this.#jumpToSelectedEngine(e);
});
});
}
#initContainer() {
if (this.matchedRule?.enabled) {
this.inputTarget = this.#getInputTarget();
this.insertTarget = this.#getInsertTarget();
this.insertPositionLabel = this.#getInsertPositionLabel();
if (this.inputTarget && this.insertTarget) {
this.#createContainerDOM();
} else {
console.warn(
`未找到输入框或插入位置,跳过初始化:\n输入框:${this.inputTarget}\n插入位置:${this.insertTarget}`
);
}
} else if (this.#isOnSelectSearchMode()) {
this.inputTarget = {};
this.insertTarget = document.body;
this.insertPositionLabel = "beforeend";
this.#createContainerDOM();
this.container.classList.add("selectSearch");
document.addEventListener("selectionchange", () =>
this.#toggleSelectSearchJumpBar()
);
} else {
console.info("未启用搜索跳转,跳过初始化");
return false;
}
this.matchedRule?.class
? (this.container.className += ` ${this.matchedRule.class}`)
: {};
// 由于与要插入网页的样式无法很好的兼容,更改源网页的样式
if (this.matchedRule?.stylish) {
GM_addStyle(this.matchedRule.stylish);
}
return true;
}
#createContainerDOM() {
this.container = document.createElement("sejspan");
this.container.id = "sej-container";
this.container.className = "rwl-exempt";
if (
this.matchedRule?.style.includes("sticky") ||
this.matchedRule?.style.includes("fixed")
) {
this.containerWrapper = this.container;
} else {
this.containerWrapper = document.createElement("sejspan");
this.containerWrapper.id = "sej-container-wrapper";
this.containerWrapper.appendChild(this.container);
}
}
#toggleSelectSearchJumpBar() {
const selection = getSelection();
if (selection.isCollapsed) {
this.container.style.top = "-50px";
} else {
this.inputTarget.textContent = selection.toString();
this.container.style.top = "2px";
}
}
#isOnSelectSearchMode() {
if (
(!this.matchedRule || !this.matchedRule.enabled) &&
this.settingData.selectSearch
) {
return true;
}
}
#getInputTarget() {
return typeof this.matchedRule?.insertIntoDoc.keyword == "function"
? this.matchedRule.insertIntoDoc.keyword
: this.#getElementBySelector(this.matchedRule?.insertIntoDoc.keyword);
}
#getInsertTarget() {
return typeof this.matchedRule?.insertIntoDoc.target == "function"
? this.matchedRule.insertIntoDoc.target()
: this.#getElementBySelector(this.matchedRule?.insertIntoDoc.target);
}
#getInsertPositionLabel() {
return this.matchedRule?.insertIntoDoc.where.toLowerCase();
}
#initEngines() {
const self = this;
this.engineList.engineCategories.forEach(function (item) {
// console.log(item); // 搜索菜单 ["网页", "web", true]
const category = item[1]; // "web"
const cName = item[0]; // "网页"
let engines = [];
self.engineList[category].forEach(function (engine) {
const engineUrl = engine.url;
if (engine.disable) return;
if (
self.settingData.HideTheSameLink &&
self.matchedRule?.url.test(engineUrl)
)
return; // 去掉跳转到当前引擎的引擎
let engineListButton = self.engineButtonTemplate
.replace("$encoding$", (engine.encoding || "utf-8").toLowerCase())
.replace("$url$", engineUrl)
.replace("$name$", engine.name)
.replace("$category$", category);
// 图标
if (engine.favicon) {
engineListButton = engineListButton.replace(
"$favicon$",
engine.favicon
);
} else {
engineListButton = engineListButton.replace(
'src="$favicon$"',
""
);
}
// gbk编码
if (engine.gbk) {
engineListButton = engineListButton.replace("$gbk$", engine.gbk);
} else {
engineListButton = engineListButton.replace('gbk="$gbk$"', "");
}
// 新标签页
if (settingData.newtab || engine.blank) {
engineListButton = engineListButton.replace("$blank$", "_blank");
} else {
engineListButton = engineListButton.replace(
'target="$blank$"',
""
);
}
engines.push(engineListButton);
});
// 非空列表
if (!engines.length) return;
engines = engines.join("");
// 展开当前搜索分类列表
if (
!self.settingData.foldlist &&
category == self.matchedRule?.engineList
) {
self.container.innerHTML = engines;
} else {
const dropDownList = document.createElement("sejspan");
dropDownList.className = "sej-drop-list rwl-exempt";
dropDownList.innerHTML = engines;
// a:主搜索菜单
// dropList: 搜索子菜单
const jumpBarButton =
dropDownList.firstElementChild.cloneNode(true);
jumpBarButton.className =
jumpBarButton.className + " sej-drop-list-trigger";
// 隐藏主搜索菜单的图标
if (!self.settingData.icon) {
cName = "";
}
jumpBarButton.lastChild.nodeValue = cName;
self.dropDownLists.push([jumpBarButton, dropDownList]);
}
});
}
#addEnginesToDOM() {
this.dropDownLists.forEach((item) => {
this.container.appendChild(item[0]); //将搜索列表放入主搜索
document.body.appendChild(item[1]); // 插入搜索子菜单
new DropDownList(item[0], item[1]);
});
switch (this.insertPositionLabel) {
case "beforebegin": // 'beforeBegin'(插入到给定元素的前面) ;
this.insertTarget.parentNode.insertBefore(
this.containerWrapper,
this.insertTarget
);
break;
case "afterbegin": // 'afterBegin'(作为给定元素的第一个子元素) ;
if (this.insertTarget.firstChild) {
this.insertTarget.insertBefore(
this.containerWrapper,
this.insertTarget.firstChild
);
} else {
this.insertTarget.appendChild(this.container);
}
break;
case "beforeend": // 'beforeEnd' (作为给定元素的最后一个子元素) ;
this.insertTarget.appendChild(this.containerWrapper);
break;
case "afterend": // 'afterEnd'(插入到给定元素的后面);.
if (this.insertTarget.nextSibling) {
this.insertTarget.parentNode.insertBefore(
this.containerWrapper,
this.insertTarget.nextSibling
);
} else {
this.insertTarget.parentNode.appendChild(this.container);
}
break;
default:
this.insertTarget.appendChild(this.containerWrapper);
break;
}
}
#addStyle() {
if (this.matchedRule?.style) {
// 判断是否存在脚本 “AC-baidu:重定向优化百度搜狗谷歌搜索_去广告_favicon_双列”
if (this.settingData.center == 2) {
// 自动判断是否添加
if (
document.querySelector(".AC-style-logo") &&
this.matchedRule.style_ACBaidu
) {
this.matchedRule.style = this.matchedRule.style_ACBaidu;
}
} else if (this.settingData.center == 1) {
// 强制添加
this.matchedRule.style = this.matchedRule.style_ACBaidu
? this.matchedRule.style_ACBaidu
: this.matchedRule.style;
} //
// 判断是否存在脚本“知乎排版优化”
if (document.getElementById("SearchMain")) {
if (
document.getElementById("SearchMain").style.marginLeft == "150px"
) {
this.matchedRule.style = this.matchedRule.style_ZhihuChenglinz;
this.matchedRule.fixedTop = null;
}
}
this.container.style.cssText = this.matchedRule.style;
}
//兼容ac百度中lite选项, fixedtop和正常的不一样
setTimeout(function () {
if (
document.querySelector(".AC-baiduLiteStyle") &&
matchedRule.fixedTop2
) {
matchedRule.fixedTop = matchedRule.fixedTop2;
}
}, 2500);
// 吸附顶部时的占位
if (
getComputedStyle(this.container).position !== "sticky" &&
this.containerWrapper !== this.container &&
!this.#isOnSelectSearchMode()
) {
this.containerWrapper.style.height =
this.container.offsetHeight +
parseFloat(getComputedStyle(this.container).marginTop) +
parseFloat(getComputedStyle(this.container).marginBottom) +
"px";
this.containerWrapper.style.position = "relative";
this.containerWrapper.style.display = "flow-root";
}
}
#fixedToTop(fixedTop, color, originalContainerDistanceTop) {
if (!this.container) {
return;
}
fixedTop = fixedTop ? fixedTop : 0;
if (this.container.style.position != "sticky") {
const rect = this.container.getBoundingClientRect();
if (originalContainerDistanceTop - window.scrollY <= fixedTop) {
this.container.style.position = "fixed";
this.container.style.top = fixedTop + "px";
this.container.style.left = rect.left + "px";
this.container.style.padding = "0";
this.container.style.margin = "0";
this.container.style.backgroundColor = color;
} else {
this.container.style.cssText = matchedRule.style;
}
}
}
#jumpToSelectedEngine(e) {
const target = e.target;
if (!target) return;
if (!target.classList.contains("sej-engine")) return;
let searchKeyword;
if (typeof this.inputTarget == "function") {
searchKeyword = this.inputTarget();
} else {
if (this.inputTarget.nodeName == "INPUT") {
searchKeyword = this.inputTarget.value;
} else {
searchKeyword = this.inputTarget.textContent;
}
}
// 如果搜索内容是通过某一网站搜索, 就去掉。 例: 0 site:zhihu.com 只保留0, 后面的网站会去掉
if (!this.settingData.HideTheSameLink) {
searchKeyword = searchKeyword.replace(/site:[^\s]+/, "");
}
// 编码 解码
// 对搜索词编码 (未做解码处理,浏览器自动处理) 网站1688采用gbk编码
const ogbk = target.getAttribute("gbk");
if (ogbk) {
searchKeyword = toGBK(searchKeyword);
} else {
searchKeyword = encodeURIComponent(searchKeyword);
}
let targetURL = target.getAttribute("url");
// 一键搜索
if (
this.settingData.allOpen &&
target.classList.contains("sej-drop-list-trigger")
) {
var list = this.engineList[target.dataset.iqxincategory];
for (var i = 0; i < list.length; i++) {
if (
list[i].url.indexOf("site:") < 0 &&
matchedRule?.url.test(list[i].url)
)
continue;
if (list[i].disable) continue;
var href = list[i].url.replaceAll("%s", searchKeyword);
GM_openInTab(href);
}
target.setAttribute("onclick", "return false;");
return;
}
// 如果有post请求
var postSign = targetURL?.indexOf("$post$");
if (postSign && postSign !== -1) {
target.addEventListener("click", function (e) {
e.preventDefault();
});
var f = this.#getEngineJumpPostForm(
targetURL.substring(0, postSign),
[
targetURL.substring(postSign + 6),
decodeURIComponent(searchKeyword),
],
target.getAttribute("target")
);
document.body.appendChild(f);
f.submit();
} else {
target.href = target
.getAttribute("url")
.replaceAll("%s", searchKeyword);
}
if (this.#isOnSelectSearchMode()) {
target.target = "_blank";
}
if (target?.target !== "_blank") {
target.target = "_top";
}
}
#getElementBySelector(selector) {
if (selector?.startsWith("css;")) {
return document.querySelector(selector.slice(4));
} else {
return document.evaluate(selector, document, null, 9, null)
.singleNodeValue;
}