-
Notifications
You must be signed in to change notification settings - Fork 226
/
AC-Baidu-SoGou-Google-NoRedirect.user.js
2622 lines (2447 loc) · 115 KB
/
AC-Baidu-SoGou-Google-NoRedirect.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 AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列
// @name:en AC-baidu-google_sogou_bing_RedirectRemove_favicon_adaway_TwoLine
// @name:zh AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列
// @name:ja AC-baidu-重定向最適化Baiduの搜狗のGoogleのBing検索結果のリダイレクト除去+favicon
// @description 1.繞過百度、搜狗、谷歌、好搜搜索結果中的自己的跳轉鏈接,直接訪問原始網頁-反正都能看懂 2.新增自定义网站拦截功能 3添加Favicon显示 4.页面CSS 5.添加计数 6.开关选择以上功能 7.自动翻页功能
// @description:en 1.bypass the redirect link at baidu\sogou\google\haosou; 2.remove ads at baidu; 3.add Favicon for each website; 4.render your own style; 5.counter; 6.Switch to handle all 7.Auto Pager
// @description:ja 1.迂回Baidu、Sogou、Google、Haosou検索検索結果の中の自分の遷移リンク; 2.Baiduの余分な広告を取り除く; 3.コメントを追加; 4.ページのカスタムCSP; 5.カウントを追加; 6.スイッチは以上の機能を選択します; 7.自動ページめくり.
// @icon https://ae01.alicdn.com/kf/Hac1a58055c5047cdb91349e91aa208d5k.jpg
// @author AC
// @license GPL-3.0-only
// @create 2015-11-25
// @run-at document-start
// @version 27.06
// @connect baidu.com
// @connect google.com
// @connect google.com.hk
// @connect google.com.jp
// @connect bing.com
// @connect duckduckgo.com
// @connect dogedoge.com
// @connect so.com
// @connect localhost
// @connect 90dao.com
// @connect *
// @include *://ipv6.baidu.com/*
// @include *://www.baidu.com/*
// @include *://www1.baidu.com/*
// @include *://m.baidu.com/*
// @include *://xueshu.baidu.com/s*
// @include *://www.so.com/s?*
// @include *://*.bing.com/*
// @include *://encrypted.google.*/search*
// @include *://*.google*/search*
// @include *://scholar.google.com/scholar*
// @include *://*.google*/webhp*
// @include *://*duckduckgo.com/*
// @include *://*.dogedoge.com/*
// @include *://*.90dao.com/*
// @include *://*.tujidu.com/*
// @include *://localhost*/*
// @exclude *://*.google*/sorry*
// @exclude https://zhidao.baidu.com/*
// @exclude https://*.zhidao.baidu.com/*
// @exclude https://www.baidu.com/img/*
// @exclude https://lens.google.com/*
// @supportURL https://ac.tujidu.com/
// @home-url https://greasyfork.org/zh-TW/scripts/14178
// @home-url2 https://github.com/langren1353/GM_script
// @homepageURL https://greasyfork.org/zh-TW/scripts/14178
// @copyright 2015-2025, AC
// @lastmodified 2024-08-26
// @feedback-url https://github.com/langren1353/GM_script
// @note 2024.08-26-V27.05 fix:暗黑模式
// @note 2024.08-19-V27.05 fix:拦截功能、被拦截域名问题、和其他脚本兼容的CSS植入问题、优化域名检测逻辑;
// @note 2024.08-16-V27.04 修复:谷歌双列加载缓慢、双列效果优化、单列居中效果优化;bing页面bug修复;暗黑模式引入;编号、下划线功能修复;鸭鸭修复 & 勿忘国耻
// @note 2024.08-09-V27.03 增加字节跳动的Vue地址,避免部分地区打不开lib.baomitu.com导致的脚本无效
// @note 2024.08-06-V27.02 更换域名,解决SNI拦截问题;优化右侧栏显示逻辑-双列以上隐藏
// @note 2024.08-06-V27.01 重构-十周年优化版,优化项:1.重构设置功能,提供更强大的设置功能;2.极大优化页面加载动画效果;3.修复现有页面显示和效果(谷歌[主]、必应)单列、多列;4.兼容ViolentMonkey,兼容Firefox浏览器
// @note 2024.03-05-V26.10 fix: 谷歌白屏的问题;再次支持鸭鸭搜索引擎,鸭鸭三列支持;baidu\Google双列功能
// @note 2023.12-16-V26.07 日常维护;优化各页面加载卡顿的问题,优化搜索引擎显示效果
// @note 2023.06-19-V26.06 修复谷歌显示效果的错位问题等,修复谷歌异常白屏问题
// @note 2022.12-07-V26.04 修复必应错位问题;优化谷歌双列动画问题
// @note 2022.08-23-V26.03 修复因背景图引起的看不清字的问题;修复百度单列错位问题;修复google自定义按钮不可见
// @note 2022.08-23-V26.02 加快代码执行速度;减少动画撕裂;替换CDN的md5库
// @note 2022.08-22-V26.01 因甲癌手术和公司事务停更了2个月,目前补上,推荐更新。 1.修复百度加载缓慢的问题;2.修复谷歌样式加载顺序异常的问题;3.整体优化样式加载时间,更流畅了
// @note 2022.06-18-V25.09 修复可能出现的脚本参数读取失败导致的脚本不执行的异常 & 修复 拦截规则特殊参数的问题 & 更换CDN地址
// @note 2022.06-16-V25.06 优化重定向逻辑,部分网站只需要稍作处理,不用做接口请求了,感谢众多搜索引擎的版本迭代更新
// @note 2022.04-08-V25.05 主要修复Block功能;其次优化样式加载速度-减少撕裂感
// @note 2022.03-07-V25.04 修复谷歌、必应样式问题;修复并优化拦截功能
// @note 2022.01-29-V25.02 修复谷歌、百度、必应的部分样式错位的问题
// @note 2021.12-06-V25.01 修复百度样式偏左 & 修复谷歌样式显示
// @note 2021.10-31-V24.29 fixed Less requirement for faster Load
// @note 2021.10-29-V24.27 移除必应能选择的广告;增加自定义样式less的支持
// @note 2021.09-02-V24.26 修复必应多favicon,修复百度百科问题;修复谷歌一个小问题
// @note 2021.07-16-V24.25 修复一个bug;兼容百度下搜索股票tag;
// @note 2021.06-15-V24.24 更换cdn地址
// @note 2017.05.12 -> 2021.06-15 && V8.6 -> V24.24 各种各样的历史更新记录,从一个版本迭代到另一个版本
// @note 2017.05.12-V8.4 新增:默认屏蔽谷歌的安全搜索功能
// @note 2017.05.05-V8.3 修复include范围太小导致的百度知道的屏蔽问题
// @note 2017.05.04-V8.2 终于修复了百度知道图片替换了文字的这个大BUG; 顺便处理了superapi.zhidao.baidu.com; 新增谷歌搜索结果重定向去除
// @note 2017.05.04-V8.1 终于修复了百度知道图片替换了文字的这个大BUG,顺便处理了superapi.zhidao.baidu.com
// @note 2017.05.04-V8.0 终于修复了百度知道图片替换了文字的这个大BUG,待测试
// @note 2017.03.28-V7.6 修复在ViolentMonkey上的不支持的问题
// @note 2017.03.28-V7.5 尝试修复chrome上的问题
// @note 2017.03.21-V7.4 尝试处理Edge上不支持的问题,结果发现是Edge本身的TamperMonkey支持有问题
// @note 2017.03.19-V7.3 修复打开百度之后再次点击“百度一下”导致的无法更新重定向问题
// @note 2017.03.19-V7.2 未知原因chrome的MutationObserver无法使用了,继续回归以前的DOMNodeInserted
// @note 2017.02.17-V7.0 修复搜狗的搜索结果重定向问题+改个名字
// @note 2017.02.17-V6.9 修复搜狗的搜索结果重定向问题
// @note 2016.10.27-V6.7 修复了以前的重复请求,现在的请求数应该小了很多,网络也就不卡了,感觉萌萌哒
// @note 2016.04.24-V6.6 恢复以前的版本,因为兼容性问题
// @note 2015.12.01-V5.0 加入搜狗的支持,但是支持不是很好
// @note 2015.11.25-V2.0 优化,已经是真实地址的不再尝试获取
// @note 2015.11.25-V1.0 完成去掉百度重定向的功能
// @resource baiduCommonStyle https://ibaidu.tujidu.com/newcss/baiduCommonStyle.less?t=27.04
// @resource baiduOnePageStyle https://ibaidu.tujidu.com/newcss/baiduOnePageStyle.less?t=27.04
// @resource baiduTwoPageStyle https://ibaidu.tujidu.com/newcss/baiduTwoPageStyle.less?t=27.04
// @resource googleCommonStyle https://ibaidu.tujidu.com/newcss/googleCommonStyle.less?t=27.04
// @resource googleOnePageStyle https://ibaidu.tujidu.com/newcss/googleOnePageStyle.less?t=27.04
// @resource googleTwoPageStyle https://ibaidu.tujidu.com/newcss/googleTwoPageStyle.less?t=27.04
// @resource bingCommonStyle https://ibaidu.tujidu.com/newcss/bingCommonStyle.less?t=27.04
// @resource bingOnePageStyle https://ibaidu.tujidu.com/newcss/bingOnePageStyle.less?t=27.04
// @resource bingTwoPageStyle https://ibaidu.tujidu.com/newcss/bingTwoPageStyle.less?t=27.04
// @resource duckduckgoCommonStyle https://ibaidu.tujidu.com/newcss/duckCommonStyle.less?t=27.04
// @resource duckduckgoOnePageStyle https://ibaidu.tujidu.com/newcss/duckOnePageStyle.less?t=27.04
// @resource duckduckgoTwoPageStyle https://ibaidu.tujidu.com/newcss/duckTwoPageStyle.less?t=27.04
// @resource dogeCommonStyle https://ibaidu.tujidu.com/newcss/dogeCommonStyle.less?t=27.04
// @resource dogeOnePageStyle https://ibaidu.tujidu.com/newcss/dogeOnePageStyle.less?t=27.04
// @resource dogeTwoPageStyle https://ibaidu.tujidu.com/newcss/dogeTwoPageStyle.less?t=27.04
// @resource HuYanStyle https://ibaidu.tujidu.com/newcss/HuYanStyle.less?t=27.04
// @resource BgAutoFit https://ibaidu.tujidu.com/newcss/BgAutoFit.less?t=27.04
// @resource HuaHua-ACDrakMode https://ibaidu.tujidu.com/newcss/HuaHua-ACDrakMode.less?t=27.04
// @resource baiduLiteStyle https://gitcode.net/-/snippets/1906/raw/master/LiteStyle.css?inline=false
// @require https://update.greasyfork.org/scripts/433620/1422795/Less4_1_2_fixed.js
// @require https://lib.baomitu.com/vue/3.2.31/vue.runtime.global.prod.min.js
// @require https://lf6-cdn-tos.bytecdntp.com/cdn/expire-10-y/vue/3.2.31/vue.runtime.global.prod.min.js
// @noframes
// @grant GM_info
// @grant GM_getValue
// @grant GM.getValue
// @grant GM_setValue
// @grant GM.setValue
// @grant GM_addStyle
// @grant GM_getResourceURL
// @grant GM_listValues
// @grant GM.getResourceUrl
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_registerMenuCommand
// @grant GM_addValueChangeListener
// @grant unsafeWindow
// ==/UserScript==
~(async () => {
Object.defineProperty(console, 'mylog', {
value: function() {
if(CONST && CONST.curConfig) {
if(CONST.curConfig.isDevMode) {
const error = new Error();
const stackTrace = error.stack.split('\n')[2].trim(); // 获取调用栈信息
try{
const [targetLink] = /chrome-extension:\/\/(.*)/.exec(stackTrace) // 提取文件名和行号
const data = [...arguments].join(' ').padEnd(60, ' ')
console.log(data, `\t\t ${targetLink}`); // 结合自定义输出和调用栈信息
}catch (e){
// console.error(error.stack)
console.log('[log] -', ...arguments); // 如果没有匹配到文件名和行号,则只输出自定义信息
}
}
} else {
console.log.apply(this, arguments);
}
},
})
const { reactive, watch } = Vue;
const MyApi = (() => {
/**
* @param cssText CSS的内容,如果是less的话,需要编译后的
* @param className 新增的类名,或者是一堆类名(空格隔开)
*/
function addStyle(cssText, className = ''){ // 添加CSS代码,不考虑文本载入时间,带有className
if(className) {
const selectorName = (' ' + className).split(' ').join('.')
let oldNode = document.querySelector(selectorName)
if(!oldNode) {
oldNode = document.createElement("style");
oldNode.className = className;
MyApi.safeFunc(() => {
document.children[0].appendChild(oldNode);
})
}
oldNode.innerHTML = cssText;
}
}
/**
* 脚本一般来说只需要插入一次的,所以不加入重载功能
* @param scriptText 新增的脚本的名字
*/
function addScript(scriptText) {
const scriptNode = document.createElement('script')
scriptNode.innerText = scriptText
document.head.appendChild(scriptNode)
}
/**
* 安全脚本执行
* @param callback 回调函数
* @param catchCallback 异常的回调函数
*/
const safeFunc = (callback, catchCallback = () => {}) => {
try{
return callback()
}catch (e){
console.mylog(e)
return catchCallback()
}
}
const safeGetNodeFunc = (selector, callbackFunc) => {
const node = document.querySelector(selector)
if(node) {
callbackFunc(node)
}
}
/**
* 等待元素后,执行的函数
* @param selector 选择器 | 选择的函数
* @param callbackFunc 回调函数
* @param findTick 查询周期,默认200
* @param clearAfterFind 查询完成后自动结束?
* @param timeout 查询超时,超时后停止
* @param errCallback 查询超时后,回调
*/
const safeWaitFunc = async(selector, callbackFunc = node => {
}, findTick = 200, clearAfterFind = true, timeout = 20000 * 1000, errCallback) => {
if(findTick < 20) findTick = 20
let count = timeout / findTick
let t_id = null
const firstSuccess = await mainRunFunc()
if (!clearAfterFind || !firstSuccess) {
t_id = setInterval(mainRunFunc, findTick);
}
async function strRun() {
let hasFind = false
let selectRes = document.querySelectorAll(selector);
if (selectRes.length <= 0) {
hasFind = false
}
if (selectRes.length >= 1) {
selectRes = selectRes[0];
hasFind = true
}
if (clearAfterFind && hasFind) {
clearId();
await callbackFunc(selectRes)
}
return hasFind
}
async function funcRun() {
let hasFind = false
const res = selector()
if (res && res.length > 0) {
hasFind = true
if (clearAfterFind && hasFind) clearId();
await callbackFunc(selector()[0]);
} else if (res) {
hasFind = true
if (clearAfterFind && hasFind) clearId();
await callbackFunc();
}
return hasFind
}
async function mainRunFunc() {
if (count-- < 0) {
clearId()
errCallback && errCallback()
}
if ((typeof (selector) == "string")) {
return await strRun()
} else if (typeof (selector) === "function") {
return await funcRun()
}
}
function clearId() {
if (t_id) clearInterval(t_id)
}
}
/**
* 提取URL参数数据
* @param attribute 参数Key
* @param needDecode 是否需要解码,默认解码
* @param baseUrl 默认网址来源
* @returns {string} 变量结果Value
*/
function getUrlAttribute(baseUrl = location.href, attribute, needDecode = true){
const [, search = ''] = baseUrl.split("?");
var searchValue = search.split("&");
for (var i = 0; i < searchValue.length; i++) {
var key_value = searchValue[i].split("=");
var reg = new RegExp("^"+attribute+"$");
if (reg.test(key_value[0])) {
var searchWords = key_value[1];
return needDecode?decodeURIComponent(searchWords):searchWords;
}
}
}
const http = {
async get(url) {
return new Promise((resolve, reject) => {
const timeout = 10000
GM_xmlhttpRequest({
url,
fetch: true,
method: 'GET',
timeout: timeout,
onload: resp => {
resolve([null, resp.responseText, resp.responseHeaders])
},
onerror: resp => {
reject([resp, '', {}])
}
})
})
},
async post(url, data) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url,
data,
method: 'POST',
timeout: 10000,
onload: resp => resolve([null, resp.responseText, resp.responseHeaders]),
onerror: resp => reject([resp, {}])
})
})
}
}
/**
* 等待多久后,重新加载网页
* @param timeout
*/
const refreshAfter = () => {
let id = null
return (timeout) => {
clearTimeout(id)
id = setTimeout(() => {
location.reload()
}, timeout)
}
}
/**
* 等待多少ms后执行
* @param ms 毫秒
* @returns {Promise<unknown>}
*/
const waitTime = (ms) => {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
const debounce = (fn, delay) => {
let timer = null;
return function () {
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, arguments);
}, delay);
};
}
const throttle = (fn, delay) => {
let timer = null;
let startTime = Date.now();
return function () {
const curTime = Date.now();
const remaining = delay - (curTime - startTime);
clearTimeout(timer);
if (remaining <= 0) {
fn.apply(this, arguments);
startTime = Date.now();
} else {
timer = setTimeout(() => {
fn.apply(this, arguments);
startTime = Date.now();
}, remaining);
}
};
}
/**
*
* @param callback 回调函数
* @param timeout 定时周期
* @param mustWaitEnd 必须等待上次执行结束?true = 等待;false=标准Interval
* @constructor
*/
const setIntervalRun = (callback, timeout, mustWaitEnd = true) => {
let isLocked = false
return setInterval(() => {
if (mustWaitEnd || !isLocked) {
isLocked = true
callback()
isLocked = false
}
}, timeout)
}
function Reg_Get(HTML, reg) {
let RegE = new RegExp(reg);
try {
return RegE.exec(HTML)[1];
} catch (e) {
return "";
}
}
function getElementByXpath(e, t, r = document) {
t = t || r;
try {
return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
} catch (t) {
return void console.error("无效的xpath");
}
}
function getAllElementsByXpath(xpath, contextNode, doc = document) {
contextNode = contextNode || doc;
const result = [];
try {
const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < query.snapshotLength; i++) {
const node = query.snapshotItem(i); //if node is an element node
if (node.nodeType === 1) result.push(node);
}
} catch (err) {
throw new Error(`Invalid xpath: ${xpath}`);
}
return result;
}
// 翻页用的获取器
const getAllElements = (selector, contextNode, doc = document, win = window, _cplink = undefined) => {
if (!selector) return []; //@ts-ignore
contextNode = contextNode || doc;
if (typeof selector === 'string') {
if (selector.search(/^css;/i) === 0) {
return contextNode.querySelectorAll(selector.slice(4))
} else {
return getAllElementsByXpath(selector, contextNode, doc);
}
} else {
const query = selector(doc, win, _cplink);
if (!Array.isArray(query)) {
throw new Error('Wrong type is returned by getAllElements');
} else {
return query;
}
}
}
function hideNode(node) {
if(node.hasAttribute('ac-ad-hide')) return
node.setAttribute('ac-ad-hide', '1')
node.style = 'display: none !important;'
}
function safeRemove_xpath(xpathSelector, useHide) {
safeFunc(() => {
let removeNodes = getAllElements(xpathSelector);
if(useHide) {
for (let i = 0; i < removeNodes.length; i++){
hideNode(removeNodes[i])
}
} else {
for (let i = 0; i < removeNodes.length; i++){
removeNodes[i].remove() // 避免卡顿现象
}
}
})
}
function safeRemoveAd(selector) {
[...document.querySelectorAll(selector)].map(one => safeFunc(() => one.remove()))
}
return {
addStyle,
addScript,
safeFunc,
safeGetNodeFunc,
safeWaitFunc,
getUrlAttribute,
http,
refreshAfter: refreshAfter(),
waitTime,
debounce,
throttle,
setIntervalRun,
Reg_Get,
getElementByXpath,
getAllElementsByXpath,
getAllElements,
safeRemoveAd,
safeRemove_xpath
}
})()
const setHostBind = () => {
// 避免多个脚本,重复执行
if (unsafeWindow.isACBaiduInit) {
throw new Error('已经有脚本在运行了,疑似重复安装')
} else {
unsafeWindow.isACBaiduInit = true
}
GM_addValueChangeListener('ACBlockRules', (key, oldVal, newVal = '{}', remote) => {
if (unsafeWindow.webInterface) {
unsafeWindow.webInterface.update()
} else {
CONST.blockRuleList = JSON.parse(newVal) // 将对象设置到CONST上
CONST.acpush_acremoveInit()
}
})
if(location.host.includes('tujidu.com') || location.host.includes('90dao.com') || location.host.includes('localhost')) {
unsafeWindow.AC_GM_Interface = {
async get(key, dataStr) {
if(key.includes('op_')) {
const trueKey = key.replace(/^op_/, '')
const config = JSON.parse(await GM.getValue('ACConfig', '{}'))
let res = config[trueKey] || JSON.parse(dataStr)
if(key.includes('common')) {
res.version = GM_info.script.version
}
return res
} else {
return JSON.parse(await GM.getValue(key, dataStr))
}
},
async save(key, dataObj) {
if(key.includes('op_')) {
const trueKey = key.replace(/^op_/, '')
const config = JSON.parse(await GM.getValue('ACConfig', '{}'))
config[trueKey] = dataObj
GM.setValue('ACConfig', JSON.stringify(config))
GM.setValue('SyncConfig', JSON.stringify({ refreshUrl: true })) // 触发到Sync上,通过Sync通信
} else {
console.log('设置save函数')
GM.setValue(key, JSON.stringify(dataObj)) // 需要是string了
}
},
async change(key, dataObj) {
const trueKey = key.replace(/^op_/, '')
const Sync = JSON.parse(await GM.getValue('ACConfig', '{}'))
Sync[trueKey] = dataObj
GM.setValue('SyncConfig', JSON.stringify(Sync)) // 触发到Sync上,通过Sync通信
},
}
if(location.host.includes('localhost')) {
unsafeWindow.isDevMode = true
}
throw new Error('90dao不需要执行其他函数,抛出异常表示结束')
}
}
try{
setHostBind()
} catch (e)
{
// 不再执行后续函数,停在这里了
return;
}
class SiteOptions {
constructor(_gmInstance) {
this.gmInstance = _gmInstance
// 名字自动映射的
this.siteName = this.gmInstance._getSiteName()
this.useItem = {
SiteTypeID: 0,
MainType: "",
Stype_Normal: "",
FaviconType: "",
FaviconAddTo: "",
CounterType: "",
BlockType: "",
MultiPageType: "",
pager: {
nextLink: "",
pageElement: "",
HT_insert: ["", 2], // 1 = beforebegin; 2 = beforeend
replaceE: "",
stylish: "",
}
}
if(this['_s_' + this.siteName]) {
this.useItem = Object.assign({
pageNum: 1, // 页码
pageUrl: '', // 下一页的地址
}, this['_s_' + this.siteName]())
} else {
this.siteName = ''
}
// 作为静态参数用
this.baidu = this._s_baidu()
this.google = this._s_google()
this.bing = this._s_bing()
this.haosou = this._s_haosou()
this.duckduckgo = this._s_duckduckgo()
this.baidu_xueshu = this._s_baidu_xueshu()
this.google_scholar = this._s_google_scholar()
}
_s_baidu() {
if (this.useItem.SiteTypeID === 1) {
if(location.href.search(/(&|\?)(wd|word)=/) < 0) {
console.mylog('禁用CSS的')
this.gmInstance.curConfig.enableCSS = false
}
}
return {
SiteTypeID: 1,
MainType: "#content_left>.c-container",
Stype_Normal: "h3.t>a, .c-container article a",
FaviconType: ".c-showurl, .c-title a",
FaviconAddTo: "h3",
CounterType: "#content_left>#double>div[srcid] *[class~=t]>a:first-child,[class~=op_best_answer_question],#content_left>div[srcid] *[class~=t]>a:first-child,[class~=op_best_answer_question]",
BlockType: "h3 a",
MultiPageType: "#container #content_left, body[news] #container #content_left>div:not([class]):not([id])",
pager: {
nextLink: '//div[@id="page"]//a[contains(text(),"下一页")][@href]',
pageElement: "css;div#content_left > *",
HT_insert: ["css;div#content_left", 2], // 1 = beforebegin; 2 = beforeend
replaceE: "css;#page",
stylish: ".autopagerize_page_info, div.sp-separator {margin-bottom: 10px !important;}.c-img-border{display:none}",
}
}
}
_s_bing() {
// 图片站 、地图站、购物站
if(this.useItem.SiteTypeID === 5) {
if (location.href.search(/images\/search/) > 0) {
console.mylog("特殊站,不加载样式,不添加menu");
this.gmInstance.curConfig.enableCSS = false
} else if(location.href.search(/search/) > 0) {
this.gmInstance.curConfig.enableCSS = true // 仅在搜索结果页,展示背景图即可
} else {
this.gmInstance.curConfig.enableCSS = false
}
}
return {
SiteTypeID: 5,
MainType: "#b_results>li",
Stype_Normal: "h2>a",
FaviconType: ".b_attribution>cite",
FaviconAddTo: "h2",
CounterType: "#b_results>li[class~=b_ans] h2,#b_results>li[class~=b_algo] h2",
BlockType: "h2 a",
MultiPageType: "#b_content #b_results",
pager: {
nextLink: "//a[contains(@class,\"sb_pagN\")]",
pageElement: "id(\"b_results\")/li[not(contains(@class,\"b_pag\") or contains(@class,\"b_ans b_top\"))]",
HT_insert: ["id(\"b_results\")/li[@class=\"b_pag\"]", 1], // 1 = beforebegin; 2 = beforeend
replaceE: "id(\"b_results\")//nav[@role=\"navigation\"]",
}
}
}
_s_google() {
// 图片站 、地图站、购物站
if (this.useItem.SiteTypeID === 4) {
if(location.href.search(/tbm=(isch|lcl|shop|flm)/) > 0) {
console.mylog("特殊站,不加载样式,不添加menu");
this.gmInstance.curConfig.enableCSS = false
}
}
return {
SiteTypeID: 4,
MainType: "#rso .g, div[data-micp-id='rso'] .g",
FaviconType: ".iUh30",
FaviconAddTo: "h3",
CounterType: "#rso .g h3:not(table h3),._yE>div[class~=_kk] h3",
BlockType: ".g h3", // 修复block翻页的问题
MultiPageType: ".srg, #rso, div[two-father], #rso>div:not(.g), #kp-wp-tab-overview",
pager: {
nextLink: "id('pnnext')|id('navbar navcnt nav')//td[span]/following-sibling::td[1]/a|id('nn')/parent::a",
pageElement: "id('rso')|id('center_col')/style[contains(.,'relative')][id('rso')]",
HT_insert: ["css;#res", 2], // 1 = beforebegin; 2 = beforeend
replaceE: '//div[@id="navcnt"] | //div[@id="rcnt"]//div[@role="navigation"]',
}
}
}
_s_haosou() {
if (this.useItem.SiteTypeID === 3) {}
return {
SiteTypeID: 3,
MainType: ".res-list",
Stype_Normal: "h3>a",
FaviconType: "cite",
FaviconAddTo: "h3",
CounterType: ".results>div",
BlockType: "h3 a",
// TODO 增加这个
MultiPageType: "????????", // 多列模式下,待选择的元素,未来再说
pager: {
nextLink: "//div[@id='page']//a[text()='下一页>'] | id('snext')",
pageElement: "//div[@id='container']/div",
HT_insert: ["//div[@id='container']", 2], // 1 = beforebegin; 2 = beforeend
replaceE: "id('page')"
}
}
}
_s_duckduckgo() {
if (this.useItem.SiteTypeID === 10){}
return {
SiteTypeID: 10,
MainType: "#react-layout li",
FaviconType: ".nrn-react-div .result__url__domain",
FaviconAddTo: "h2",
CounterType: "#react-layout li h2 a",
BlockType: "h2 a",
MultiPageType: "#react-layout .react-results--main",
pager: {
nextLink: "//a[contains(@class,\"sb_pagN\")]",
pageElement: "id(\"b_results\")/li[not(contains(@class,\"b_pag\") or contains(@class,\"b_ans b_top\"))]",
HT_insert: ["id(\"b_results\")/li[@class=\"b_pag\"]", 1], // 1 = beforebegin; 2 = beforeend
replaceE: "id(\"b_results\")//nav[@role=\"navigation\"]",
}
}
}
_s_baidu_xueshu() {
if (this.useItem.SiteTypeID === 8) {
console.warn('启动百度学术特殊设置')
this.gmInstance.curConfig.adsStyleMode = 2
}
return {
SiteTypeID: 8,
MainType: "#content_left .result",
Stype_Normal: "h3.t>a, #results .c-container>.c-blocka",
FaviconType: ".result-op, .c-showurl", // baidu 似乎要改版了?
FaviconAddTo: "h3",
CounterType: "#content_left>#double>div[srcid] *[class~=t]>a,[class~=op_best_answer_question],#content_left>div[srcid] *[class~=t]>a,[class~=op_best_answer_question]",
BlockType: "h3 a",
}
}
_s_google_scholar() {
if (this.useItem.SiteTypeID === 4.1) {}
return {
SiteTypeID: 4.1,
MainType: "#rso .g, div[data-micp-id='rso'] .g",
FaviconType: ".iUh30",
FaviconAddTo: "h3",
CounterType: "#rso .g h3:not(table h3),._yE>div[class~=_kk] h3",
BlockType: "a:not([href*='translate.google.com'])", // 修复block翻页的问题
pager: {
nextLink: '//a[./span[@class="gs_ico gs_ico_nav_next"]]',
pageElement: '//div[@class="gs_r gs_or gs_scl"]',
HT_insert: null, // 1 = beforebegin; 2 = beforeend
replaceE: '//div[@id="navcnt"] | //div[@id="rcnt"]//div[@role="navigation"]',
}
}
}
}
class BaseConfig {
constructor(isEngine = true) {
this.commonStyleEnable = true // 是否开启默认效果优化
this.commonStyleLink = ''
this.commonStyleLess = ''
// 搜索引擎的逻辑
if(isEngine) {
this.adsStyleEnable = true // 是否开启默认效果优化
this.adsStyleMode = '3' // 0-不带css;1-单列靠左;2-单列居中;3-双列居中
this.HuYanMode = false // 护眼模式
this.HuYanMode_Color = '#ffffff' // 护眼模式-颜色
this.BgEnable = false // 背景图-是否启用
this.BgUseUrl = '' // 默认背景图
this.BgFit = true // 背景图-是否适应
this.BgBase64Image = '' // 这个KEY暂时不使用
this.customStyleEnable = false
this.customStyleLink = ''
this.customStyleLess = ''
}
}
}
class CSSAutoInsert {
constructor() {
this.hasChanged = false
this.cssInsertSet = {}
MyApi.setIntervalRun(()=> {
if(this.hasChanged) {
this.hasChanged = false
this.doInsert()
}
}, 50)
}
add(uniqueName, cssText) {
uniqueName = 'AC-' + uniqueName // 加上特殊前缀,标志关键词
// 如果有,并且数据还一模一样,那么跳过
if (this.cssInsertSet[uniqueName] && this.cssInsertSet[uniqueName] === cssText) {
return
}
console.mylog('--->插入样式表:' + uniqueName)
this.cssInsertSet[uniqueName] = `\n/************${uniqueName}*********/\n` + cssText
this.hasChanged = true
}
clear() {
this.cssInsertSet = {}
this.hasChanged = true
}
doInsert() {
const cssText = Object.values(this.cssInsertSet).join('\n')
MyApi.addStyle(cssText, Object.keys(this.cssInsertSet).join(' ')) // 方便排查css插入
console.mylog('插入CSS完成')
}
}
class ACGM {
constructor() {
this.initGM()
this.bindGM()
}
async initACGM() {
let ACConfig = {}
this.blockRuleList = []
const DefaultConfig = {
common: {
version: '', // 从代码中动态拉取,丢弃任何值
isDevMode: false, // 是否为调试模式,从页面给出来的
isLocalDevMode: false, // 是否为本地调试模式,从页面给出来的,用于加载本地CSS
localDebugBaseUrl: '', // 本地调试模式,本地CSS的入口地址
isRedirectEnable: false, // 是否开启重定向功能
isAdsEnable: false, // 是否开启去广告模式
isFaviconEnable: true, // 是否开启Favicon图标
isAutopage: true, // 是否开启自动翻页功能
isBlockEnable: true, // 是否开启去拦截模式
isBlockResultDisplay: true, // 是否删除已拦截的条目
isBlockBtnDisplay: false, // 是否显示block按钮
isRightDisplayEnable: true, // 是否开启右侧边栏
isCounterEnable: false, // 是否显示计数器
isALineDisable: false, // 是否禁止下划线
isDarkModeEnable: false, // 是否加载暗黑模式
...new BaseConfig(false)
},
baidu: {
doRemoveSug: true, // 删除移动预测
doRemoveAIGen: false, // 移除百度AI搜索结果
baiduLiteEnable: false, // 启用百度Lite样式表
...new BaseConfig()
},
google: {
useBaiduLogo: false, // 默认不使用百度logo
...new BaseConfig()
},
bing: {
optimizeBing: true,
...new BaseConfig()
},
duckduckgo: {
optimizeDuckDuckGo: true, // 是否开启优化
...new BaseConfig()
}
};
try {
let res = await GM.getValue("ACConfig", "{}")
ACConfig = JSON.parse(res);
res = await GM.getValue("ACBlockRules", "[]")
this.blockRuleList = JSON.parse(res);
this.acpush_acremoveInit()
} catch (e) {
console.error('出bug了')
ACConfig = DefaultConfig
}
// 随便给一个值初始化,这个值,只是临时的值,如果需要写入,也是从另一端拉取,不是这个值来覆盖的
this.curConfig = {
...DefaultConfig.common,
...DefaultConfig.baidu
}
this.sortIndex = 1
this.bingScrollPos = 0
this.ACConfig = Object.assign({}, DefaultConfig, ACConfig) // 作为临时修改用
// this.enableCSS = true
this.cssAutoInsert = new CSSAutoInsert()
this.cssFavionList = reactive({
list: []
})
this.adsCSSList = {
baiduLiteStyle: '',
leftCommonStyle: '',
onePageStyle: '',
twoPageStyle: '',
multiPageStyle: '',
expandPageStyle: '',
customStyle: '', // 自定义样式表
commonStyle: '', // 全局样式表
huyanStyle: '',
bgAutoFitStyle: '',
darkModeStyle: '', // 暗黑护眼色
faviconStyle: '', // 动态插入的favicon的数据
}
this.lock = {
bodyLocked: true,
headLocked: true,
pageLoadingLocked: false,
isBlockChecking: false,
afterBlockChangeChecked: true, // 数据刷新后,是否检查过了,用于减少reg判定
}
// 数据先初始化
this.curConfig = reactive({
enableCSS: true,
...this.ACConfig.common,
...this.ACConfig[this._getSiteName()]
})
// 再得到真实options,并调整config
this.options = new SiteOptions(this)
await this.loadSiteCSS()
this.waitBodyHead()
this.openSeetingsUrl = ''
this.check90daoConn()
}
initGM() {
if (typeof (GM) === "undefined") {
// 这个是ViolentMonkey的支持选项
GM = {};
GM.setValue = GM_setValue;
GM.getValue = GM_getValue;
}
if (typeof GM_getResourceText === 'undefined') {
GM_getResourceText = async function(aResourceName) {
// 如果没有这个接口,那就是没办法缓存这个数据,所以只能用本地的数据进行缓存了
let res = await (await fetch(await GM.getResourceUrl(aResourceName))).text();
let saveRes = await GM.getValue(aResourceName);
if (typeof (saveRes) === 'undefined') {
GM.setValue(aResourceName, res);
} else {
return saveRes;
}
return res;
}
}
}
bindGM() {
GM_registerMenuCommand('AC-重定向脚本设置', function() {
window.open(CONST.openSeetingsUrl)
});
GM_registerMenuCommand('脚本重置 - 修复脚本', function() {
GM.setValue('ACConfig', '{}');
location.reload();
});
}
check90daoConn() {
const storeValue = sessionStorage.getItem('access_90dao')
this.openSeetingsUrl = storeValue || 'https://ac-baidu.tujidu.com/pages/custom/#' + CONST.options.siteName
if (!storeValue) {
console.log('目前不存在')
GM_xmlhttpRequest({
method: "HEAD",
timeout: 3000,
url: "https://ac-baidu.90dao.com/",
onload: ()=> {
this.openSeetingsUrl = 'https://ac-baidu.90dao.com/pages/custom/#' + CONST.options.siteName
sessionStorage.setItem('access_90dao', this.openSeetingsUrl)
},