AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列

1.繞過百度、搜狗、谷歌、好搜搜索結果中的自己的跳轉鏈接,直接訪問原始網頁-反正都能看懂 2.新增自定义网站拦截功能 3添加Favicon显示 4.页面CSS 5.添加计数 6.开关选择以上功能 7.自动翻页功能

  1. // ==UserScript==
  2. // @name AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列
  3. // @name:en AC-baidu-google_sogou_bing_RedirectRemove_favicon_adaway_TwoLine
  4. // @name:zh AC-baidu-重定向优化百度搜狗谷歌必应搜索_favicon_双列
  5. // @name:ja AC-baidu-重定向最適化Baiduの搜狗のGoogleのBing検索結果のリダイレクト除去+favicon
  6. // @description 1.繞過百度、搜狗、谷歌、好搜搜索結果中的自己的跳轉鏈接,直接訪問原始網頁-反正都能看懂 2.新增自定义网站拦截功能 3添加Favicon显示 4.页面CSS 5.添加计数 6.开关选择以上功能 7.自动翻页功能
  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
  8. // @description:ja 1.迂回Baidu、Sogou、Google、Haosou検索検索結果の中の自分の遷移リンク; 2.Baiduの余分な広告を取り除く; 3.コメントを追加; 4.ページのカスタムCSP; 5.カウントを追加; 6.スイッチは以上の機能を選択します; 7.自動ページめくり.
  9. // @icon https://ae01.alicdn.com/kf/Hac1a58055c5047cdb91349e91aa208d5k.jpg
  10. // @author AC
  11. // @license GPL-3.0-only
  12. // @create 2015-11-25
  13. // @run-at document-start
  14. // @version 27.07
  15. // @connect baidu.com
  16. // @connect google.com
  17. // @connect google.com.hk
  18. // @connect google.com.jp
  19. // @connect bing.com
  20. // @connect duckduckgo.com
  21. // @connect dogedoge.com
  22. // @connect so.com
  23. // @connect localhost
  24. // @connect 90dao.com
  25. // @connect *
  26. // @include *://ipv6.baidu.com/*
  27. // @include *://www.baidu.com/*
  28. // @include *://www1.baidu.com/*
  29. // @include *://m.baidu.com/*
  30. // @include *://xueshu.baidu.com/s*
  31. // @include *://www.so.com/s?*
  32. // @include *://*.bing.com/*
  33. // @include *://encrypted.google.*/search*
  34. // @include *://*.google*/search*
  35. // @include *://scholar.google.com/scholar*
  36. // @include *://*.google*/webhp*
  37. // @include *://*duckduckgo.com/*
  38. // @include *://*.dogedoge.com/*
  39. // @include *://*.90dao.com/*
  40. // @include *://*.tujidu.com/*
  41. // @include *://localhost*/*
  42. // @exclude *://*.google*/sorry*
  43. // @exclude https://zhidao.baidu.com/*
  44. // @exclude https://*.zhidao.baidu.com/*
  45. // @exclude https://www.baidu.com/img/*
  46. // @exclude https://lens.google.com/*
  47. // @supportURL https://ac.tujidu.com/
  48. // @home-url https://greasyfork.org/zh-TW/scripts/14178
  49. // @home-url2 https://github.com/langren1353/GM_script
  50. // @homepageURL https://greasyfork.org/zh-TW/scripts/14178
  51. // @copyright 2015-2025, AC
  52. // @lastmodified 2024-11-17
  53. // @feedback-url https://github.com/langren1353/GM_script
  54. // @note 2024.11-17-V27.07 fix:谷歌排版问题、谷歌翻页后图片无效问题
  55. // @note 2024.08-26-V27.06 fix:暗黑模式
  56. // @note 2024.08-19-V27.05 fix:拦截功能、被拦截域名问题、和其他脚本兼容的CSS植入问题、优化域名检测逻辑;
  57. // @note 2024.08-16-V27.04 修复:谷歌双列加载缓慢、双列效果优化、单列居中效果优化;bing页面bug修复;暗黑模式引入;编号、下划线功能修复;鸭鸭修复 & 勿忘国耻
  58. // @note 2024.08-09-V27.03 增加字节跳动的Vue地址,避免部分地区打不开lib.baomitu.com导致的脚本无效
  59. // @note 2024.08-06-V27.02 更换域名,解决SNI拦截问题;优化右侧栏显示逻辑-双列以上隐藏
  60. // @note 2024.08-06-V27.01 重构-十周年优化版,优化项:1.重构设置功能,提供更强大的设置功能;2.极大优化页面加载动画效果;3.修复现有页面显示和效果(谷歌[主]、必应)单列、多列;4.兼容ViolentMonkey,兼容Firefox浏览器
  61. // @note 2024.03-05-V26.10 fix: 谷歌白屏的问题;再次支持鸭鸭搜索引擎,鸭鸭三列支持;baidu\Google双列功能
  62. // @note 2023.12-16-V26.07 日常维护;优化各页面加载卡顿的问题,优化搜索引擎显示效果
  63. // @note 2023.06-19-V26.06 修复谷歌显示效果的错位问题等,修复谷歌异常白屏问题
  64. // @note 2022.12-07-V26.04 修复必应错位问题;优化谷歌双列动画问题
  65. // @note 2022.08-23-V26.03 修复因背景图引起的看不清字的问题;修复百度单列错位问题;修复google自定义按钮不可见
  66. // @note 2022.08-23-V26.02 加快代码执行速度;减少动画撕裂;替换CDN的md5库
  67. // @note 2022.08-22-V26.01 因甲癌手术和公司事务停更了2个月,目前补上,推荐更新。 1.修复百度加载缓慢的问题;2.修复谷歌样式加载顺序异常的问题;3.整体优化样式加载时间,更流畅了
  68. // @note 2022.06-18-V25.09 修复可能出现的脚本参数读取失败导致的脚本不执行的异常 & 修复 拦截规则特殊参数的问题 & 更换CDN地址
  69. // @note 2022.06-16-V25.06 优化重定向逻辑,部分网站只需要稍作处理,不用做接口请求了,感谢众多搜索引擎的版本迭代更新
  70. // @note 2022.04-08-V25.05 主要修复Block功能;其次优化样式加载速度-减少撕裂感
  71. // @note 2022.03-07-V25.04 修复谷歌、必应样式问题;修复并优化拦截功能
  72. // @note 2022.01-29-V25.02 修复谷歌、百度、必应的部分样式错位的问题
  73. // @note 2021.12-06-V25.01 修复百度样式偏左 & 修复谷歌样式显示
  74. // @note 2021.10-31-V24.29 fixed Less requirement for faster Load
  75. // @note 2021.10-29-V24.27 移除必应能选择的广告;增加自定义样式less的支持
  76. // @note 2021.09-02-V24.26 修复必应多favicon,修复百度百科问题;修复谷歌一个小问题
  77. // @note 2021.07-16-V24.25 修复一个bug;兼容百度下搜索股票tag;
  78. // @note 2021.06-15-V24.24 更换cdn地址
  79. // @note 2017.05.12 -> 2021.06-15 && V8.6 -> V24.24 各种各样的历史更新记录,从一个版本迭代到另一个版本
  80. // @note 2017.05.12-V8.4 新增:默认屏蔽谷歌的安全搜索功能
  81. // @note 2017.05.05-V8.3 修复include范围太小导致的百度知道的屏蔽问题
  82. // @note 2017.05.04-V8.2 终于修复了百度知道图片替换了文字的这个大BUG; 顺便处理了superapi.zhidao.baidu.com; 新增谷歌搜索结果重定向去除
  83. // @note 2017.05.04-V8.1 终于修复了百度知道图片替换了文字的这个大BUG,顺便处理了superapi.zhidao.baidu.com
  84. // @note 2017.05.04-V8.0 终于修复了百度知道图片替换了文字的这个大BUG,待测试
  85. // @note 2017.03.28-V7.6 修复在ViolentMonkey上的不支持的问题
  86. // @note 2017.03.28-V7.5 尝试修复chrome上的问题
  87. // @note 2017.03.21-V7.4 尝试处理Edge上不支持的问题,结果发现是Edge本身的TamperMonkey支持有问题
  88. // @note 2017.03.19-V7.3 修复打开百度之后再次点击“百度一下”导致的无法更新重定向问题
  89. // @note 2017.03.19-V7.2 未知原因chrome的MutationObserver无法使用了,继续回归以前的DOMNodeInserted
  90. // @note 2017.02.17-V7.0 修复搜狗的搜索结果重定向问题+改个名字
  91. // @note 2017.02.17-V6.9 修复搜狗的搜索结果重定向问题
  92. // @note 2016.10.27-V6.7 修复了以前的重复请求,现在的请求数应该小了很多,网络也就不卡了,感觉萌萌哒
  93. // @note 2016.04.24-V6.6 恢复以前的版本,因为兼容性问题
  94. // @note 2015.12.01-V5.0 加入搜狗的支持,但是支持不是很好
  95. // @note 2015.11.25-V2.0 优化,已经是真实地址的不再尝试获取
  96. // @note 2015.11.25-V1.0 完成去掉百度重定向的功能
  97. // @resource baiduCommonStyle https://ibaidu.tujidu.com/newcss/baiduCommonStyle.less?t=27.04
  98. // @resource baiduOnePageStyle https://ibaidu.tujidu.com/newcss/baiduOnePageStyle.less?t=27.04
  99. // @resource baiduTwoPageStyle https://ibaidu.tujidu.com/newcss/baiduTwoPageStyle.less?t=27.04
  100. // @resource googleCommonStyle https://ibaidu.tujidu.com/newcss/googleCommonStyle.less?t=27.04
  101. // @resource googleOnePageStyle https://ibaidu.tujidu.com/newcss/googleOnePageStyle.less?t=27.04
  102. // @resource googleTwoPageStyle https://ibaidu.tujidu.com/newcss/googleTwoPageStyle.less?t=27.04
  103. // @resource bingCommonStyle https://ibaidu.tujidu.com/newcss/bingCommonStyle.less?t=27.04
  104. // @resource bingOnePageStyle https://ibaidu.tujidu.com/newcss/bingOnePageStyle.less?t=27.04
  105. // @resource bingTwoPageStyle https://ibaidu.tujidu.com/newcss/bingTwoPageStyle.less?t=27.04
  106. // @resource duckduckgoCommonStyle https://ibaidu.tujidu.com/newcss/duckCommonStyle.less?t=27.04
  107. // @resource duckduckgoOnePageStyle https://ibaidu.tujidu.com/newcss/duckOnePageStyle.less?t=27.04
  108. // @resource duckduckgoTwoPageStyle https://ibaidu.tujidu.com/newcss/duckTwoPageStyle.less?t=27.04
  109. // @resource dogeCommonStyle https://ibaidu.tujidu.com/newcss/dogeCommonStyle.less?t=27.04
  110. // @resource dogeOnePageStyle https://ibaidu.tujidu.com/newcss/dogeOnePageStyle.less?t=27.04
  111. // @resource dogeTwoPageStyle https://ibaidu.tujidu.com/newcss/dogeTwoPageStyle.less?t=27.04
  112. // @resource HuYanStyle https://ibaidu.tujidu.com/newcss/HuYanStyle.less?t=27.04
  113. // @resource BgAutoFit https://ibaidu.tujidu.com/newcss/BgAutoFit.less?t=27.04
  114. // @resource HuaHua-ACDrakMode https://ibaidu.tujidu.com/newcss/HuaHua-ACDrakMode.less?t=27.04
  115. // @resource baiduLiteStyle https://gitcode.net/-/snippets/1906/raw/master/LiteStyle.css?inline=false
  116. // @require https://update.greasyfork.org/scripts/433620/1422795/Less4_1_2_fixed.js
  117. // @require https://lib.baomitu.com/vue/3.2.31/vue.runtime.global.prod.min.js
  118. // @require https://lf6-cdn-tos.bytecdntp.com/cdn/expire-10-y/vue/3.2.31/vue.runtime.global.prod.min.js
  119. // @noframes
  120. // @grant GM_info
  121. // @grant GM_getValue
  122. // @grant GM.getValue
  123. // @grant GM_setValue
  124. // @grant GM.setValue
  125. // @grant GM_addStyle
  126. // @grant GM_getResourceURL
  127. // @grant GM_listValues
  128. // @grant GM.getResourceUrl
  129. // @grant GM_xmlhttpRequest
  130. // @grant GM_getResourceText
  131. // @grant GM_registerMenuCommand
  132. // @grant GM_addValueChangeListener
  133. // @grant unsafeWindow
  134. // @namespace 1353464539@qq.com
  135. // ==/UserScript==
  136. ~(async () => {
  137. Object.defineProperty(console, 'mylog', {
  138. value: function() {
  139. if(CONST && CONST.curConfig) {
  140. if(CONST.curConfig.isDevMode) {
  141. const error = new Error();
  142. const stackTrace = error.stack.split('\n')[2].trim(); // 获取调用栈信息
  143. try{
  144. const [targetLink] = /chrome-extension:\/\/(.*)/.exec(stackTrace) // 提取文件名和行号
  145. const data = [...arguments].join(' ').padEnd(60, ' ')
  146. console.log(data, `\t\t ${targetLink}`); // 结合自定义输出和调用栈信息
  147. }catch (e){
  148. // console.error(error.stack)
  149. console.log('[log] -', ...arguments); // 如果没有匹配到文件名和行号,则只输出自定义信息
  150. }
  151. }
  152. } else {
  153. console.log.apply(this, arguments);
  154. }
  155. },
  156. })
  157. const { reactive, watch } = Vue;
  158. const MyApi = (() => {
  159. /**
  160. * @param cssText CSS的内容,如果是less的话,需要编译后的
  161. * @param className 新增的类名,或者是一堆类名(空格隔开)
  162. */
  163. function addStyle(cssText, className = ''){ // 添加CSS代码,不考虑文本载入时间,带有className
  164. if(className) {
  165. const selectorName = (' ' + className).split(' ').join('.')
  166. let oldNode = document.querySelector(selectorName)
  167. if(!oldNode) {
  168. oldNode = document.createElement("style");
  169. oldNode.className = className;
  170. MyApi.safeFunc(() => {
  171. document.children[0].appendChild(oldNode);
  172. })
  173. }
  174. oldNode.innerHTML = cssText;
  175. }
  176. }
  177.  
  178. /**
  179. * 脚本一般来说只需要插入一次的,所以不加入重载功能
  180. * @param scriptText 新增的脚本的名字
  181. */
  182. function addScript(scriptText) {
  183. const scriptNode = document.createElement('script')
  184. scriptNode.innerText = scriptText
  185. document.head.appendChild(scriptNode)
  186. }
  187.  
  188. /**
  189. * 安全脚本执行
  190. * @param callback 回调函数
  191. * @param catchCallback 异常的回调函数
  192. */
  193. const safeFunc = (callback, catchCallback = () => {}) => {
  194. try{
  195. return callback()
  196. }catch (e){
  197. console.mylog(e)
  198. return catchCallback()
  199. }
  200. }
  201.  
  202. const safeGetNodeFunc = (selector, callbackFunc) => {
  203. const node = document.querySelector(selector)
  204. if(node) {
  205. callbackFunc(node)
  206. }
  207. }
  208.  
  209. /**
  210. * 等待元素后,执行的函数
  211. * @param selector 选择器 | 选择的函数
  212. * @param callbackFunc 回调函数
  213. * @param findTick 查询周期,默认200
  214. * @param clearAfterFind 查询完成后自动结束?
  215. * @param timeout 查询超时,超时后停止
  216. * @param errCallback 查询超时后,回调
  217. */
  218. const safeWaitFunc = async(selector, callbackFunc = node => {
  219. }, findTick = 200, clearAfterFind = true, timeout = 20000 * 1000, errCallback) => {
  220. if(findTick < 20) findTick = 20
  221. let count = timeout / findTick
  222. let t_id = null
  223. const firstSuccess = await mainRunFunc()
  224. if (!clearAfterFind || !firstSuccess) {
  225. t_id = setInterval(mainRunFunc, findTick);
  226. }
  227.  
  228. async function strRun() {
  229. let hasFind = false
  230. let selectRes = document.querySelectorAll(selector);
  231. if (selectRes.length <= 0) {
  232. hasFind = false
  233. }
  234. if (selectRes.length >= 1) {
  235. selectRes = selectRes[0];
  236. hasFind = true
  237. }
  238.  
  239. if (clearAfterFind && hasFind) {
  240. clearId();
  241. await callbackFunc(selectRes)
  242. }
  243. return hasFind
  244. }
  245.  
  246. async function funcRun() {
  247. let hasFind = false
  248. const res = selector()
  249. if (res && res.length > 0) {
  250. hasFind = true
  251. if (clearAfterFind && hasFind) clearId();
  252. await callbackFunc(selector()[0]);
  253. } else if (res) {
  254. hasFind = true
  255. if (clearAfterFind && hasFind) clearId();
  256. await callbackFunc();
  257. }
  258. return hasFind
  259. }
  260.  
  261. async function mainRunFunc() {
  262. if (count-- < 0) {
  263. clearId()
  264. errCallback && errCallback()
  265. }
  266.  
  267. if ((typeof (selector) == "string")) {
  268. return await strRun()
  269. } else if (typeof (selector) === "function") {
  270. return await funcRun()
  271. }
  272. }
  273.  
  274. function clearId() {
  275. if (t_id) clearInterval(t_id)
  276. }
  277. }
  278.  
  279. /**
  280. * 提取URL参数数据
  281. * @param attribute 参数Key
  282. * @param needDecode 是否需要解码,默认解码
  283. * @param baseUrl 默认网址来源
  284. * @returns {string} 变量结果Value
  285. */
  286. function getUrlAttribute(baseUrl = location.href, attribute, needDecode = true){
  287. const [, search = ''] = baseUrl.split("?");
  288. var searchValue = search.split("&");
  289. for (var i = 0; i < searchValue.length; i++) {
  290. var key_value = searchValue[i].split("=");
  291. var reg = new RegExp("^"+attribute+"$");
  292. if (reg.test(key_value[0])) {
  293. var searchWords = key_value[1];
  294. return needDecode?decodeURIComponent(searchWords):searchWords;
  295. }
  296. }
  297. }
  298.  
  299. const http = {
  300. async get(url) {
  301. return new Promise((resolve, reject) => {
  302. const timeout = 10000
  303. GM_xmlhttpRequest({
  304. url,
  305. fetch: true,
  306. method: 'GET',
  307. timeout: timeout,
  308. onload: resp => {
  309. resolve([null, resp.responseText, resp.responseHeaders])
  310. },
  311. onerror: resp => {
  312. reject([resp, '', {}])
  313. }
  314. })
  315. })
  316. },
  317. async post(url, data) {
  318. return new Promise((resolve, reject) => {
  319. GM_xmlhttpRequest({
  320. url,
  321. data,
  322. method: 'POST',
  323. timeout: 10000,
  324. onload: resp => resolve([null, resp.responseText, resp.responseHeaders]),
  325. onerror: resp => reject([resp, {}])
  326. })
  327. })
  328. }
  329. }
  330.  
  331. /**
  332. * 等待多久后,重新加载网页
  333. * @param timeout
  334. */
  335. const refreshAfter = () => {
  336. let id = null
  337. return (timeout) => {
  338. clearTimeout(id)
  339. id = setTimeout(() => {
  340. location.reload()
  341. }, timeout)
  342. }
  343. }
  344.  
  345. /**
  346. * 等待多少ms后执行
  347. * @param ms 毫秒
  348. * @returns {Promise<unknown>}
  349. */
  350. const waitTime = (ms) => {
  351. return new Promise(resolve => {
  352. setTimeout(resolve, ms);
  353. });
  354. }
  355.  
  356. const debounce = (fn, delay) => {
  357. let timer = null;
  358.  
  359. return function () {
  360. clearTimeout(timer);
  361. timer = setTimeout(() => {
  362. fn.apply(this, arguments);
  363. }, delay);
  364. };
  365. }
  366.  
  367. const throttle = (fn, delay) => {
  368. let timer = null;
  369. let startTime = Date.now();
  370.  
  371. return function () {
  372. const curTime = Date.now();
  373. const remaining = delay - (curTime - startTime);
  374.  
  375. clearTimeout(timer);
  376.  
  377. if (remaining <= 0) {
  378. fn.apply(this, arguments);
  379. startTime = Date.now();
  380. } else {
  381. timer = setTimeout(() => {
  382. fn.apply(this, arguments);
  383. startTime = Date.now();
  384. }, remaining);
  385. }
  386. };
  387. }
  388.  
  389. /**
  390. *
  391. * @param callback 回调函数
  392. * @param timeout 定时周期
  393. * @param mustWaitEnd 必须等待上次执行结束?true = 等待;false=标准Interval
  394. * @constructor
  395. */
  396. const setIntervalRun = (callback, timeout, mustWaitEnd = true) => {
  397. let isLocked = false
  398. return setInterval(() => {
  399. if (mustWaitEnd || !isLocked) {
  400. isLocked = true
  401. callback()
  402. isLocked = false
  403. }
  404. }, timeout)
  405. }
  406.  
  407. function Reg_Get(HTML, reg) {
  408. let RegE = new RegExp(reg);
  409. try {
  410. return RegE.exec(HTML)[1];
  411. } catch (e) {
  412. return "";
  413. }
  414. }
  415. function getElementByXpath(e, t, r = document) {
  416. t = t || r;
  417. try {
  418. return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  419. } catch (t) {
  420. return void console.error("无效的xpath");
  421. }
  422. }
  423.  
  424. function getAllElementsByXpath(xpath, contextNode, doc = document) {
  425. contextNode = contextNode || doc;
  426. const result = [];
  427.  
  428. try {
  429. const query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  430.  
  431. for (let i = 0; i < query.snapshotLength; i++) {
  432. const node = query.snapshotItem(i); //if node is an element node
  433.  
  434. if (node.nodeType === 1) result.push(node);
  435. }
  436. } catch (err) {
  437. throw new Error(`Invalid xpath: ${xpath}`);
  438. }
  439. return result;
  440. }
  441.  
  442. // 翻页用的获取器
  443. const getAllElements = (selector, contextNode, doc = document, win = window, _cplink = undefined) => {
  444. if (!selector) return []; //@ts-ignore
  445.  
  446. contextNode = contextNode || doc;
  447.  
  448. if (typeof selector === 'string') {
  449. if (selector.search(/^css;/i) === 0) {
  450. return contextNode.querySelectorAll(selector.slice(4))
  451. } else {
  452. return getAllElementsByXpath(selector, contextNode, doc);
  453. }
  454. } else {
  455. const query = selector(doc, win, _cplink);
  456.  
  457. if (!Array.isArray(query)) {
  458. throw new Error('Wrong type is returned by getAllElements');
  459. } else {
  460. return query;
  461. }
  462. }
  463. }
  464.  
  465. function hideNode(node) {
  466. if(node.hasAttribute('ac-ad-hide')) return
  467. node.setAttribute('ac-ad-hide', '1')
  468. node.style = 'display: none !important;'
  469. }
  470.  
  471. function safeRemove_xpath(xpathSelector, useHide) {
  472. safeFunc(() => {
  473. let removeNodes = getAllElements(xpathSelector);
  474. if(useHide) {
  475. for (let i = 0; i < removeNodes.length; i++){
  476. hideNode(removeNodes[i])
  477. }
  478. } else {
  479. for (let i = 0; i < removeNodes.length; i++){
  480. removeNodes[i].remove() // 避免卡顿现象
  481. }
  482. }
  483. })
  484. }
  485.  
  486. function safeRemoveAd(selector) {
  487. [...document.querySelectorAll(selector)].map(one => safeFunc(() => one.remove()))
  488. }
  489.  
  490. return {
  491. addStyle,
  492. addScript,
  493. safeFunc,
  494. safeGetNodeFunc,
  495. safeWaitFunc,
  496. getUrlAttribute,
  497. http,
  498. refreshAfter: refreshAfter(),
  499. waitTime,
  500. debounce,
  501. throttle,
  502. setIntervalRun,
  503. Reg_Get,
  504. getElementByXpath,
  505. getAllElementsByXpath,
  506. getAllElements,
  507. safeRemoveAd,
  508. safeRemove_xpath
  509. }
  510. })()
  511. const setHostBind = () => {
  512. // 避免多个脚本,重复执行
  513. if (unsafeWindow.isACBaiduInit) {
  514. throw new Error('已经有脚本在运行了,疑似重复安装')
  515. } else {
  516. unsafeWindow.isACBaiduInit = true
  517. }
  518. GM_addValueChangeListener('ACBlockRules', (key, oldVal, newVal = '{}', remote) => {
  519. if (unsafeWindow.webInterface) {
  520. unsafeWindow.webInterface.update()
  521. } else {
  522. CONST.blockRuleList = JSON.parse(newVal) // 将对象设置到CONST上
  523. CONST.acpush_acremoveInit()
  524. }
  525. })
  526. if(location.host.includes('tujidu.com') || location.host.includes('90dao.com') || location.host.includes('localhost')) {
  527. unsafeWindow.AC_GM_Interface = {
  528. async get(key, dataStr) {
  529. if(key.includes('op_')) {
  530. const trueKey = key.replace(/^op_/, '')
  531. const config = JSON.parse(await GM.getValue('ACConfig', '{}'))
  532. let res = config[trueKey] || JSON.parse(dataStr)
  533. if(key.includes('common')) {
  534. res.version = GM_info.script.version
  535. }
  536. return res
  537. } else {
  538. return JSON.parse(await GM.getValue(key, dataStr))
  539. }
  540. },
  541. async save(key, dataObj) {
  542. if(key.includes('op_')) {
  543. const trueKey = key.replace(/^op_/, '')
  544. const config = JSON.parse(await GM.getValue('ACConfig', '{}'))
  545. config[trueKey] = dataObj
  546. GM.setValue('ACConfig', JSON.stringify(config))
  547. GM.setValue('SyncConfig', JSON.stringify({ refreshUrl: true })) // 触发到Sync上,通过Sync通信
  548. } else {
  549. console.log('设置save函数')
  550. GM.setValue(key, JSON.stringify(dataObj)) // 需要是string了
  551. }
  552. },
  553. async change(key, dataObj) {
  554. const trueKey = key.replace(/^op_/, '')
  555. const Sync = JSON.parse(await GM.getValue('ACConfig', '{}'))
  556. Sync[trueKey] = dataObj
  557. GM.setValue('SyncConfig', JSON.stringify(Sync)) // 触发到Sync上,通过Sync通信
  558. },
  559. }
  560.  
  561. if(location.host.includes('localhost')) {
  562. unsafeWindow.isDevMode = true
  563. }
  564.  
  565. throw new Error('90dao不需要执行其他函数,抛出异常表示结束')
  566. }
  567. }
  568. try{
  569. setHostBind()
  570. } catch (e)
  571. {
  572. // 不再执行后续函数,停在这里了
  573. return;
  574. }
  575. class SiteOptions {
  576. constructor(_gmInstance) {
  577. this.gmInstance = _gmInstance
  578. // 名字自动映射的
  579. this.siteName = this.gmInstance._getSiteName()
  580. this.useItem = {
  581. SiteTypeID: 0,
  582. MainType: "",
  583. Stype_Normal: "",
  584. FaviconType: "",
  585. FaviconAddTo: "",
  586. CounterType: "",
  587. BlockType: "",
  588. MultiPageType: "",
  589. pager: {
  590. nextLink: "",
  591. pageElement: "",
  592. HT_insert: ["", 2], // 1 = beforebegin; 2 = beforeend
  593. replaceE: "",
  594. stylish: "",
  595. }
  596. }
  597.  
  598. if(this['_s_' + this.siteName]) {
  599. this.useItem = Object.assign({
  600. pageNum: 1, // 页码
  601. pageUrl: '', // 下一页的地址
  602. }, this['_s_' + this.siteName]())
  603. } else {
  604. this.siteName = ''
  605. }
  606.  
  607. // 作为静态参数用
  608. this.baidu = this._s_baidu()
  609. this.google = this._s_google()
  610. this.bing = this._s_bing()
  611. this.haosou = this._s_haosou()
  612. this.duckduckgo = this._s_duckduckgo()
  613. this.baidu_xueshu = this._s_baidu_xueshu()
  614. this.google_scholar = this._s_google_scholar()
  615. }
  616.  
  617. _s_baidu() {
  618. if (this.useItem.SiteTypeID === 1) {
  619. if(location.href.search(/(&|\?)(wd|word)=/) < 0) {
  620. console.mylog('禁用CSS的')
  621. this.gmInstance.curConfig.enableCSS = false
  622. }
  623. }
  624.  
  625. return {
  626. SiteTypeID: 1,
  627. MainType: "#content_left>.c-container",
  628. Stype_Normal: "h3.t>a, .c-container article a",
  629. FaviconType: ".c-showurl, .c-title a",
  630. FaviconAddTo: "h3",
  631. 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]",
  632. BlockType: "h3 a",
  633. MultiPageType: "#container #content_left, body[news] #container #content_left>div:not([class]):not([id])",
  634. pager: {
  635. nextLink: '//div[@id="page"]//a[contains(text(),"下一页")][@href]',
  636. pageElement: "css;div#content_left > *",
  637. HT_insert: ["css;div#content_left", 2], // 1 = beforebegin; 2 = beforeend
  638. replaceE: "css;#page",
  639. stylish: ".autopagerize_page_info, div.sp-separator {margin-bottom: 10px !important;}.c-img-border{display:none}",
  640. }
  641. }
  642. }
  643.  
  644. _s_bing() {
  645. // 图片站 、地图站、购物站
  646. if(this.useItem.SiteTypeID === 5) {
  647. if (location.href.search(/images\/search/) > 0) {
  648. console.mylog("特殊站,不加载样式,不添加menu");
  649. this.gmInstance.curConfig.enableCSS = false
  650. } else if(location.href.search(/search/) > 0) {
  651. this.gmInstance.curConfig.enableCSS = true // 仅在搜索结果页,展示背景图即可
  652. } else {
  653. this.gmInstance.curConfig.enableCSS = false
  654. }
  655. }
  656.  
  657. return {
  658. SiteTypeID: 5,
  659. MainType: "#b_results>li",
  660. Stype_Normal: "h2>a",
  661. FaviconType: ".b_attribution>cite",
  662. FaviconAddTo: "h2",
  663. CounterType: "#b_results>li[class~=b_ans] h2,#b_results>li[class~=b_algo] h2",
  664. BlockType: "h2 a",
  665. MultiPageType: "#b_content #b_results",
  666. pager: {
  667. nextLink: "//a[contains(@class,\"sb_pagN\")]",
  668. pageElement: "id(\"b_results\")/li[not(contains(@class,\"b_pag\") or contains(@class,\"b_ans b_top\"))]",
  669. HT_insert: ["id(\"b_results\")/li[@class=\"b_pag\"]", 1], // 1 = beforebegin; 2 = beforeend
  670. replaceE: "id(\"b_results\")//nav[@role=\"navigation\"]",
  671. }
  672. }
  673. }
  674.  
  675. _s_google() {
  676. // 图片站 、地图站、购物站
  677. if (this.useItem.SiteTypeID === 4) {
  678. if(location.href.search(/tbm=(isch|lcl|shop|flm)/) > 0) {
  679. console.mylog("特殊站,不加载样式,不添加menu");
  680. this.gmInstance.curConfig.enableCSS = false
  681. }
  682. }
  683.  
  684. return {
  685. SiteTypeID: 4,
  686. MainType: "#rso .g, div[data-micp-id='rso'] .g",
  687. FaviconType: ".iUh30",
  688. FaviconAddTo: "h3",
  689. CounterType: "#rso .g h3:not(table h3),._yE>div[class~=_kk] h3",
  690. BlockType: ".g h3", // 修复block翻页的问题
  691. MultiPageType: ".srg, #rso, div[two-father], #rso>div:not(.g), #kp-wp-tab-overview",
  692. pager: {
  693. nextLink: "id('pnnext')|id('navbar navcnt nav')//td[span]/following-sibling::td[1]/a|id('nn')/parent::a",
  694. pageElement: "id('rso')|id('center_col')/style[contains(.,'relative')][id('rso')]",
  695. HT_insert: ["css;#res", 2], // 1 = beforebegin; 2 = beforeend
  696. replaceE: '//div[@id="navcnt"] | //div[@id="rcnt"]//div[@role="navigation"]',
  697. }
  698. }
  699. }
  700.  
  701. _s_haosou() {
  702. if (this.useItem.SiteTypeID === 3) {}
  703. return {
  704. SiteTypeID: 3,
  705. MainType: ".res-list",
  706. Stype_Normal: "h3>a",
  707. FaviconType: "cite",
  708. FaviconAddTo: "h3",
  709. CounterType: ".results>div",
  710. BlockType: "h3 a",
  711. // TODO 增加这个
  712. MultiPageType: "????????", // 多列模式下,待选择的元素,未来再说
  713. pager: {
  714. nextLink: "//div[@id='page']//a[text()='下一页>'] | id('snext')",
  715. pageElement: "//div[@id='container']/div",
  716. HT_insert: ["//div[@id='container']", 2], // 1 = beforebegin; 2 = beforeend
  717. replaceE: "id('page')"
  718. }
  719. }
  720. }
  721.  
  722. _s_duckduckgo() {
  723. if (this.useItem.SiteTypeID === 10){}
  724. return {
  725. SiteTypeID: 10,
  726. MainType: "#react-layout li",
  727. FaviconType: ".nrn-react-div .result__url__domain",
  728. FaviconAddTo: "h2",
  729. CounterType: "#react-layout li h2 a",
  730. BlockType: "h2 a",
  731. MultiPageType: "#react-layout .react-results--main",
  732. pager: {
  733. nextLink: "//a[contains(@class,\"sb_pagN\")]",
  734. pageElement: "id(\"b_results\")/li[not(contains(@class,\"b_pag\") or contains(@class,\"b_ans b_top\"))]",
  735. HT_insert: ["id(\"b_results\")/li[@class=\"b_pag\"]", 1], // 1 = beforebegin; 2 = beforeend
  736. replaceE: "id(\"b_results\")//nav[@role=\"navigation\"]",
  737. }
  738. }
  739. }
  740.  
  741. _s_baidu_xueshu() {
  742. if (this.useItem.SiteTypeID === 8) {
  743. console.warn('启动百度学术特殊设置')
  744. this.gmInstance.curConfig.adsStyleMode = 2
  745. }
  746.  
  747. return {
  748. SiteTypeID: 8,
  749. MainType: "#content_left .result",
  750. Stype_Normal: "h3.t>a, #results .c-container>.c-blocka",
  751. FaviconType: ".result-op, .c-showurl", // baidu 似乎要改版了?
  752. FaviconAddTo: "h3",
  753. 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]",
  754. BlockType: "h3 a",
  755. }
  756. }
  757.  
  758. _s_google_scholar() {
  759. if (this.useItem.SiteTypeID === 4.1) {}
  760.  
  761. return {
  762. SiteTypeID: 4.1,
  763. MainType: "#rso .g, div[data-micp-id='rso'] .g",
  764. FaviconType: ".iUh30",
  765. FaviconAddTo: "h3",
  766. CounterType: "#rso .g h3:not(table h3),._yE>div[class~=_kk] h3",
  767. BlockType: "a:not([href*='translate.google.com'])", // 修复block翻页的问题
  768. pager: {
  769. nextLink: '//a[./span[@class="gs_ico gs_ico_nav_next"]]',
  770. pageElement: '//div[@class="gs_r gs_or gs_scl"]',
  771. HT_insert: null, // 1 = beforebegin; 2 = beforeend
  772. replaceE: '//div[@id="navcnt"] | //div[@id="rcnt"]//div[@role="navigation"]',
  773. }
  774. }
  775. }
  776. }
  777. class BaseConfig {
  778. constructor(isEngine = true) {
  779. this.commonStyleEnable = true // 是否开启默认效果优化
  780. this.commonStyleLink = ''
  781. this.commonStyleLess = ''
  782.  
  783. // 搜索引擎的逻辑
  784. if(isEngine) {
  785. this.adsStyleEnable = true // 是否开启默认效果优化
  786. this.adsStyleMode = '3' // 0-不带css;1-单列靠左;2-单列居中;3-双列居中
  787. this.HuYanMode = false // 护眼模式
  788. this.HuYanMode_Color = '#ffffff' // 护眼模式-颜色
  789.  
  790. this.BgEnable = false // 背景图-是否启用
  791. this.BgUseUrl = '' // 默认背景图
  792. this.BgFit = true // 背景图-是否适应
  793. this.BgBase64Image = '' // 这个KEY暂时不使用
  794.  
  795. this.customStyleEnable = false
  796. this.customStyleLink = ''
  797. this.customStyleLess = ''
  798. }
  799. }
  800. }
  801. class CSSAutoInsert {
  802. constructor() {
  803. this.hasChanged = false
  804. this.cssInsertSet = {}
  805.  
  806. MyApi.setIntervalRun(()=> {
  807. if(this.hasChanged) {
  808. this.hasChanged = false
  809. this.doInsert()
  810. }
  811. }, 50)
  812. }
  813.  
  814. add(uniqueName, cssText) {
  815. uniqueName = 'AC-' + uniqueName // 加上特殊前缀,标志关键词
  816. // 如果有,并且数据还一模一样,那么跳过
  817. if (this.cssInsertSet[uniqueName] && this.cssInsertSet[uniqueName] === cssText) {
  818. return
  819. }
  820. console.mylog('--->插入样式表:' + uniqueName)
  821. this.cssInsertSet[uniqueName] = `\n/************${uniqueName}*********/\n` + cssText
  822. this.hasChanged = true
  823. }
  824.  
  825. clear() {
  826. this.cssInsertSet = {}
  827. this.hasChanged = true
  828. }
  829.  
  830. doInsert() {
  831. const cssText = Object.values(this.cssInsertSet).join('\n')
  832. MyApi.addStyle(cssText, Object.keys(this.cssInsertSet).join(' ')) // 方便排查css插入
  833. console.mylog('插入CSS完成')
  834. }
  835. }
  836. class ACGM {
  837. constructor() {
  838. this.initGM()
  839. this.bindGM()
  840. }
  841.  
  842. async initACGM() {
  843. let ACConfig = {}
  844. this.blockRuleList = []
  845. const DefaultConfig = {
  846. common: {
  847. version: '', // 从代码中动态拉取,丢弃任何值
  848. isDevMode: false, // 是否为调试模式,从页面给出来的
  849. isLocalDevMode: false, // 是否为本地调试模式,从页面给出来的,用于加载本地CSS
  850. localDebugBaseUrl: '', // 本地调试模式,本地CSS的入口地址
  851. isRedirectEnable: false, // 是否开启重定向功能
  852. isAdsEnable: false, // 是否开启去广告模式
  853. isFaviconEnable: true, // 是否开启Favicon图标
  854. isAutopage: true, // 是否开启自动翻页功能
  855.  
  856. isBlockEnable: true, // 是否开启去拦截模式
  857. isBlockResultDisplay: true, // 是否删除已拦截的条目
  858. isBlockBtnDisplay: false, // 是否显示block按钮
  859.  
  860. isRightDisplayEnable: true, // 是否开启右侧边栏
  861. isCounterEnable: false, // 是否显示计数器
  862. isALineDisable: false, // 是否禁止下划线
  863. isDarkModeEnable: false, // 是否加载暗黑模式
  864.  
  865. ...new BaseConfig(false)
  866. },
  867. baidu: {
  868. doRemoveSug: true, // 删除移动预测
  869. doRemoveAIGen: false, // 移除百度AI搜索结果
  870. baiduLiteEnable: false, // 启用百度Lite样式表
  871. ...new BaseConfig()
  872. },
  873. google: {
  874. useBaiduLogo: false, // 默认不使用百度logo
  875. ...new BaseConfig()
  876. },
  877. bing: {
  878. optimizeBing: true,
  879. ...new BaseConfig()
  880. },
  881. duckduckgo: {
  882. optimizeDuckDuckGo: true, // 是否开启优化
  883. ...new BaseConfig()
  884. }
  885. };
  886. try {
  887. let res = await GM.getValue("ACConfig", "{}")
  888. ACConfig = JSON.parse(res);
  889.  
  890. res = await GM.getValue("ACBlockRules", "[]")
  891. this.blockRuleList = JSON.parse(res);
  892. this.acpush_acremoveInit()
  893. } catch (e) {
  894. console.error('出bug了')
  895. ACConfig = DefaultConfig
  896. }
  897. // 随便给一个值初始化,这个值,只是临时的值,如果需要写入,也是从另一端拉取,不是这个值来覆盖的
  898. this.curConfig = {
  899. ...DefaultConfig.common,
  900. ...DefaultConfig.baidu
  901. }
  902. this.sortIndex = 1
  903. this.bingScrollPos = 0
  904. this.ACConfig = Object.assign({}, DefaultConfig, ACConfig) // 作为临时修改用
  905. // this.enableCSS = true
  906. this.cssAutoInsert = new CSSAutoInsert()
  907. this.cssFavionList = reactive({
  908. list: []
  909. })
  910.  
  911. this.adsCSSList = {
  912. baiduLiteStyle: '',
  913.  
  914. leftCommonStyle: '',
  915. onePageStyle: '',
  916. twoPageStyle: '',
  917. multiPageStyle: '',
  918. expandPageStyle: '',
  919.  
  920. customStyle: '', // 自定义样式表
  921. commonStyle: '', // 全局样式表
  922.  
  923. huyanStyle: '',
  924. bgAutoFitStyle: '',
  925. darkModeStyle: '', // 暗黑护眼色
  926. faviconStyle: '', // 动态插入的favicon的数据
  927. }
  928.  
  929. this.lock = {
  930. bodyLocked: true,
  931. headLocked: true,
  932. pageLoadingLocked: false,
  933. isBlockChecking: false,
  934. afterBlockChangeChecked: true, // 数据刷新后,是否检查过了,用于减少reg判定
  935. }
  936. // 数据先初始化
  937. this.curConfig = reactive({
  938. enableCSS: true,
  939. ...this.ACConfig.common,
  940. ...this.ACConfig[this._getSiteName()]
  941. })
  942. // 再得到真实options,并调整config
  943. this.options = new SiteOptions(this)
  944. await this.loadSiteCSS()
  945. this.waitBodyHead()
  946. this.openSeetingsUrl = ''
  947. this.check90daoConn()
  948. }
  949.  
  950. initGM() {
  951. if (typeof (GM) === "undefined") {
  952. // 这个是ViolentMonkey的支持选项
  953. GM = {};
  954. GM.setValue = GM_setValue;
  955. GM.getValue = GM_getValue;
  956. }
  957. if (typeof GM_getResourceText === 'undefined') {
  958. GM_getResourceText = async function(aResourceName) {
  959. // 如果没有这个接口,那就是没办法缓存这个数据,所以只能用本地的数据进行缓存了
  960. let res = await (await fetch(await GM.getResourceUrl(aResourceName))).text();
  961. let saveRes = await GM.getValue(aResourceName);
  962. if (typeof (saveRes) === 'undefined') {
  963. GM.setValue(aResourceName, res);
  964. } else {
  965. return saveRes;
  966. }
  967. return res;
  968. }
  969. }
  970. }
  971.  
  972. bindGM() {
  973. GM_registerMenuCommand('AC-重定向脚本设置', function() {
  974. window.open(CONST.openSeetingsUrl)
  975. });
  976. GM_registerMenuCommand('脚本重置 - 修复脚本', function() {
  977. GM.setValue('ACConfig', '{}');
  978. location.reload();
  979. });
  980. }
  981.  
  982. check90daoConn() {
  983. const storeValue = sessionStorage.getItem('access_90dao')
  984. this.openSeetingsUrl = storeValue || 'https://ac-baidu.tujidu.com/pages/custom/#' + CONST.options.siteName
  985. if (!storeValue) {
  986. console.log('目前不存在')
  987. GM_xmlhttpRequest({
  988. method: "HEAD",
  989. timeout: 3000,
  990. url: "https://ac-baidu.90dao.com/",
  991. onload: ()=> {
  992. this.openSeetingsUrl = 'https://ac-baidu.90dao.com/pages/custom/#' + CONST.options.siteName
  993. sessionStorage.setItem('access_90dao', this.openSeetingsUrl)
  994. },
  995. onerror: ()=> {
  996. this.openSeetingsUrl = 'https://ibaidu.tujidu.com/pages/custom/#' + CONST.options.siteName
  997. sessionStorage.setItem('access_90dao', this.openSeetingsUrl)
  998. }
  999. });
  1000. }
  1001. }
  1002. saveConfig() {
  1003. const commonConfig = this.ACConfig['common']
  1004. const siteConfig = this.ACConfig[this.options.siteName]
  1005. for(const key in siteConfig) {
  1006. siteConfig[key] = this.curConfig[key]
  1007. }
  1008. for(const key in commonConfig) {
  1009. commonConfig[key] = this.curConfig[key]
  1010. }
  1011. GM.setValue('ACConfig', JSON.stringify(this.ACConfig));
  1012. }
  1013.  
  1014. saveBlockRule() {
  1015. GM.setValue('ACBlockRules', JSON.stringify(this.blockRuleList));
  1016. }
  1017.  
  1018. renewConfig(newConfig) {
  1019. const chooseCfg = newConfig[this.options.siteName]
  1020. const commonCfg = newConfig['common']
  1021. if(chooseCfg) {
  1022. Object.assign(this.curConfig, chooseCfg)
  1023. }
  1024. if(commonCfg) {
  1025. Object.assign(this.curConfig, commonCfg)
  1026. }
  1027. }
  1028.  
  1029. async loadStyleByName_WithLessCache(styleName) {
  1030. if(CONST.curConfig.isDevMode && CONST.curConfig.isLocalDevMode && CONST.curConfig.localDebugBaseUrl) {
  1031. const renderCSSKeyName = '__AC.RenderCSS__' + styleName
  1032. return await setLocalLessData(renderCSSKeyName, getDebugStyle) // 不带缓存,随时刷新了
  1033. // return await cacheStyle(renderCSSKeyName, getDebugStyle) // 带缓存,随时刷新了
  1034. } else {
  1035. return await cacheStyle(styleName, getRenderStyle)
  1036. }
  1037.  
  1038. async function cacheStyle(styleName, getLessDataFunc) {
  1039. const renderCSSKeyName = '__AC.RenderCSS__' + styleName
  1040. const localData = localStorage.getItem(renderCSSKeyName)
  1041. if (localData) {
  1042. setTimeout(() => {
  1043. console.mylog('*****有缓存了,但是在刷新了:' + styleName)
  1044. setLocalLessData(renderCSSKeyName, getLessDataFunc)
  1045. }, 2000)
  1046. return localData
  1047. } else {
  1048. console.mylog('*****没有缓存' + styleName)
  1049. return await setLocalLessData(renderCSSKeyName, getLessDataFunc)
  1050. }
  1051. }
  1052.  
  1053. async function setLocalLessData(renderCSSKeyName, getLessDataFunc) {
  1054. const { css = '' } = await less.render(await getLessDataFunc());
  1055. localStorage.setItem(renderCSSKeyName, css)
  1056. return css
  1057. }
  1058.  
  1059. async function getDebugStyle() {
  1060. const dataUrl = `${CONST.curConfig.localDebugBaseUrl}${styleName}.less`
  1061. const [err, text] = await MyApi.http.get(dataUrl)
  1062. if(!err) {
  1063. return text
  1064. } else {
  1065. console.error('加载失败', dataUrl)
  1066. }
  1067. return ''
  1068. }
  1069.  
  1070. async function getRenderStyle() {
  1071. return GM_getResourceText(styleName)
  1072. }
  1073. }
  1074.  
  1075. async loadSiteCSS() {
  1076. console.mylog('CSS加载开始' + +this.curConfig.adsStyleMode)
  1077. // 加载多列
  1078. if (this.curConfig.adsStyleEnable) {
  1079. if (+this.curConfig.adsStyleMode >= 4) {
  1080. this.adsCSSList.multiPageStyle = await this.getMultiPageStyle() // 多列效果
  1081. }
  1082. if (+this.curConfig.adsStyleMode >= 3) {
  1083. this.adsCSSList.twoPageStyle = await this.loadStyleByName_WithLessCache(this.options.siteName + 'TwoPageStyle') // 双列效果
  1084. }
  1085. if (+this.curConfig.adsStyleMode >= 2) {
  1086. this.adsCSSList.onePageStyle = await this.loadStyleByName_WithLessCache(this.options.siteName + 'OnePageStyle') // 单列居中
  1087. }
  1088. if (+this.curConfig.adsStyleMode >= 1) {
  1089. this.adsCSSList.leftCommonStyle = await this.loadStyleByName_WithLessCache(this.options.siteName + 'CommonStyle') // 单列效果
  1090. }
  1091. }
  1092. // 加载百度Lite
  1093. if (this.curConfig.baiduLiteEnable) {
  1094. this.adsCSSList.baiduLiteStyle = await this.loadStyleByName_WithLessCache('baiduLiteStyle')
  1095. }
  1096. // 加载背景图优化
  1097. if (this.curConfig.BgEnable && this.curConfig.BgFit) {
  1098. this.adsCSSList.bgAutoFitStyle = await this.loadStyleByName_WithLessCache('BgAutoFit')
  1099. }
  1100. // 加载护眼样式
  1101. if (this.curConfig.HuYanMode) {
  1102. this.adsCSSList.huyanStyle = await this.getHuyanStyle()
  1103. }
  1104. if (this.curConfig.isDarkModeEnable) {
  1105. this.adsCSSList.darkModeStyle = await this.loadStyleByName_WithLessCache('HuaHua-ACDrakMode')
  1106. }
  1107. // 加载自定义样式
  1108. if (this.curConfig.customStyleEnable) {
  1109. console.mylog('触发custom更新')
  1110. const { css = '' } = await less.render(this.curConfig.customStyleLess);
  1111. this.adsCSSList.customStyle = css
  1112. }
  1113. // 加载其他样式
  1114. if (this.curConfig.commonStyleEnable) {
  1115. console.mylog('触发common更新')
  1116. const { css = '' } = await less.render(this.curConfig.commonStyleLess);
  1117. this.adsCSSList.commonStyle = css
  1118. }
  1119. console.mylog('CSS加载结束')
  1120. // 2秒后再加载
  1121. setTimeout(() => {
  1122. this.loadAllStyle()
  1123. }, 2000)
  1124. }
  1125.  
  1126. getMultiPageStyle() {
  1127. return this.options.useItem.MultiPageType +
  1128. (+this.curConfig.adsStyleMode === 4 ?
  1129. "{grid-template-columns: repeat(3, 33.3%); grid-template-areas:'xmain xmain xmain';}" :
  1130. "{grid-template-columns: repeat(4, 25%); grid-template-areas:'xmain xmain xmain xmain';}")
  1131. }
  1132.  
  1133. async getHuyanStyle() {
  1134. function Lighter(oriRGB, deltaY) {
  1135. function clip255(value) {
  1136. if (value > 255) return 255;
  1137. if (value < 0) return 0;
  1138. return value;
  1139. }
  1140. // 按比例缩放 + 1/deltaY
  1141. // HEX 2 RGB
  1142. let rgb = oriRGB.replace("#", "");
  1143. let R = parseInt("0x" + rgb.substr(0, 2));
  1144. let G = parseInt("0x" + rgb.substr(2, 2));
  1145. let B = parseInt("0x" + rgb.substr(4, 2));
  1146. // RGB 2 YUV
  1147. let Y = ((66 * R + 129 * G + 25 * B + 128) >> 8) + 16;
  1148. let U = ((-38 * R - 74 * G + 112 * B + 128) >> 8) + 128;
  1149. let V = ((112 * R - 94 * G - 18 * B + 128) >> 8) + 128;
  1150. Y = Y * (1 + 1.0 / deltaY);// 提高亮度
  1151. // YUV 2 RGB
  1152. R = clip255((298 * (Y - 16) + 409 * (V - 128) + 128) >> 8);
  1153. G = clip255((298 * (Y - 16) - 100 * (U - 128) - 208 * (V - 128) + 128) >> 8);
  1154. B = clip255((298 * (Y - 16) + 516 * (U - 128) + 128) >> 8);
  1155. return "#" + ((R << 16) + (G << 8) + B).toString(16);
  1156. }
  1157.  
  1158. let HuyanStyle = await this.loadStyleByName_WithLessCache('HuYanStyle')
  1159. const huyanColor = this.curConfig.HuYanMode_Color
  1160.  
  1161. return HuyanStyle
  1162. .replace(/#aaa(a*)/igm, huyanColor)
  1163. .replace(/#bbb(b*)/igm, Lighter(huyanColor, -40))
  1164. .replace(/#ccc(c*)/igm, Lighter(huyanColor, 45));
  1165. }
  1166.  
  1167. async loadAllStyle() {
  1168. if (!this.adsCSSList.leftCommonStyle) this.adsCSSList.leftCommonStyle = await this.loadStyleByName_WithLessCache(this.options.siteName + 'CommonStyle') // 单列效果
  1169. if (!this.adsCSSList.onePageStyle) this.adsCSSList.onePageStyle = await this.loadStyleByName_WithLessCache(this.options.siteName + 'OnePageStyle') // 单列居中
  1170. if (!this.adsCSSList.twoPageStyle) this.adsCSSList.twoPageStyle = await this.loadStyleByName_WithLessCache(this.options.siteName + 'TwoPageStyle') // 双列效果
  1171. if (!this.adsCSSList.baiduLiteStyle) this.adsCSSList.baiduLiteStyle = await this.loadStyleByName_WithLessCache('baiduLiteStyle')
  1172. if (!this.adsCSSList.bgAutoFitStyle) this.adsCSSList.bgAutoFitStyle = await this.loadStyleByName_WithLessCache('BgAutoFit')
  1173. if (!this.adsCSSList.darkModeStyle) this.adsCSSList.darkModeStyle = await this.loadStyleByName_WithLessCache('HuaHua-ACDrakMode')
  1174. }
  1175.  
  1176. waitBodyHead() {
  1177. // 永远执行
  1178. MyApi.safeWaitFunc(() => {return document.head}, () => {
  1179. console.mylog('解锁head')
  1180. this.lock.headLocked = false
  1181. })
  1182. MyApi.safeWaitFunc(() => {return document.body}, () => {
  1183. console.mylog('解锁body')
  1184. this.lock.bodyLocked = false
  1185. })
  1186. }
  1187.  
  1188. addIntervalTrigger(site = '', waitAt = 'now', callback, interval_time = 0, runTimes = 1) {
  1189. console.mylog('addIntervalTrigger', site, "------------", this.options.siteName)
  1190. if(site !== 'all' && this.options.siteName !== site) return
  1191.  
  1192. let count = runTimes
  1193. const intId = MyApi.setIntervalRun(async () => {
  1194. count--
  1195. if(
  1196. !((waitAt === 'now') ||
  1197. (waitAt === 'body' && !this.lock.bodyLocked) ||
  1198. (waitAt === 'head' && !this.lock.headLocked))
  1199. ) {
  1200. return
  1201. }
  1202. if(count >= 0) {
  1203. await callback(count)
  1204. } else {
  1205. clearInterval(intId)
  1206. }
  1207. }, interval_time)
  1208. }
  1209.  
  1210. acpush_acremoveInit() {
  1211. function acpush(data = "") {
  1212. this.hasEdit = true
  1213. data = data.trim()
  1214. // 如果是垃圾数据,那么可以丢弃的
  1215. if (!data) return '无效内容';
  1216. // 如果数据中有回车,那数据也是无效的正文而已
  1217. if (data.search(/(,|:|。|\n)/) >= 0) return '格式不符合要求';
  1218. if (this.findIndex(m => m === data) < 0) {
  1219. this.push(data);
  1220. dataChangeCallback()
  1221. } else {
  1222. return "已存在相同项"
  1223. }
  1224. }
  1225. function acremove (data) {
  1226. this.hasEdit = true
  1227. let delId = this.findIndex(m => m === data);
  1228. if (delId >= 0) {
  1229. this.splice(delId, 1);
  1230. dataChangeCallback()
  1231. return delId
  1232. }
  1233. return -1
  1234. }
  1235. function dataChangeCallback() {
  1236. CONST.lock.afterBlockChangeChecked = false
  1237. PageBlockFunc._updateRegListRule()
  1238. }
  1239. Object.defineProperty(CONST.blockRuleList, 'acpush', { value: acpush })
  1240. Object.defineProperty(CONST.blockRuleList, 'acremove', { value: acremove })
  1241. }
  1242.  
  1243. _getSiteName() {
  1244. const specialRule = {
  1245. 'xueshu.baidu.com': 'baidu_xueshu',
  1246. 'scholar.google.com': 'google_scholar',
  1247. 'so.com': 'haosou',
  1248. }
  1249. let useRule = Object.keys(specialRule).find(one => location.host.includes(one))
  1250. if(!useRule) {
  1251. useRule = location.host.replace(/.*(baidu|google|bing|duckduckgo).*/, '$1')
  1252. } else {
  1253. return specialRule[useRule]
  1254. }
  1255. return useRule
  1256. }
  1257. }
  1258. const CONST = new ACGM()
  1259. await CONST.initACGM()
  1260.  
  1261. class PageFuncClass {
  1262. constructor() {
  1263. this.removeAds = this.removeAdFunc()
  1264. }
  1265. GoogleInBaiduMode() {
  1266. MyApi.safeGetNodeFunc("#logo img, #logocont img", function(node) {
  1267. let faNode = node.parentNode.parentNode;
  1268. if(faNode.hasAttribute('xchanged')) return
  1269. faNode.classList.add("baidu");
  1270. faNode.setAttribute('xchanged', 1)
  1271. node.removeAttribute("src");
  1272. node.src = "https://www.baidu.com/img/flexible/logo/pc/result.png";
  1273. node.width = "125";
  1274. node.removeAttribute("height");
  1275. });
  1276. MyApi.safeGetNodeFunc("#main .logo img[alt='Google']", function(node) {
  1277. if(node.hasAttribute('xchanged')) return
  1278. node.setAttribute('xchanged', 1)
  1279. node.removeAttribute("srcset");
  1280. node.src = "https://www.baidu.com/img/flexible/logo/pc/result.png";
  1281. node.style.height = '30px'
  1282. node.style.marginTop = '-10px'
  1283. }, 300);
  1284. MyApi.safeGetNodeFunc("form[role='search'] .logo img", function(node) {
  1285. if(node.hasAttribute('xchanged')) return
  1286. node.setAttribute('xchanged', 1)
  1287. node.removeAttribute("srcset");
  1288. node.src = "https://www.baidu.com/img/flexible/logo/pc/result.png";
  1289. node.setAttribute("height", "30");
  1290. node.style.marginTop = '-10px'
  1291. }, 300);
  1292. if(!document.title.includes('百度')) {
  1293. document.title = document.title.replace(/^Google/, "百度一下,你就知道")
  1294. .replace(/ - Google 搜索/, "_百度搜索")
  1295. .replace(/ - Google Search/, "_百度搜索");
  1296. }
  1297. MyApi.safeGetNodeFunc("head", function() {
  1298. let linkTarget = document.querySelector("link[type='image/x-icon']") || document.createElement('link');
  1299. if(!linkTarget.href.includes('baidu')) return
  1300. linkTarget.type = 'image/x-icon';
  1301. linkTarget.rel = 'shortcut icon';
  1302. linkTarget.href = 'https://www.baidu.com/favicon.ico';
  1303. document.head.appendChild(linkTarget);
  1304. })
  1305. }
  1306. removeAdFunc() {
  1307. function removeBaiduAd() {
  1308. // 移除右侧栏广告
  1309. MyApi.safeRemove_xpath("id('content_right')/div[.//a[starts-with(text(), '广告')]]");
  1310. // 移除标准广告
  1311. MyApi.safeRemove_xpath("id('content_left')/div[.//span[contains(@class, 'tuiguang') or contains(@class, 'brand')][contains(text(), '广告')]]");
  1312. // 移除标准广告 - 新
  1313. MyApi.safeRemove_xpath("id('content_left')/div[.//a[text()='广告']]");
  1314. // 移除右侧栏顶部-底部无用广告
  1315. MyApi.safeRemove_xpath("id('content_right')/br");
  1316. MyApi.safeRemove_xpath("id('content_right')/div[not(@id)]");
  1317. // 移除顶部可能出现的 "为您推荐"
  1318. MyApi.safeRemove_xpath("id('content_left')//div[contains(@class, '_rs')]");
  1319.  
  1320. /****移除Mobile模式上的部分广告****/
  1321. MyApi.safeRemove_xpath("id('page-bd')/div[not(contains(@class, 'result'))]");
  1322. MyApi.safeRemove_xpath("id('page-bd')/div[not(@class)]");
  1323. MyApi.safeRemove_xpath("//div[@class='na-like-container']");
  1324. }
  1325. function removeGoogleAd() {
  1326. MyApi.safeRemoveAd("#bottomads");
  1327. MyApi.safeRemoveAd('div[aria-label="广告"]');
  1328. MyApi.safeRemoveAd('div[aria-label="Ads"]');
  1329. }
  1330. function removeBingAd() {
  1331. MyApi.safeRemoveAd(".b_ad");
  1332. MyApi.safeRemove_xpath("id('b_results')/li[./div[@class='ad_fls']]");
  1333.  
  1334. // 移除特殊tag,带url标记的广告类
  1335. const resList = [...document.querySelectorAll("ol>li")].filter(one => one.querySelector('p')) // 定位到所有包含p标签的li
  1336. const adList = resList.filter(one => window.getComputedStyle(one.querySelector('p'), '::before').getPropertyValue('content').includes('url')) // 检查每一个p标签,里面存在before伪元素,且伪元素中是链接的,均为广告
  1337. adList.forEach(one => one.remove())
  1338. }
  1339. function removeHaosouAd() {
  1340. MyApi.safeRemoveAd("#so_kw-ad");
  1341. MyApi.safeRemoveAd("#m-spread-left");
  1342. // 移除搜索中底部广告
  1343. MyApi.safeRemoveAd("#m-spread-bottom");
  1344. // 移除右侧栏顶部广告
  1345. MyApi.safeRemove_xpath("id('righttop_box')//li[.//span[contains(text(), '广告')]]");
  1346. }
  1347.  
  1348. return {
  1349. removeBaiduAd,
  1350. removeGoogleAd,
  1351. removeBingAd,
  1352. removeHaosouAd
  1353. }
  1354. }
  1355. InsertSettingMenu() {
  1356. if (document.querySelector("#myuser") === null) {
  1357. MyApi.safeWaitFunc("#u, #gb, #b_header>#id_h, #header_wrapper .js-hl-butto", parent => {
  1358. parent.style = "width: auto;";
  1359. let userAdiv = document.createElement("div");
  1360. userAdiv.id = "myuser";
  1361. userAdiv.innerHTML = `<input type='submit' class='myuserconfig' value='自定义'/><span class='ac-newversionDisplay' style='background-color: red;float: left;height: 8px;width: 8px;border-radius: 4px;display: none'>&nbsp;</span>`;
  1362.  
  1363. parent.insertBefore(userAdiv, parent.childNodes[0]);
  1364. document.querySelector("#myuser .myuserconfig").addEventListener("click", function(e) {
  1365. window.open(CONST.openSeetingsUrl)
  1366. }, true);
  1367. }, 300)
  1368. }
  1369. }
  1370. RedirectHandle() {
  1371. // 处理主重定向
  1372. if (CONST.options.useItem.SiteTypeID < 0) return;
  1373. if (CONST.curConfig.isRedirectEnable) {
  1374. if (CONST.options.useItem.Stype_Normal) { // 如果定义了,那么就去处理重定向
  1375. resetURLNormal();
  1376. }
  1377. if (CONST.options.useItem.SiteTypeID === CONST.options.google.SiteTypeID) removeOnMouseDownFunc(); // 移除onMouseDown事件,谷歌去重定向
  1378. if (location.host.includes('m.baidu.com')) removeMobileBaiduDirectLink(); // 处理百度手机版本的重定向地址
  1379. remove_xueshuBaidu(); // 百度学术重定向问题
  1380. MyApi.safeRemoveAd(".res_top_banner"); // 移除百度可能显示的劫持
  1381. }
  1382.  
  1383. function removeMobileBaiduDirectLink() {
  1384. let nodes = document.querySelectorAll("#page #page-bd #results .result:not([ac_redirectStatus])");
  1385. for (let i = 0; i < nodes.length; i++) {
  1386. let curNode = nodes[i];
  1387. MyApi.safeFunc(function() {
  1388. let curData = JSON.parse(curNode.dataset.log.replace(/'/gm, "\""));
  1389. let trueLink = curData.mu;
  1390. curNode.querySelector("article").setAttribute("rl-link-href", trueLink);
  1391. curNode.querySelectorAll("a").forEach(function(per) {
  1392. per.setAttribute("href", trueLink);
  1393. });
  1394. });
  1395. curNode.setAttribute("ac_redirectStatus", "1");
  1396. }
  1397. }
  1398.  
  1399. function removeOnMouseDownFunc() {
  1400. MyApi.safeFunc(() => {
  1401. let resultNodes = document.querySelectorAll(".g .rc a, #rs, #rso .g a");
  1402. for (let i = 0; i < resultNodes.length; i++) {
  1403. let one = resultNodes[i];
  1404. one.setAttribute("onmousedown", ""); // 谷歌去重定向干扰
  1405. one.setAttribute("target", "_blank"); // 谷歌链接新标签打开
  1406. one.setAttribute("data-jsarwt", "0"); // Firefox谷歌去重定向干扰
  1407. }
  1408. })
  1409. }
  1410.  
  1411. function remove_xueshuBaidu() {
  1412. if (CONST.options.useItem.SiteTypeID === CONST.options.baidu_xueshu.SiteTypeID) {
  1413. let xnodes = document.querySelectorAll("a[href*='sc_vurl=http']");
  1414. for (let j = 0; j < xnodes.length; j++) {
  1415. let xurl = MyApi.getUrlAttribute(xnodes[j].href, "sc_vurl", true);
  1416. xnodes[j].href = xurl;
  1417. }
  1418. }
  1419. }
  1420.  
  1421. function DealRedirect (request, curNodeHref, respText, RegText, hrefType) {
  1422. if (respText === null || typeof (respText) === "undefined") return;
  1423. let resultResponseUrl = "";
  1424. if (RegText != null) {
  1425. resultResponseUrl = MyApi.Reg_Get(respText, RegText);
  1426. } else {
  1427. resultResponseUrl = respText;
  1428. }
  1429. if (resultResponseUrl !== null && resultResponseUrl !== "" && !resultResponseUrl.includes("www.baidu.com/link")) {
  1430. try {
  1431. let host = PageFunc.getTextHost(resultResponseUrl);
  1432.  
  1433. document.querySelectorAll("*[href*='" + curNodeHref + "']").forEach(per => {
  1434. let changeNode = per;
  1435.  
  1436. changeNode.setAttribute("ac_redirectStatus", "2");
  1437. changeNode.href = resultResponseUrl;
  1438. // changeNode.setAttribute("data-orihref", changeNode.href);
  1439. if (changeNode.hasAttribute("meta")) {
  1440. changeNode.setAttribute("meta", host);
  1441. changeNode.dataset.host = host;
  1442. }
  1443.  
  1444. if (hrefType === null || hrefType === undefined || hrefType === "title") {
  1445. if (changeNode.text && changeNode.text.length < 10 && !changeNode.text.includes(host)
  1446. // 不能是redirect url 不能是h2\h3下直属链接
  1447. && !changeNode.parentElement.tagName.toLowerCase().includes("h")) {
  1448. changeNode.insertAdjacentHTML("beforeEnd", "&nbsp;-&nbsp;" + host);
  1449. }
  1450. }
  1451. })
  1452. request && request.abort();
  1453. } catch (e) {
  1454. }
  1455. }
  1456. }
  1457. function resetURLNormal() {
  1458. const mainList = document.querySelectorAll(CONST.options.useItem.MainType)
  1459.  
  1460. // 注意有重复的地址,尽量对重复地址进行去重
  1461. var hasDealHrefSet = new Set();
  1462. for (let i = 0; i < mainList.length; i++) {
  1463. // 此方法是异步,故在结束的时候使用i会出问题-严重!
  1464. // 采用闭包的方法来进行数据的传递
  1465. const curNode = mainList[i];
  1466.  
  1467. if (curNode !== null && curNode.getAttribute("ac_redirectStatus") === null) {
  1468. curNode.setAttribute("ac_redirectStatus", "0");
  1469.  
  1470. const linkNode = curNode.querySelector(CONST.options.useItem.Stype_Normal);
  1471. if(linkNode === null) {
  1472. continue
  1473. }
  1474.  
  1475. // 跳过特殊链接的处理
  1476. if(linkNode.href && (linkNode.href.startsWith('javascript') || linkNode.href.startsWith('#'))) {
  1477. continue
  1478. }
  1479.  
  1480. let linkHref = linkNode.href;
  1481. let len1 = hasDealHrefSet.size;
  1482. hasDealHrefSet.add(linkHref);
  1483. let len2 = hasDealHrefSet.size;
  1484. if (len1 === len2) continue; // 说明数据已经处理过,存在相同的记录
  1485. const isLinkNeedDeal = () => {
  1486. // 如果当前节点存在mu参数,或者link节点存在data-mdurl,那么就算直接成功,不用重新请求一遍了
  1487. let trueLink = curNode.getAttribute('mu') || linkNode.getAttribute('data-mdurl')
  1488. if(trueLink && !trueLink.includes('nourl')) {
  1489. trueLink = getBaiduEncodingHandle(trueLink)
  1490. DealRedirect(null, linkHref, trueLink);
  1491. return true
  1492. }
  1493. }
  1494. const getBaiduEncodingHandle = (linkUrl) => {
  1495. let resLink = linkUrl
  1496. if(CONST.options.useItem.SiteTypeID === CONST.options.baidu.SiteTypeID && linkUrl.includes('baidu.com')) {
  1497. const [, first = ''] = /(ie=[^&]+)/.exec(location.search) || []
  1498. resLink = linkUrl.replace(/(ie=[^&]+)/, first)
  1499. }
  1500. return resLink
  1501. }
  1502. if(!isLinkNeedDeal()) {
  1503. continue
  1504. }
  1505. // 走接口重定向处理
  1506. if (linkHref.includes("www.baidu.com/link") ||
  1507. linkHref.includes("m.baidu.com/from") ||
  1508. linkHref.includes("www.sogou.com/link") ||
  1509. linkHref.includes("so.com/link") ||
  1510. linkHref.search("bing.com/(ck|a|aclick)") > 0 ||
  1511. linkHref.search("e.so.com/(search|eclk)") > 0
  1512. ) {
  1513. (async function(c_curnode, c_curhref) {
  1514. let url = c_curhref.replace(/^http:/, "https:");
  1515. if (CONST.options.useItem.SiteTypeID === CONST.options.baidu.SiteTypeID && !url.includes("eqid")) {
  1516. // 如果是百度,并且没有带有解析参数,那么手动带上
  1517. url = url + "&wd=&eqid=";
  1518. }
  1519.  
  1520. let gmRequestNode = GM_xmlhttpRequest({
  1521. url: url,
  1522. headers: { "Accept": "*/*", "Referer": c_curhref.replace(/^http:/, "https:") },
  1523. method: "GET",
  1524. timeout: 8000,
  1525. onload: function(response) { // MARK 有时候这个函数根本不进来 - 调试的问题 - timeout
  1526. if (response.responseText || response.responseHeaders) {
  1527. // 由于是特殊返回-并且好搜-搜狗-百度都是这个格式,故提出
  1528. DealRedirect(gmRequestNode, c_curhref, response.responseText, "URL='([^']+)'")
  1529. // 这个是在上面无法处理的情况下,备用的 tm-finalurldhdg tm-finalurlmfdh
  1530.  
  1531. if (response.responseHeaders.includes("tm-finalurl")) {
  1532. let relURL = Reg_Get(response.responseHeaders, "tm-finalurl\\w+: ([^\\s]+)");
  1533. if (relURL === null || relURL === "" || relURL.includes("www.baidu.com/search/error")) return;
  1534. DealRedirect(gmRequestNode, c_curhref, relURL);
  1535. }
  1536. }
  1537. }
  1538. });
  1539. })(curNode, linkHref); //传递旧的网址过去,读作c_curhref
  1540. }
  1541. }
  1542. }
  1543. if (hasDealHrefSet.size > 0 && mainList.length - hasDealHrefSet.size > 0) console.mylog("丢弃掉", mainList.length - hasDealHrefSet.size, "个重复链接");
  1544. }
  1545. }
  1546. getTextHost(sbefore) {
  1547. sbefore = (sbefore && sbefore.trim()).replace(/\s-\s\d{4}-\d{1,2}-\d{1,2}/, "") || "";
  1548. let send;
  1549. let result = sbefore.split('-');
  1550. // --搜狗百度专用;如果第一个是中文的话,地址就是第二个
  1551. if ((result.length > 1 && new RegExp("[\\u4E00-\\u9FFF]+", "g").test(sbefore)) && CONST.options.useItem.SiteTypeID === CONST.options.baidu.SiteTypeID) {
  1552. sbefore = result[1];
  1553. } else {
  1554. result = sbefore.split('\n');
  1555. if (result.length > 1 && CONST.options.useItem.SiteTypeID === CONST.options.google.SiteTypeID) {
  1556. sbefore = result[1];
  1557. }
  1558. }
  1559. // 此时sbefore几乎是等于网址了,但是有时候会有多的空格,多的内容,多的前缀http,多余的路径
  1560. let res = new RegExp(/(https?:\/\/)?([^/\s]+)/i).exec(sbefore);
  1561. send = (res && res[2].trim()) || "";
  1562. // send = sbefore.replace(/(\/[^/]*|\s*)/, "").replace(/<[^>]*>/g, "").replace(/https?:\/\//g, "").replace(/<\/?strong>/g, "").replace(/<\/?b>/g, "").replace(/<?>?/g, "").replace(/( |\/).*/g, "").replace(/\.\..*/, "");
  1563. if (send === "") return null;
  1564. if (send.indexOf(".") < 0) return null;
  1565. if (send.indexOf("↵") >= 0) return null;
  1566. return send.trim();
  1567. }
  1568. getNodeHost(sitetpNode) {
  1569. if (!sitetpNode) return {}
  1570. if (CONST.options.useItem.SiteTypeID === CONST.options.baidu.SiteTypeID) {
  1571. const href = sitetpNode.getAttribute("href");
  1572. if (href != null && !href.includes("baidu.com/link")) {
  1573. // 已经解析出来了
  1574. return { curHost: this.getTextHost(href), curUrl: href };
  1575. } else {
  1576. const host = this.getTextHost(sitetpNode.innerText || sitetpNode.textContent)
  1577. return { curHost: host, curUrl: host, isBaiduLink: true }; // 未被解密
  1578. }
  1579. } else if (sitetpNode instanceof HTMLAnchorElement) {
  1580. return { curHost: sitetpNode.host, curUrl: sitetpNode.href };
  1581. } else {
  1582. const host = this.getTextHost(sitetpNode.innerText || sitetpNode.textContent)
  1583. return { curHost: host, curUrl: host };
  1584. }
  1585. }
  1586. addFavicon(citeList) {
  1587. const insertList = []
  1588. if (CONST.options.useItem.SiteTypeID !== null) {
  1589. for (let index = 0; index < citeList.length; index++) {
  1590. if (null === citeList[index].getAttribute("ac_faviconStatus")) {
  1591. let curNode = citeList[index];
  1592. let targetNode = curNode;
  1593. let { curHost, curUrl } = PageFunc.getNodeHost(targetNode);
  1594. if (!curHost) { // 跳过解不出来的地址
  1595. continue;
  1596. } else {
  1597. }
  1598. let faviconUrl = curHost;
  1599. let II = 0;
  1600. for (; II <= 5; II++) {
  1601. targetNode = targetNode.parentNode;
  1602. if (targetNode != null && targetNode.querySelector(CONST.options.useItem.FaviconAddTo) != null) {
  1603. break;
  1604. }
  1605. }
  1606. if (targetNode.parentNode.hasAttribute('tpl') && targetNode.parentNode.getAttribute('tpl').includes('stock')) {
  1607. curNode.setAttribute("ac_faviconStatus", "-3");
  1608. continue
  1609. }
  1610. //console.mylog(index+"."+faviconUrl+"--"+II);
  1611. if (II <= 5) {
  1612. // 先用父节点判断一下是否存在img
  1613. let tmpHTML = targetNode.innerHTML;
  1614. let pos = tmpHTML.indexOf("fav-url")
  1615. & tmpHTML.indexOf("wr_fav")
  1616. & tmpHTML.indexOf("favurl")
  1617. & tmpHTML.indexOf("tit-ico")
  1618. & tmpHTML.indexOf("img_fav rms_img")
  1619. & tmpHTML.indexOf("c-tool-")
  1620. & tmpHTML.indexOf("span class=\"c-icon c-icon-")
  1621. & tmpHTML.indexOf("img class=\"xA33Gc")
  1622. & tmpHTML.indexOf("img class=\"XNo5Ab\""); // 谷歌图标
  1623. //他自己已经做了favicon了
  1624. if (pos > -1) {
  1625. curNode.setAttribute("ac_faviconStatus", "-2");
  1626. continue;
  1627. }
  1628. targetNode = targetNode.querySelector(CONST.options.useItem.FaviconAddTo);
  1629. let host = faviconUrl.replace(/[^.]+\.([^.]+)\.([^.]+)/, "$1.$2");
  1630.  
  1631. if (!targetNode.hasAttribute("data-favicon-t") && host.length >= 3) {
  1632. let faviconUrl = curNode.href || host
  1633. if (CONST.options.useItem.SiteTypeID === CONST.options.baidu.SiteTypeID && faviconUrl.includes("baidu.com/link")) {
  1634. faviconUrl = host
  1635. }
  1636.  
  1637. targetNode.setAttribute('data-favicon-t', faviconUrl)
  1638. insertList.push({
  1639. tagName: targetNode.tagName.toLowerCase(),
  1640. url: faviconUrl
  1641. })
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. insertList.map(one => CONST.cssFavionList.list.push(one))
  1648. }
  1649. addCounter(citeList) {
  1650. const cssText = "font-style:normal;position:relative;z-index:1;margin-right:4px;display:inline-block;color:white;font-family:'微软雅黑';font-size:16px;text-align:center;width:22px;line-height:22px;border-radius:50%;";
  1651. for (let i = 0; i < citeList.length; i++) {
  1652. let cur = citeList[i];
  1653. const index = cur.getAttribute('SortIndex');
  1654. if (index === null || typeof (index) === "undefined") {
  1655. cur.setAttribute('SortIndex', CONST.sortIndex);
  1656. let ele = document.createElement('em');
  1657. ele.className = 'AC-CounterT';
  1658. ele.style = cssText;
  1659. ele.innerText = CONST.sortIndex;
  1660. let child = cur.firstElementChild;
  1661. if (child && child.nodeName === 'DIV') {
  1662. let emNode = child.querySelector('em');
  1663. if (emNode) emNode.parentNode.insertAdjacentElement('afterBegin', ele)
  1664. } else {
  1665. cur.insertAdjacentElement('afterBegin', ele);
  1666. }
  1667. CONST.sortIndex++;
  1668. } else {
  1669. const curCounter = cur.querySelector(".AC-CounterT")
  1670. if (!curCounter) continue
  1671. const oriIndex = curCounter.innerText
  1672. const checkValue = (i + 1) % 100;
  1673. // 数据值不同
  1674. // 数据没有被翻译
  1675. if (+index !== checkValue && !/^\d+$/.test(oriIndex)) { // 按需更新
  1676. curCounter.innerText = checkValue;
  1677. cur.setAttribute('SortIndex', checkValue);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. acSetCookie(cname, cvalue, domain, exdays) {
  1683. MyApi.safeFunc(() => {
  1684. exdays = exdays || 30;
  1685. let d = new Date();
  1686. domain = (domain ? "domain=" + domain : "") + ";";
  1687. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  1688. let expires = "expires=" + d.toUTCString();
  1689. document.cookie = cname + "=" + cvalue + "; " + domain + expires + ";path=/;SameSite=None;Secure";
  1690. })
  1691. }
  1692. dataChangeFireCallback() {
  1693. // 数据有变更,那么尝试重新渲染状态
  1694. CONST.cssAutoInsert.clear()
  1695.  
  1696. if(!CONST.curConfig.enableCSS) {
  1697. MyApi.safeGetNodeFunc('#myuser', node => node.remove())
  1698. return
  1699. }
  1700. console.mylog('即将插入CSS1')
  1701. if (CONST.curConfig.adsStyleEnable) {
  1702. console.mylog('即将插入CSS2')
  1703. if(+CONST.curConfig.adsStyleMode === 1) {
  1704. console.mylog('靠左优化模式')
  1705. CONST.cssAutoInsert.add("expandPageStyle", CONST.adsCSSList.expandPageStyle)
  1706. CONST.cssAutoInsert.add("leftCommonStyle", CONST.adsCSSList.leftCommonStyle)
  1707. } else if (+CONST.curConfig.adsStyleMode === 2) {
  1708. console.mylog('单列居中')
  1709. CONST.cssAutoInsert.add("expandPageStyle", CONST.adsCSSList.expandPageStyle)
  1710. CONST.cssAutoInsert.add("leftCommonStyle", CONST.adsCSSList.leftCommonStyle)
  1711. CONST.cssAutoInsert.add("onePageStyle", CONST.adsCSSList.onePageStyle)
  1712. } else if (+CONST.curConfig.adsStyleMode === 3) {
  1713. console.mylog('双列居中')
  1714. CONST.cssAutoInsert.add("leftCommonStyle", CONST.adsCSSList.leftCommonStyle)
  1715. CONST.cssAutoInsert.add("twoPageStyle", CONST.adsCSSList.twoPageStyle)
  1716. } else if (+CONST.curConfig.adsStyleMode === 4 ||+CONST.curConfig.adsStyleMode === 5) {
  1717. console.mylog('N列居中')
  1718. CONST.cssAutoInsert.add("leftCommonStyle", CONST.adsCSSList.leftCommonStyle)
  1719. CONST.cssAutoInsert.add("twoPageStyle", CONST.adsCSSList.twoPageStyle)
  1720. CONST.cssAutoInsert.add("multiPageStyle", CONST.adsCSSList.multiPageStyle)
  1721. }
  1722. }
  1723.  
  1724. CONST.cssAutoInsert.add("styleLogo", ".minidiv #logo img{width: 100px;height: unset;margin-top: 0.3rem;} body.purecss-mode:before{display: none;}")
  1725. CONST.cssAutoInsert.add("specialBAIDU", ".opr-recommends-merge-imgtext{display:none!important;}.res_top_banner{display:none!important;}.headBlock, body>div.result-op{display:none;}")
  1726. CONST.cssAutoInsert.add("animationStyle", "@keyframes ani_leftToright{0%{transform:translateX(-32px);opacity:0.2;}20%{opacity:0.5;}30%{opacity:0.8;}100%{opacity:1;}}@keyframes ani_bottomTotop{0%{transform:translateY(32px);opacity:0.2;}20%{opacity:0.5;}30%{opacity:0.8;}100%{opacity:1;}}@-webkit-keyframes ani_topTobuttom{0%{transform:translateY(-32px);opacity:0.2;}20%{opacity:0.5;}30%{opacity:0.8;}100%{opacity:1;}}@-webkit-keyframes ani_hideToShow{0%{display:none;opacity:0.2;}20%{opacity:0.5;}30%{opacity:0.8;}100%{opacity:1;}}@-webkit-keyframes ani_showToHide{0%{display:none;opacity:1;}20%{opacity:0.8;}30%{opacity:0.5;}100%{opacity:0.3;}}.aniDelete{transition:all 0.15s cubic-bezier(0.4,0,1,1);opacity:0.1}")
  1727. CONST.cssAutoInsert.add("menuBtn", ".achide{display:none;} .newFuncHighLight{color:red;font-weight: 100;background-color: yellow;font-weight: 600;}#sp-ac-container label{display:inline;}#u{width:319px}#u #myuser{display:inline-block;margin: 13px -10px 0 24px;}.site-wrapper #myuser,.sogou-set-box #myuser,#gbw #myuser{margin-right:15px;} #gb #myuser{margin-top:7px;} #myuser,#myuser .myuserconfig{padding:0;margin:0}#myuser{display:inline-block;}#myuser .myuserconfig{display:inline-block;line-height:1.5;background:#4e6ef2;color:#fff;font-weight:700;text-align:center;padding:6px;border:2px solid #E5E5E5;}#myuser .myuserconfig{box-shadow:0 0 10px 3px rgba(0,0,0,.1);border-radius: 6px}#myuser .myuserconfig:hover{background:#4662d9 !important;color:#fff;cursor:pointer;border:2px solid #73A6F8;}")
  1728.  
  1729. if(CONST.curConfig.baiduLiteEnable) {
  1730. CONST.cssAutoInsert.add("baiduLiteStyle", CONST.adsCSSList.baiduLiteStyle)
  1731. }
  1732. if(CONST.curConfig.HuYanMode) {
  1733. CONST.cssAutoInsert.add("huYanStyle", CONST.adsCSSList.huyanStyle)
  1734. }
  1735. if(CONST.curConfig.adsStyleEnable) {
  1736. CONST.cssAutoInsert.add("adsBlockStyle", "#bottomads{display:none;} #content_left>div:not([id])>div[cmatchid], #content_left>div[id*='300']:not([class*='result']),#content_right td>div:not([id]),#content_right>br{position:absolute;top:-6666px;}")
  1737. }
  1738. if(CONST.curConfig.BgEnable) {
  1739. const imageUrl = CONST.curConfig.BgUseUrl
  1740. if(imageUrl) {
  1741. const bgCSS = `body:before{pointer-events: none;position: fixed;width: 100%;height: 100%;top: 0;left: 0;content: '';background-image: url('${imageUrl}');background-size: 100% auto;opacity: 0.6;}`
  1742. CONST.cssAutoInsert.add("backGroundImage", bgCSS)
  1743. }
  1744. if(CONST.curConfig.BgFit) {
  1745. CONST.cssAutoInsert.add("bgFitStyle", CONST.adsCSSList.bgAutoFitStyle)
  1746. }
  1747. }
  1748. if(CONST.curConfig.isDarkModeEnable) {
  1749. CONST.cssAutoInsert.add("darkModeStyle", CONST.adsCSSList.darkModeStyle)
  1750. }
  1751. if (CONST.curConfig.isAutopage) {
  1752. const sepImgs = {
  1753. top: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAWtJREFUeNrclE0rRGEUx8c1GUpRJIVIZGdhZCVr38GGhaI0ZXwCkliglChZEcvJxhdgYWOjLEUpm/EyiLzze+o8dTzdO3PljoVTv7rPc8/5d+6555xYrEhWop6boda5+6l9wjWcWpF+WIbqCJJ9hFRcDr3QAIkIhKugz5PDfkSixkphz5aiAnqgE8rgWRxGoSOPyBkswQuUwyscw4HrmFCZL8Kt/JAg7mEFPEmo4FdPwk0BUcsdzIap0TQ8qMAPuICcEjLnd+VjSjcfJNgIc/DkZGSymYGsnK9EZMrxe4MFaNGiZjC2fT5zQ3p7QDK1dR2GSljziclAvRUe8nHYVA4jjvC43NfAuk/smB2QNqcsWxKcLbAKTFnS0hWD6n27Fd6FLqiDI5iQmQ9jpiVT0sNJ6aYd7dAE3QHBbinSAX5JWWaxuLo8F35jh/bBK9Y+/r/Cl6pLcnna8NvuDGMnslpbZRpXZYT/3r4EGACZL3ZL2afNFAAAAABJRU5ErkJggg==",
  1754. bottom: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAXFJREFUeNrM1c8rBGEcx/FdtCEkLqYtpdwkKSUHUhxwITdK+Z3yM2cOLnJ39Cc44SgHScmJwlFxsIdlCScO6/2t76Onp52dXTtbnno1M8+Pz84+zzMzkcg/KA3oRTzM0A4cI4VTdIUVPIM3pPGO5aABJTkGx1BqjYmFFZxW7nnBwXmXogWX6bEGc2jEIU7+kNWDUSSwZyqndSvJ3N1g2Bm0oLtB2j+w7rQP4MpqXzRT0YRaPW/BthMedYLs60HsoE2vq9BsPwAJa8XFLUa0fUrvROo/saT1Q9adGimdlt8yj6TT6Q6d2vaida9YRbtP6EqmBZC5fHA6X+AAz1bwEc6cfk9+oaZM4NoZJL70+J2hTaZtNpet041zK8yP/Mgl+rOF1emr0UM1xnAfEPyISd0Jno6vtx+QuM6PZ22lpO7dbEV2Siv6rPeIjNs1HdYC7ixfG+YBqdTVDqPIv6iIWvO7iXGUFxAqi72PraJ9IH8EGACQcYjYRd5GHwAAAABJRU5ErkJggg==",
  1755. pre: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAASlJREFUeNpiYBjOoBiIrwJxFRAzUsvQViD+CMT/gfgTEPdRy9BPUENh+AsQ91JiaAuSS9HxZ3INb8Hi0v+UurwF6qL/ROBvQNxDrKFfkTT+A+JnQPwBKfJA/L9Ian7ic7kMEHcC8Q80F3UAcRsQv4by30INaUJT9weaWhSQDRUB4uVYvLkYiAWAOBopvEFBlArEPEA8G4ue9UAsATM4EYuCJUgKMtAMLoSKCwPxXCx6c1igClTQgmUZVPNrHMEGy3mgYCkCYiYgTkCSV4UZvA2IjYBYDIgvQbPvOyJTECid5wHxbyA2BuL3QLwRWYEsEJvg0IweFEU41IEMlgcxWJAEH0MxJeAsjMFEq6Jw+Br8BimVfMCTDEkG7EBcA8T3oWUJx4DVYwABBgCannnSzbgwIQAAAABJRU5ErkJggg==",
  1756. next: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAT1JREFUeNrc1b1KA0EYheEl/iARFFEkKl6D0UK8CrEVrCwEexFCtBIlRWIjsfEiLL0FKzs7QUWxM2piFMUkvhPOwLAs2TGuCn7wkNll5jC7+w0Jgv9avdjAObbQn1TwCu7QwhWW4xakPIOHMKzxGCaSCm6ioXHLZ0Hqpz7KrwRPIvvNvBlM2zYyNY8cMjhDHo9fCBzErnIqKNjgRSxpvIABbOLes2MKWHfuXdhXcR2avKrJ4zGhI9gLhQbq9XaZgGO1kutIOzIHpKp7NawhjYOINSeY6lFwHacw17P6NTWHd4xqnNbcS83LObtsaCPbEW+gXUW8ODswC27xoOsn3ODDmfOGss9XLuE54jGjvPqGuuG1mFDzZIfdNHynnde7DbW1r5DwTstJHP2iE55YqD36ebXZDvr+7L/sU4ABAIpVZWnoA5GkAAAAAElFTkSuQmCC",
  1757. next_gray: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAtxJREFUeNrclc9L2mEcx7/6NbVZqRVj7pIOlIUuZ1HMgv0BDcqT7JrskH13ELPBF7eTvz10HznWQBlBRIfBXIfBLmqXscvYZWPKrMNIU9Apmrr34/w6i0ovMZjw+H0+z/N8Xt+Pn/fn80hR/+WHYRhBIpFwRKPRz/F4/KnD4RB28xH0Ah4cHHyoUCjsIpFIIZPJHkml0m9Yfn2ZD78XcL1eH6rValIMCmMUtqKbD7/HbNQxaq15oxcH/lXpcmXgtnh2u/2mXC6/DqE+sSxLlUqlniE0TVPBYJAqFot6+GV9Pt+PJthms80sLS2xEonkhlgs/jgwMOBcXV3N5fP5rlCcp9bX1yWLi4uecrk8U6lUshDY3wRbLJYFGKZsNksq4N78/LwY9hOn05k5Ojqi+PzTGePxeFwZUl6vd8hkMvkPDg6sZJ2M5eXlr1wqUu2kA5JOpy2IAO+oO9fW1n5mMpk2nDjmcjkKNU25XC652Wx2pVIp65mXJ2nyjUPpqakpNZxuA8Y5T87OzsobjcYHpVKpGhsbe1CtVkXYqxQKhTdqtfqL1Wr1JpPJxxyU5Lq/vz8aCoX8TTDatYiFhF6vxx5tAJwm8OPj48m5ubmKSqUaAWwSa9eQw6JGo/luNBoNh4eHbAe0JhAINsLh8LNAIJCiudhxB+Qh2ludTifDAQLvI3AIch+Rkl8jJlrhCbOqgfoLmDepOF/BfGNra2sFFZFtvqgzMbFYjAiyp9Vqh4VC4cTJyYmQ90epIQJtHRO1bA5aRhAvdnZ2GI/H87cEz5YPgeOS2RsfHx9B7u+gOi68yQAtYX9zd3eXgZCna/s8By5ypGUUzhOISHgO9BfWXwG6chZ6IbiVc6LwnsFgGIVAepLzjk4rYW1ze3ubcbvd53fjZV2FaqGQ63fT09PDMO9i9BEoon0J9Rm/339xm3dr2f39fVLX7wFvoMVvoYWfRyIRFndD/Z/8nf0WYAA8EC1Z/ZNm4gAAAABJRU5ErkJggg==",
  1758. pre_gray: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAslJREFUeNrclTtMWmEUxz/uvTzlIUhpNMR0aGNjrNHSmHTqRJyadujQDbSGRwJUaYCmDizqUEw6ODVNGgbpYCfSpFINCQzFR9oyMXRsXFCsAXkIKNL/R7gGWxOsSdPEk5zc3O+e87vn+59zv0vIpbSJiQmyubn5LBKJpNbX11+4XC5Buxy2XYDNZiMOh2OW4ziPTCbTi8XikeHh4SsSieQTXnIxsN1uJ1ardVYgEDgPDw+V9Xqd1Go1Mcuyg7AuuVy+sra29ndgVEnGx8dnhEKhs1qtKgE/eXZ8fCzC+q3+/n6tSqVaSSQS5wM7nU5iMplmsF1XpVI5BeXt6OhIBFkGAe9SKpV/wNmzKjWbzRT6tFwuK86CUqPrkIVWPjQwMKBWKBSn4Ozv0LGxsRmRSDSFSjua0Do8TRWAS+B5+B68g/IhixCNvQPN1WjuieZsS/f1aNQ0wzBuaCqlUCQRtVr9Es1K4kVDWJNhrQjAIiqMlkqle804FnkjBoOhEzv4vrGxkW2ALRaLFrq+QoAV2nE8tLe3dzEYDE5vb2939vX1PcBkiKVSaQ1jForFYq+NRqMum83ebsYzmJq7sGu4xhkKxsDfB/AxnO860ev1oeXlZU8gEMgmk0kFqmw8o9dUKiWfn58vhMPh54h7S+OpQXNSLBYfejyeR1yzw9dbRon09PS8W11dnfL5fJl8Pk+0Wi3hk5vyCNBY4vV6f0Im9+joKJNOp818o8G70ah4aWnpIzSKYCa/dXd3B+PxuHNycjKzs7NzAms1+qFQy+VydDRz0WjUpdPp3tB8TFM0FAqFGxXPzc19plJrNJqraMoXt9tNt3Suc+Tg4ICeJfmFhQVLoVAwoKG7fr//B8cHAL6Fy9ZFDinaG/r5w77ya8y/OhEvKRhjtIup2YMTeBb3mXY53HnAmNkP+/v7NzHTTwAO4f79f/ud/RJgAOLcRNZqLojMAAAAAElFTkSuQmCC",
  1759. };
  1760. const cssText = ".sp-separator{grid-column: 1 / -1; line-height:1.8 !important;opacity:1 !important;position:relative !important;float:none !important;top:0 !important;left:0 !important;min-width:366px;width:auto;text-align:center !important;font-size:14px !important;display:block !important;padding:3px 0 !important;margin:5px 10px 8px;clear:both !important;border-style:solid !important;border-color:#cccccc !important;border-width:1px !important;-moz-border-radius:30px !important;border-radius:30px !important;background-color:#ffffff !important;}.sp-separator:hover{box-shadow:0 0 11px rgba(33,33,33,0.2);}#sp-separator-hover{display:none;}.sp-separator:hover #sp-separator-hover{display:block;}.sp-separator .sp-someinfo{position:absolute !important;right:10px !important;font-size:12px !important;font-style:italic !important;background:none !important;}.sp-separator span{vertical-align: middle;cursor: pointer;padding: 0;margin: 0 5px;display: inline-block; width:22px;height:22px;}.sp-separator a{margin:0 20px 0 -6px !important;display:inline !important;text-shadow:#fff 0 1px 0 !important;background:none !important;color:#595959 !important;}.sp-separator input{padding:0 !important;line-height:23px !important;}.sp-separator .sp-md-span{font-weight:bold !important;margin:0 20px !important;}#sp-sp-md-number{width:6ch !important;vertical-align:middle !important;display:inline-block !important;text-align:left !important;}" +
  1761. `.ac_sp_top{background-image:url('${ sepImgs.top }')}` +
  1762. `.ac_sp_pre{background-image:url('${ sepImgs.pre }')}` +
  1763. `.ac_sp_next{background-image:url('${ sepImgs.next }')}` +
  1764. `.ac_sp_bottom{background-image:url('${ sepImgs.bottom }')}` +
  1765. `.ac_sp_next_gray{background-image:url('${ sepImgs.next_gray }')}` +
  1766. `.ac_sp_pre_gray{background-image:url('${ sepImgs.pre_gray }')}`
  1767. CONST.cssAutoInsert.add("preloadAutoPage", cssText)
  1768. }
  1769. if(CONST.curConfig.isBlockEnable) {
  1770. CONST.cssAutoInsert.add("customBlockStyle", "button.ghhider.ghhb[ac-user-alter='1']::before{content:'取消 - ';}#sp-ac-container .ac-block-item{color:#AAA;margin-left:48px;}#sp-ac-container .ac-block-itemdel{float:right;margin-left:0;padding:0 20px;cursor:pointer;}#sp-ac-container .ac-block-itemdel:hover{color:red;}#sp-ac-container .ac-block-high{color:#000;}.ac-blockList li:hover{background-color:#a3caff;color:white !important;cursor:pointer;} *[ac-needhide] *{display:none} *:not([ac-needhide]) .blockShow{display: none;} *[ac-needhide] .blockShow{display:unset;cursor:pointer;} *[ac-needhide] .blockShow:hover{border:1px solid #DDD}button.ghhider{color:#555;background-color:#fcfcfc;font-family:sans-serif;margin:auto 2px;border:1px solid #ccc;border-radius:4px;padding:2px 3px}button.ghhider{font-size:12px}button.ghhider:hover{color:#006aff;background:#fff} body[haosou] button.ghhider{vertical-align: super;} body[google] button.ghhider{vertical-align: top;}") // 公共自定义样式
  1771. }
  1772. if(CONST.curConfig.isFaviconEnable) {
  1773. CONST.cssAutoInsert.add("faviconStyle", CONST.adsCSSList.faviconStyle) // 插入Favicon图标
  1774. }
  1775. if(CONST.curConfig.isBlockEnable || CONST.curConfig.isFaviconEnable) {
  1776. CONST.cssAutoInsert.add("lineTitleFix", 'body[haosou] .res-title {display: inline-flex;}') // 插入Favicon图标
  1777. }
  1778. if(CONST.curConfig.isALineDisable) {
  1779. CONST.cssAutoInsert.add("alinkEnable", "a,a em{text-decoration:none !important}")
  1780. }
  1781. if(CONST.curConfig.isCounterEnable) {
  1782. CONST.cssAutoInsert.add("counterStyle", ".AC-CounterT{background:#FD9999}body #sp-ac-container{position:fixed;top:3.9vw;right:8.8vw}")
  1783. }
  1784. // if(CONST.options.useItem.SiteTypeID === CONST.options.google.SiteTypeID && CONST.curConfig.useBaiduLogo) {
  1785. // CONST.cssAutoInsert.add("useBaiduLogo", "") // 谷歌使用百度LOGO
  1786. // }
  1787.  
  1788. /*****自定义样式最后加载*****/
  1789. if (CONST.curConfig.commonStyleEnable) {
  1790. CONST.cssAutoInsert.add("commonStyle", CONST.adsCSSList.commonStyle) // 公共自定义样式
  1791. }
  1792. if (CONST.curConfig.customStyleEnable) {
  1793. CONST.cssAutoInsert.add("customStyle", CONST.adsCSSList.customStyle) // 站点自定义样式
  1794. }
  1795. }
  1796. pagerBind() {
  1797. const ShowPager = {
  1798. getFullHref: function(e) {
  1799. if (e === null) return '';
  1800. "string" != typeof e && (e = e.getAttribute("href"));
  1801. var t = this.getFullHref.a;
  1802. return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
  1803. },
  1804. createDocumentByString: function(str) {
  1805. // string转为DOM
  1806. if (!str) {
  1807. console.error("[AC-Script]", 'No string found to be converted to DOM');
  1808. return;
  1809. }
  1810.  
  1811. if (document.documentElement.nodeName !== 'HTML') {
  1812. return new DOMParser().parseFromString(str, 'application/xhtml+xml');
  1813. }
  1814. var doc;
  1815.  
  1816. MyApi.safeFunc(() => {
  1817. // firefox and chrome 30+,Opera 12 会报错
  1818. doc = new DOMParser().parseFromString(str, 'text/html');
  1819. if (doc) {
  1820. return doc;
  1821. }
  1822. })
  1823.  
  1824. if (document.implementation.createHTMLDocument) {
  1825. doc = document.implementation.createHTMLDocument('superPreloader');
  1826. } else {
  1827. MyApi.safeFunc(() => {
  1828. doc = document.cloneNode(false);
  1829. doc.appendChild(doc.importNode(document.documentElement, false));
  1830. doc.documentElement.appendChild(doc.createElement('head'));
  1831. doc.documentElement.appendChild(doc.createElement('body'));
  1832. })
  1833. }
  1834.  
  1835. if (!doc) return;
  1836. var range = document.createRange();
  1837. range.selectNodeContents(document.body);
  1838. var fragment = range.createContextualFragment(str);
  1839. doc.body.appendChild(fragment);
  1840. var headChildNames = {
  1841. TITLE: true,
  1842. META: true,
  1843. LINK: true,
  1844. STYLE: true,
  1845. BASE: true
  1846. };
  1847. var child;
  1848. var body = doc.body;
  1849. var bchilds = body.childNodes;
  1850.  
  1851. for (let i = bchilds.length - 1; i >= 0; i--) {
  1852. // 移除head的子元素
  1853. child = bchilds[i];
  1854. if (headChildNames[child.nodeName]) body.removeChild(child);
  1855. }
  1856.  
  1857. return doc;
  1858. },
  1859. loadMorePage: async function() {
  1860. if (CONST.options.useItem.pager) {
  1861. let curPageEle = MyApi.getElementByXpath(CONST.options.useItem.pager.nextLink);
  1862. var url = this.getFullHref(curPageEle);
  1863. if (CONST.options.useItem.SiteTypeID === CONST.options.google.SiteTypeID) {
  1864. if (navigator.userAgent.toLowerCase().includes('macintosh')) {
  1865. // MARK 为了兼容百度在safari下的
  1866. url = url.replace('https://', 'http://');
  1867. }
  1868. }
  1869. if (url === '') return;
  1870. if (CONST.options.useItem.pageUrl === url) {
  1871. console.error("[AC-Script]", "翻页到达底部了 - 或者异常 - 出现异常请直接反馈作者修改");
  1872. return;
  1873. }// 不会重复加载相同的页面
  1874. console.log("加载翻页地址:" + url)
  1875. CONST.options.useItem.pageUrl = url;
  1876. // 对url的数据进行读取
  1877. CONST.options.useItem.pager.startFilter && curSite.pager.startFilter();
  1878. GM_xmlhttpRequest({
  1879. url: url,
  1880. method: "GET",
  1881. timeout: 5000,
  1882. onload: function(response) {
  1883. try {
  1884. var newBody = ShowPager.createDocumentByString(response.responseText);
  1885.  
  1886. const [Rule_insertTo = '', Rule_insertMode = 1] = CONST.options.useItem.pager.HT_insert || []
  1887. let pageElems = MyApi.getAllElements(CONST.options.useItem.pager.pageElement, newBody, newBody);
  1888. const scriptElems = MyApi.getAllElements('//script', newBody, newBody);
  1889.  
  1890. let toElement;
  1891.  
  1892. if (pageElems.length) {
  1893. const curPageElems = MyApi.getAllElements(CONST.options.useItem.pager.pageElement, document, document)
  1894. const pELast = curPageElems[curPageElems.length - 1];
  1895. toElement = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1896. }
  1897. if (Rule_insertTo) {
  1898. toElement = MyApi.getAllElements(Rule_insertTo)[0];
  1899. }
  1900. if (pageElems.length >= 0) {
  1901. // 处理最后一个翻页按钮
  1902. let nextEs = document.querySelectorAll("#sp-sp-gonext");
  1903. if (nextEs.length > 0) {
  1904. let lastE = nextEs[nextEs.length - 1];
  1905. lastE.classList.replace("ac_sp_next_gray", "ac_sp_next");
  1906. }
  1907. // 插入翻页按钮元素
  1908. CONST.options.useItem.pageNum++;
  1909. let addTo = "beforeend";
  1910. if (Rule_insertMode === 1) addTo = "beforebegin";
  1911.  
  1912. const insertPager = document.createElement('div')
  1913. insertPager.id = "sp-separator-ACX".replace(/ACX/gm, CONST.options.useItem.pageNum)
  1914. insertPager.className = "sp-separator AC"
  1915. insertPager.innerHTML = `
  1916. <a class='sp-sp-nextlink' target='_blank'><b>第 <span style='color:#595959!important;'>ACX</span> 页</b></a>
  1917. <span id="sp-sp-gotop" class='ac_sp_top' title='去到顶部'></span>
  1918. <span id="sp-sp-gopre" class='${ CONST.options.useItem.pageNum <= 2 ? "ac_sp_pre_gray" : "ac_sp_pre" }' title='上滚一页' ></span>
  1919. <span id="sp-sp-gonext" class='ac_sp_next_gray' title='下滚一页'></span>
  1920. <span id="sp-sp-gobottom" class='ac_sp_bottom' title='去到底部' ></span>`
  1921. .replace(/ACX/gm, CONST.options.useItem.pageNum);
  1922.  
  1923. if(Rule_insertMode === 1) {
  1924. toElement.parentNode.insertBefore(insertPager, toElement)
  1925. // 插入新页面元素
  1926. pageElems.forEach(function(one) {
  1927. toElement.parentNode.insertBefore(one, toElement)
  1928. });
  1929. } else {
  1930. toElement.appendChild(insertPager)
  1931.  
  1932. pageElems.forEach(function(one) {
  1933. toElement.appendChild(one)
  1934. });
  1935. }
  1936.  
  1937. document.querySelectorAll(".sp-separator.AC:not([bind])").forEach(function(per) {
  1938. per.setAttribute("bind", 1);
  1939. per.addEventListener("click", PageFunc.ac_spfunc);
  1940. });
  1941.  
  1942. // 插入scripts & style - 保证js加载
  1943. if (CONST.options.useItem.SiteTypeID === CONST.options.google.SiteTypeID) {
  1944. scriptElems.forEach((one) => {
  1945. const newScript = document.createElement('script')
  1946. newScript.textContent = one.textContent // 新建一个脚本,否则可能因为不执行导致失败
  1947. toElement.appendChild(newScript)
  1948. })
  1949. }
  1950.  
  1951. // 替换待替换元素 - 一般是替换翻页的按钮
  1952. try {
  1953. if (CONST.options.useItem.pager.replaceE) {
  1954. let oriE = MyApi.getAllElements(CONST.options.useItem.pager.replaceE);
  1955. let repE = MyApi.getAllElements(CONST.options.useItem.pager.replaceE, newBody, newBody);
  1956. if (oriE.length === repE.length) {
  1957. if (oriE.length === 0) {
  1958. throw "翻页-替换翻页元素 无 'replaceE' 待替换的";
  1959. }
  1960. for (let i = 0; i < oriE.length; i++) {
  1961. oriE[i].outerHTML = repE[i].outerHTML;
  1962. }
  1963. }
  1964. }
  1965. } catch (e) {
  1966. console.log(e);
  1967. }
  1968. }
  1969. } catch (e) {
  1970. console.log(e);
  1971. }
  1972.  
  1973. CONST.lock.pageLoadingLocked = false;
  1974. },
  1975. onerror: function() {
  1976. CONST.lock.pageLoadingLocked = false;
  1977. }
  1978. });
  1979. }
  1980. },
  1981. };
  1982. console.mylog('pager已绑定成功')
  1983. this.windowscroll(async (direction, e) => {
  1984. if (direction === "down") { // 下滑才准备翻页
  1985. let spl = document.querySelector("#sp-fw-a_enable");
  1986. // 开启后,且在非(suprepreloader启用)时均可
  1987. if (CONST.curConfig.isAutopage === true && !(spl && spl.checked === true) && document.documentElement) {
  1988. const scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  1989. let scrollDelta = 888;
  1990. if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta && CONST.lock.pageLoadingLocked === false) {
  1991. console.mylog('开始进行翻页')
  1992. CONST.lock.pageLoadingLocked = true;
  1993. if (CONST.options.useItem.SiteTypeID === CONST.options.duckduckgo.SiteTypeID) { // 可以用已有的方法来实现了
  1994. if (!CONST.curConfig.optimizeDuckDuckGo || +CONST.curConfig.adsStyleMode >= 3) { // 如果没有开启,那么手动翻页 || 如果是双列的时候,似乎并不会自动触发翻页效果
  1995. const node = document.querySelector("#links .result--more a")
  1996. node && node.click();
  1997. setTimeout(function() {
  1998. CONST.lock.pageLoadingLocked = false;
  1999. }, 5000);
  2000. }
  2001. } else {
  2002. await ShowPager.loadMorePage();
  2003. if (CONST.options.useItem.pager && CONST.options.useItem.pager.stylish) {
  2004. CONST.cssAutoInsert.add('autoPager', CONST.options.useItem.pager.stylish)
  2005. } else {
  2006. setTimeout(function() {
  2007. CONST.lock.pageLoadingLocked = false;
  2008. }, 5000);
  2009. console.mylog('当前站点没有配置pager')
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. });
  2016. }
  2017. windowscroll(fn = () => {}) {
  2018. let beforeScrollTop = document.documentElement.scrollTop
  2019. window.addEventListener("scroll", function(e) {
  2020. var afterScrollTop = document.documentElement.scrollTop,
  2021. delta = afterScrollTop - beforeScrollTop;
  2022. if (delta === 0) return false;
  2023. fn(delta > 0 ? "down" : "up", e);
  2024. beforeScrollTop = afterScrollTop;
  2025. }, false);
  2026. }
  2027. ac_spfunc(e) {
  2028. console.error("这里有问题")
  2029. e.stopPropagation();
  2030. var t, r = e.currentTarget;
  2031. const Tween = {
  2032. Linear: function Linear(e, t, r, n) {
  2033. return r * e / n + t;
  2034. },
  2035. Quad: {
  2036. easeIn: function easeIn(e, t, r, n) {
  2037. return r * (e /= n) * e + t;
  2038. },
  2039. easeOut: function easeOut(e, t, r, n) {
  2040. return -r * (e /= n) * (e - 2) + t;
  2041. },
  2042. easeInOut: function easeInOut(e, t, r, n) {
  2043. return (e /= n / 2) < 1 ? r / 2 * e * e + t : -r / 2 * (--e * (e - 2) - 1) + t;
  2044. }
  2045. },
  2046. Cubic: {
  2047. easeIn: function easeIn(e, t, r, n) {
  2048. return r * (e /= n) * e * e + t;
  2049. },
  2050. easeOut: function easeOut(e, t, r, n) {
  2051. return r * ((e = e / n - 1) * e * e + 1) + t;
  2052. },
  2053. easeInOut: function easeInOut(e, t, r, n) {
  2054. return (e /= n / 2) < 1 ? r / 2 * e * e * e + t : r / 2 * ((e -= 2) * e * e + 2) + t;
  2055. }
  2056. },
  2057. Quart: {
  2058. easeIn: function easeIn(e, t, r, n) {
  2059. return r * (e /= n) * e * e * e + t;
  2060. },
  2061. easeOut: function easeOut(e, t, r, n) {
  2062. return -r * ((e = e / n - 1) * e * e * e - 1) + t;
  2063. },
  2064. easeInOut: function easeInOut(e, t, r, n) {
  2065. return (e /= n / 2) < 1 ? r / 2 * e * e * e * e + t : -r / 2 * ((e -= 2) * e * e * e - 2) + t;
  2066. }
  2067. },
  2068. Quint: {
  2069. easeIn: function easeIn(e, t, r, n) {
  2070. return r * (e /= n) * e * e * e * e + t;
  2071. },
  2072. easeOut: function easeOut(e, t, r, n) {
  2073. return r * ((e = e / n - 1) * e * e * e * e + 1) + t;
  2074. },
  2075. easeInOut: function easeInOut(e, t, r, n) {
  2076. return (e /= n / 2) < 1 ? r / 2 * e * e * e * e * e + t : r / 2 * ((e -= 2) * e * e * e * e + 2) + t;
  2077. }
  2078. },
  2079. Sine: {
  2080. easeIn: function easeIn(e, t, r, n) {
  2081. return -r * Math.cos(e / n * (Math.PI / 2)) + r + t;
  2082. },
  2083. easeOut: function easeOut(e, t, r, n) {
  2084. return r * Math.sin(e / n * (Math.PI / 2)) + t;
  2085. },
  2086. easeInOut: function easeInOut(e, t, r, n) {
  2087. return -r / 2 * (Math.cos(Math.PI * e / n) - 1) + t;
  2088. }
  2089. },
  2090. Expo: {
  2091. easeIn: function easeIn(e, t, r, n) {
  2092. return 0 == e ? t : r * Math.pow(2, 10 * (e / n - 1)) + t;
  2093. },
  2094. easeOut: function easeOut(e, t, r, n) {
  2095. return e == n ? t + r : r * (1 - Math.pow(2, -10 * e / n)) + t;
  2096. },
  2097. easeInOut: function easeInOut(e, t, r, n) {
  2098. return 0 == e ? t : e == n ? t + r : (e /= n / 2) < 1 ? r / 2 * Math.pow(2, 10 * (e - 1)) + t : r / 2 * (2 - Math.pow(2, -10 * --e)) + t;
  2099. }
  2100. },
  2101. Circ: {
  2102. easeIn: function easeIn(e, t, r, n) {
  2103. return -r * (Math.sqrt(1 - (e /= n) * e) - 1) + t;
  2104. },
  2105. easeOut: function easeOut(e, t, r, n) {
  2106. return r * Math.sqrt(1 - (e = e / n - 1) * e) + t;
  2107. },
  2108. easeInOut: function easeInOut(e, t, r, n) {
  2109. return (e /= n / 2) < 1 ? -r / 2 * (Math.sqrt(1 - e * e) - 1) + t : r / 2 * (Math.sqrt(1 - (e -= 2) * e) + 1) + t;
  2110. }
  2111. },
  2112. Elastic: {
  2113. easeIn: function easeIn(e, t, r, n, a, o) {
  2114. return 0 == e ? t : 1 == (e /= n) ? t + r : (o || (o = .3 * n), !a || a < Math.abs(r) ? (a = r,
  2115. i = o / 4) : i = o / (2 * Math.PI) * Math.asin(r / a), -a * Math.pow(2, 10 * (e -= 1)) * Math.sin((e * n - i) * (2 * Math.PI) / o) + t);
  2116. var i;
  2117. },
  2118. easeOut: function easeOut(e, t, r, n, a, o) {
  2119. return 0 == e ? t : 1 == (e /= n) ? t + r : (o || (o = .3 * n), !a || a < Math.abs(r) ? (a = r,
  2120. i = o / 4) : i = o / (2 * Math.PI) * Math.asin(r / a), a * Math.pow(2, -10 * e) * Math.sin((e * n - i) * (2 * Math.PI) / o) + r + t);
  2121. var i;
  2122. },
  2123. easeInOut: function easeInOut(e, t, r, n, a, o) {
  2124. return 0 == e ? t : 2 == (e /= n / 2) ? t + r : (o || (o = n * (.3 * 1.5)), !a || a < Math.abs(r) ? (a = r,
  2125. i = o / 4) : i = o / (2 * Math.PI) * Math.asin(r / a), e < 1 ? a * Math.pow(2, 10 * (e -= 1)) * Math.sin((e * n - i) * (2 * Math.PI) / o) * -.5 + t : a * Math.pow(2, -10 * (e -= 1)) * Math.sin((e * n - i) * (2 * Math.PI) / o) * .5 + r + t);
  2126. var i;
  2127. }
  2128. },
  2129. Back: {
  2130. easeIn: function easeIn(e, t, r, n, a) {
  2131. return null == a && (a = 1.70158), r * (e /= n) * e * ((a + 1) * e - a) + t;
  2132. },
  2133. easeOut: function easeOut(e, t, r, n, a) {
  2134. return null == a && (a = 1.70158), r * ((e = e / n - 1) * e * ((a + 1) * e + a) + 1) + t;
  2135. },
  2136. easeInOut: function easeInOut(e, t, r, n, a) {
  2137. return null == a && (a = 1.70158), (e /= n / 2) < 1 ? r / 2 * (e * e * ((1 + (a *= 1.525)) * e - a)) + t : r / 2 * ((e -= 2) * e * ((1 + (a *= 1.525)) * e + a) + 2) + t;
  2138. }
  2139. },
  2140. Bounce: {
  2141. easeIn: function easeIn(e, t, r, n) {
  2142. return r - Tween.Bounce.easeOut(n - e, 0, r, n) + t;
  2143. },
  2144. easeOut: function easeOut(e, t, r, n) {
  2145. return (e /= n) < 1 / 2.75 ? r * (7.5625 * e * e) + t : e < 2 / 2.75 ? r * (7.5625 * (e -= 1.5 / 2.75) * e + .75) + t : e < 2.5 / 2.75 ? r * (7.5625 * (e -= 2.25 / 2.75) * e + .9375) + t : r * (7.5625 * (e -= 2.625 / 2.75) * e + .984375) + t;
  2146. },
  2147. easeInOut: function easeInOut(e, t, r, n) {
  2148. return e < n / 2 ? .5 * Tween.Bounce.easeIn(2 * e, 0, r, n) + t : .5 * Tween.Bounce.easeOut(2 * e - n, 0, r, n) + .5 * r + t;
  2149. }
  2150. }
  2151. };
  2152. const TweenM = ["Linear", "Quad", "Cubic", "Quart", "Quint", "Sine", "Expo", "Circ", "Elastic", "Back", "Bounce"];
  2153. const TweenEase = ["easeIn", "easeOut", "easeInOut"];
  2154. var prefs = {
  2155. s_method: 3,
  2156. s_ease: 2,
  2157. s_FPS: 60,
  2158. s_duration: 333,
  2159. };
  2160.  
  2161. function getRelativeDiv(e) {
  2162. var t = r.id;
  2163. return (t = t.replace(/(sp-separator-)(.+)/, (function(t, r, n) {
  2164. return r + String(Number(n) + ("pre" == e ? -1 : 1));
  2165. }))) ? document.getElementById(t) : null;
  2166. }
  2167.  
  2168. function sp_transition(e, t) {
  2169. var r = sp_transition.TweenF;
  2170. r || (r = (r = Tween[TweenM[prefs.s_method]])[TweenEase[prefs.s_ease]] || r, sp_transition.TweenF = r);
  2171. var n = 1e3 / prefs.s_FPS, a = 0, o = e, i = t - e, s = Math.ceil(prefs.s_duration / n),
  2172. c = window.scrollX;
  2173. !function transition() {
  2174. var e = Math.ceil(r(a, o, i, s));
  2175. window.scroll(c, e), a < s && (a++, setTimeout(transition, n));
  2176. }();
  2177. }
  2178.  
  2179. function scrollIt(e, t) {
  2180. sp_transition(e, t);
  2181. }
  2182.  
  2183. switch (e.target.id) {
  2184. case "sp-sp-gotop":
  2185. scrollIt(window.scrollY, 0);
  2186. break;
  2187.  
  2188. case "sp-sp-gopre":
  2189. var n = getRelativeDiv("pre");
  2190. if (!n) return;
  2191. t = window.scrollY;
  2192. var a = n.getBoundingClientRect().top;
  2193. a = t - (r.getBoundingClientRect().top - a);
  2194. scrollIt(t, a);
  2195. break;
  2196.  
  2197. case "sp-sp-gonext":
  2198. var o = getRelativeDiv("next");
  2199. if (!o) return;
  2200. t = window.scrollY;
  2201. var i = o.getBoundingClientRect().top;
  2202. i = t + (-r.getBoundingClientRect().top + i);
  2203. scrollIt(t, i);
  2204. break;
  2205.  
  2206. case "sp-sp-gobottom":
  2207. scrollIt(window.scrollY, Math.max(document.documentElement.scrollHeight, document.body.scrollHeight));
  2208. }
  2209. }
  2210. bingAutoScrollFix() {
  2211. document.addEventListener('visibilitychange', function() {
  2212. if (document.visibilityState === 'hidden') {
  2213. CONST.bingScrollPos = document.documentElement.scrollTop;
  2214. } else if (document.visibilityState === 'visible') {
  2215. setTimeout(() => {
  2216. if(CONST.bingScrollPos !== 0 && document.documentElement.scrollTop !== CONST.bingScrollPos) {
  2217. console.error('触发滚动条变更:', CONST.bingScrollPos, document.documentElement.scrollTop)
  2218. document.documentElement.scrollTop = CONST.bingScrollPos
  2219. }
  2220. }, 50)
  2221. }
  2222. });
  2223. }
  2224. bingFaviconPagerFix() {
  2225. document.querySelectorAll('div.rms_iac').forEach(one => {
  2226. const height = one.dataset.height
  2227. const width = one.dataset.width
  2228. const toClass = one.dataset.class
  2229. const imgSrc = one.dataset.src
  2230. const bm = one.dataset.bm
  2231. if(imgSrc) {
  2232. one.outerHTML = `<img src="${imgSrc}" height="${height}" width="${width}" data-priority="2" role="presentation" class="${toClass}" data-bm="${bm}">`
  2233. }
  2234. })
  2235. }
  2236. }
  2237. class PageBlockClass {
  2238. constructor() {
  2239. this.curSite = CONST.options.useItem
  2240. this.regListRule = []
  2241. this._updateRegListRule()
  2242. }
  2243.  
  2244. async start() {
  2245. const needCheckClass = (this.curSite.MainType + ',').split(',').join(":not([bhandle]),")
  2246. let checkNodes = document.querySelectorAll(needCheckClass.substring(0, needCheckClass.length - 1));
  2247. for (let i = 0; i < checkNodes.length; i++) {
  2248. let curNode = checkNodes[i];
  2249. try {
  2250. let faviconNode = curNode.querySelector(this.curSite.FaviconType);
  2251. let host = PageFunc.getNodeHost(faviconNode).curHost;
  2252. let faNode = curNode.querySelector(this.curSite.BlockType);
  2253. let nodeStyle = "display:unset;";
  2254. if (!CONST.curConfig.isBlockBtnDisplay) {
  2255. nodeStyle = "display:none;";
  2256. }
  2257. // 避免父节点出现两个block按钮
  2258. if (faNode && !faNode.hasAttribute('hasInsert')) {
  2259. faNode.setAttribute("hasInsert", "1");
  2260. let insertTo = faNode.parentNode
  2261. if(CONST.options.useItem.SiteTypeID === CONST.options.google.SiteTypeID) {
  2262. insertTo = faNode
  2263. }
  2264. insertTo.insertAdjacentHTML("beforeend", `<button style='${ nodeStyle }' class='ghhider ghhb' href="${ faviconNode?.href || faviconNode?.innerText }" meta="${ host }" data-host="${ host }" title='${ this._getBlockBtnTitle(host) }'>block</button>`);
  2265. }
  2266. curNode.setAttribute("bhandle", "1");
  2267. } catch (e) {
  2268. console.error(e)
  2269. const failed_count = +(curNode.getAttribute('failed_count') || 1)
  2270. curNode.setAttribute('failed_count', failed_count + 1)
  2271. if (failed_count > 3) {
  2272. curNode.setAttribute("bhandle", "1");
  2273. }
  2274. }
  2275. }
  2276. this._initListener();
  2277. await this.renderDisplay()
  2278. }
  2279. async renderDisplay() {
  2280. // 增加checking中的检查,避免多次重复调用,减少cpu消耗
  2281. if (CONST.lock.isBlockChecking) return
  2282. CONST.lock.isBlockChecking = true
  2283.  
  2284. let checkNodes = document.querySelectorAll(this.curSite.MainType);
  2285. if([...checkNodes].every(one => one.dataset.checked) && CONST.lock.afterBlockChangeChecked) {
  2286. CONST.lock.isBlockChecking = false
  2287. return
  2288. }
  2289. const regList = this.regListRule
  2290. let flag = "ac-needhide";
  2291. for (let i = 0; i < checkNodes.length; i++) {
  2292. try {
  2293. let curNode = checkNodes[i];
  2294. if (curNode.querySelector("button[ac-user-alter]") != null) continue; // 用户手动点过显示的,那么跳过check
  2295. // 减少数据计算
  2296. let { curHost = "", curUrl = "" } = PageFunc.getNodeHost(curNode.querySelector(this.curSite.FaviconType));
  2297. if (!curHost) continue
  2298. let BlockBtn = curNode.querySelector(".ghhider.ghhb");
  2299. BlockBtn.dataset.host = BlockBtn.dataset.meta = curHost;
  2300. BlockBtn.title = this._getBlockBtnTitle(curHost);
  2301. // 减少数据计算
  2302. if (curHost && regList.findIndex(one => {
  2303. try {
  2304. return one.test(curHost || curUrl); // 耗时操作
  2305. } catch (e) {
  2306. return one === curHost;
  2307. }
  2308. }) >= 0) {
  2309. // 只检查在屏蔽表中的数据
  2310. if (!curNode.hasAttribute(flag)) {
  2311. curNode.setAttribute(flag, "1");
  2312. if (CONST.curConfig.isBlockResultDisplay) { // 对于不显示的数据可以进行移除操作
  2313. curNode.remove();
  2314. continue;
  2315. }
  2316. let curTitle = curNode.querySelector(this.curSite.BlockType);
  2317. curTitle = curTitle.innerText || curTitle.textContent;
  2318.  
  2319. (function(xcur) {
  2320. const blockShow = xcur.querySelector(".blockShow");
  2321. if(!blockShow) {
  2322. curNode.insertAdjacentHTML("afterBegin", `<span class="blockShow" title="如果需要一直显示,请在自定义中DIY目录移除本地址">${ curTitle }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -block by ${ curHost }</span>`);
  2323. // 已经屏蔽之后的内容,点击一下显示原始内容
  2324. xcur.addEventListener("click", function(env) {
  2325. if(!xcur.querySelector(".blockShow")) return
  2326. xcur.querySelector("button.ghhider").setAttribute("ac-user-alter", "1"); // 这个属性用于保持在DOM更新时,按钮不变
  2327. xcur.removeAttribute(flag);
  2328. delete xcur.dataset.checked
  2329. MyApi.safeFunc(function() {
  2330. xcur.querySelector(".blockShow").remove();
  2331. });
  2332. env.stopPropagation();
  2333. env.preventDefault()
  2334. });
  2335. }
  2336. })(curNode);
  2337. }
  2338. } else {
  2339. curNode.removeAttribute(flag);
  2340. }
  2341. curNode.dataset.checked = '1'
  2342. } catch (e) {}
  2343. }
  2344. CONST.lock.isBlockChecking = false
  2345. CONST.lock.afterBlockChangeChecked = true
  2346. }
  2347. async _updateRegListRule() {
  2348. this.regListRule = CONST.blockRuleList.filter(one => one).map(one => {
  2349. try{
  2350. return new RegExp(one.replace("*", ".*"))
  2351. }catch (e){
  2352. return one
  2353. }
  2354. })
  2355. }
  2356. _initListener() {
  2357. let checkNodes = document.querySelectorAll("button.ghhider:not([acEnv])");
  2358.  
  2359. checkNodes.forEach(one => {
  2360. one.addEventListener("click", this._doHideEnv);
  2361. one.setAttribute("acEnv", "0");
  2362. })
  2363. }
  2364. _doHideEnv(env) {
  2365. // 先插入数据---记得还要写入存储
  2366. let node = env.sourceTarget || env.target;
  2367. let host = node.dataset.host;
  2368. if (+node.getAttribute("ac-user-alter") === 1) {
  2369. // 已经屏蔽之后,再次点击block应该是取消状态
  2370. node.removeAttribute("ac-user-alter");
  2371. CONST.blockRuleList.acremove(host);
  2372. } else {
  2373. // 正常屏蔽操作
  2374. node.removeAttribute("ac-user-alter");
  2375. CONST.blockRuleList.acpush(host);
  2376. }
  2377. CONST.saveBlockRule()
  2378. env.stopPropagation();
  2379. }
  2380. _getBlockBtnTitle(host) {
  2381. return `点击即可屏蔽 ${ host } 放开,需要在自定义中手动配置放开`;
  2382. }
  2383. }
  2384.  
  2385. const PageFunc = new PageFuncClass()
  2386. const PageBlockFunc = new PageBlockClass()
  2387.  
  2388. !await (async function() {
  2389. /***Google***/
  2390. CONST.addIntervalTrigger('google', 'now', (counter) => {
  2391. function findAndMarkP2Line() {
  2392.  
  2393. function markFatherChild(child, father) {
  2394. const child_checkedAttr = child.getAttribute('two-checked') || 0
  2395. const father_checkedAttr = father.getAttribute('two-checked') || 0
  2396. child.setAttribute('two-child', 1)
  2397. child.setAttribute('two-checked', +child_checkedAttr + 1)
  2398. father.setAttribute('two-father', 1)
  2399. father.setAttribute('two-checked', +father_checkedAttr + 1)
  2400. return father
  2401. }
  2402.  
  2403. // 检查的事preNode 和 curNode
  2404. // 但是需要先判断curNode和fatherNode有没有
  2405. function getTrueFatherChild(preNode, curNode, fatherNode) {
  2406. const minItemHeight = 100
  2407. const father_curPossible = curNode.offsetHeight > minItemHeight && fatherNode.offsetHeight / curNode.offsetHeight > 1.5
  2408. const father_anotherPossible = [...fatherNode.children].some(one => {
  2409. return one !== curNode && one.offsetHeight > minItemHeight && fatherNode.offsetHeight / one.offsetHeight > 5;
  2410. })
  2411. // 先检查父节点是否否和要求
  2412. if (father_curPossible && father_anotherPossible) {
  2413. return markFatherChild(curNode, fatherNode)
  2414. } else {
  2415. const now_curPossible = preNode.offsetHeight > minItemHeight && curNode.offsetHeight / preNode.offsetHeight > 1.5
  2416. const now_anotherPossible = [...curNode.children].some(one => {
  2417. return one !== preNode && one.offsetHeight > minItemHeight && curNode.offsetHeight / one.offsetHeight > 5;
  2418. })
  2419. // 父节点不行的话,那么检查子节点是否符合要求
  2420. if(now_curPossible && now_anotherPossible) {
  2421. return markFatherChild(preNode, curNode)
  2422. }
  2423. return null
  2424. }
  2425. }
  2426.  
  2427.  
  2428. function MarkMine(curItem) {
  2429. let maxHeight = 6, curHeight = 1
  2430. let preNode = curItem
  2431. while (curHeight < maxHeight) {
  2432. const parentNode = curItem.parentNode
  2433. let attrV = curItem.getAttribute('two-checked') || 0
  2434. if (!curItem.hasAttribute('two-checked') || +attrV < 5) {
  2435. const node = getTrueFatherChild(preNode, curItem, parentNode)
  2436. if (node) return node
  2437. }
  2438. curItem.setAttribute('two-checked', +attrV + 1)
  2439. preNode = curItem
  2440. curItem = parentNode
  2441. curHeight++
  2442. }
  2443. return null
  2444. }
  2445.  
  2446. const gList = document.querySelectorAll(".g:not([two-checked*='5'])")
  2447.  
  2448. return [...gList].filter(one => MarkMine(one))
  2449. }
  2450.  
  2451. const valid = location.href.search(/(&|\?)(q|kw)=/) >= 0 ||
  2452. document.querySelector(".g, div[two-father]")
  2453. if (!valid) {
  2454. CONST.curConfig.enableCSS = false
  2455. return
  2456. }
  2457. findAndMarkP2Line()
  2458. if(counter % 4 === 0) {
  2459. if (CONST.curConfig.useBaiduLogo) {
  2460. PageFunc.GoogleInBaiduMode()
  2461. }
  2462. if (CONST.curConfig.isAdsEnable) {
  2463. PageFunc.removeAds.removeGoogleAd()
  2464. }
  2465. }
  2466. }, 50, Infinity)
  2467. /***Baidu***/
  2468. CONST.addIntervalTrigger('baidu', 'body', () => {
  2469. // 没有(百度搜索结果的标志-[存在]百度的内容) return;
  2470. const valid = location.href.search(/(&|\?)(wd|word)=/) >= 0 ||
  2471. document.querySelector("#content_left") || document.querySelector('.s_form').offsetHeight < 100
  2472. if (!valid) {
  2473. console.mylog('无效页面,不存在搜索结构')
  2474. CONST.curConfig.enableCSS = false
  2475. return
  2476. }
  2477. if (CONST.curConfig.isAdsEnable) {
  2478. PageFunc.removeAds.removeBaiduAd()
  2479. }
  2480. if (CONST.curConfig.doRemoveSug) { // 不启用移动预测[默认]
  2481. PageFunc.acSetCookie("ORIGIN", 2, "www.baidu.com");
  2482. PageFunc.acSetCookie("ISSW", 1);
  2483. PageFunc.acSetCookie("ISSW", 1, "www.baidu.com");
  2484. }
  2485. if (location.href.includes("tn=news")) {
  2486. if (!document.body.hasAttribute('news')) document.body.setAttribute("news", "1");
  2487. } else {
  2488. document.body.removeAttribute("news");
  2489. }
  2490. }, 200, Infinity)
  2491. /***Haosou***/
  2492. CONST.addIntervalTrigger('haosou', 'body', () => {
  2493. if (CONST.curConfig.isAdsEnable) {
  2494. PageFunc.removeAds.removeHaosouAd()
  2495. }
  2496. }, 200, Infinity)
  2497. /***Bing***/
  2498. CONST.addIntervalTrigger('bing', 'body', () => {
  2499. if (CONST.curConfig.isAdsEnable) {
  2500. PageFunc.removeAds.removeBingAd()
  2501. }
  2502. PageFunc.bingAutoScrollFix()
  2503. PageFunc.bingFaviconPagerFix()
  2504. }, 200, Infinity)
  2505. /***DuckDuckgo***/
  2506. CONST.addIntervalTrigger('duckduckgo', 'body', () => {
  2507. if (CONST.curConfig.optimizeDuckDuckGo) {
  2508. setTimeout(function() {
  2509. MyApi.safeFunc(() => {
  2510. DDG.settings.set("kn", 1, { // 新窗口打开页面
  2511. saveToCloud: true,
  2512. forceTheme: true
  2513. });
  2514. DDG.settings.set("kav", 1, { // 连续显示搜索结果
  2515. saveToCloud: true,
  2516. forceTheme: true
  2517. });
  2518. })
  2519. }, 3000);
  2520. }
  2521. }, 200, Infinity)
  2522. /***All***/
  2523. CONST.addIntervalTrigger('all', 'body', () => {
  2524. PageFunc.RedirectHandle()
  2525. if (CONST.curConfig.isFaviconEnable && typeof (CONST.options.useItem.FaviconType) !== 'undefined') { // 显示favicon图标
  2526. // 延迟2秒加载,减少可能出现的问题
  2527. PageFunc.addFavicon(document.querySelectorAll(CONST.options.useItem.FaviconType)); // 添加Favicon显示
  2528. } else {
  2529. document.querySelectorAll(CONST.options.useItem.FaviconType).forEach((one) => {
  2530. one.removeAttribute("ac_faviconstatus");
  2531. })
  2532. }
  2533. if (CONST.curConfig.isCounterEnable) {
  2534. // 延迟加载,避免页面出现js问题
  2535. setTimeout(() => {
  2536. PageFunc.addCounter(document.querySelectorAll(CONST.options.useItem.CounterType)); // 显示计数器
  2537. }, 800)
  2538. } else {
  2539. document.querySelectorAll(".AC-CounterT").forEach(one => {
  2540. one.parentElement.removeAttribute('SortIndex');
  2541. one.remove()
  2542. })
  2543. }
  2544.  
  2545. // 双列模式下,自动禁用右侧栏
  2546. if (!CONST.curConfig.isRightDisplayEnable || CONST.curConfig.adsStyleMode >= 3) {
  2547. document.body.classList.remove("showRight")
  2548. } else {
  2549. if (!document.body.classList.contains('showRight')) {
  2550. document.body.classList.add("showRight")
  2551. }
  2552. }
  2553.  
  2554. if (CONST.curConfig.isBlockEnable && CONST.curConfig.isRedirectEnable) {
  2555. PageBlockFunc.start()
  2556. }
  2557. }, 200, Infinity)
  2558.  
  2559. // CONST.enableCSS = 如果生效,那么插入样式表,否则跳过样式表插入
  2560. // CONST.curConfig = 网站配置,同步过来的,以及动态被修改的
  2561. // CONST.options.useItem = 网站的静态选择器
  2562.  
  2563. MyApi.safeWaitFunc('html', () => {
  2564. GM_addValueChangeListener('SyncConfig', (key, oldVal, newVal = '{}', remote) => {
  2565. const syncOptions = JSON.parse(newVal)
  2566. CONST.renewConfig(syncOptions)
  2567. if (syncOptions.refreshUrl) MyApi.refreshAfter(500)
  2568. })
  2569. PageFunc.dataChangeFireCallback()
  2570. watch(CONST.curConfig, async() => {
  2571. await CONST.loadSiteCSS()
  2572. PageFunc.dataChangeFireCallback()
  2573. })
  2574. watch(CONST.cssFavionList, ()=> {
  2575. const baseCSS = 'h3::before, h2::before {content: " ";display:inline-block} *[data-favicon-t]:before{width: 16px; height: 16px; margin-right: 4px; background-size: 100% 100%; vertical-align: text-top;}'
  2576. CONST.adsCSSList.faviconStyle = Object.entries(CONST.cssFavionList.list).reduce((preCSS, cur) => {
  2577. const [, { tagName = '', url = '' }] = cur
  2578. let nowCSS = ''
  2579. if (url) {
  2580. // https://www.xtwind.com/api/index.php?url=???? 挂了。。。
  2581. // https://statics.dnspod.cn/proxy_favicon/_/favicon?domain=sina.cn
  2582. // www.google.com/s2/favicons?domain=764350177.lofter.com
  2583. //如果地址不正确,那么丢弃
  2584. const imgUrl = "https://favicon.yandex.net/favicon/v2/" + url + "?size=32"
  2585. nowCSS = tagName + `[data-favicon-t='${ url }']:before{background-image: url('${ imgUrl }');}`
  2586. }
  2587. return preCSS + nowCSS
  2588. }, baseCSS)
  2589. PageFunc.dataChangeFireCallback()
  2590. })
  2591. }, 20, true)
  2592. MyApi.safeWaitFunc('body', () => {
  2593. const insertName = CONST.curConfig.enableCSS ? CONST.options.siteName : (CONST.options.siteName + '_nocss')
  2594. if (!document.body.hasAttribute(insertName)) {
  2595. document.body.setAttribute(insertName, '1')
  2596. document.body.classList.add(insertName)
  2597. }
  2598. PageFunc.InsertSettingMenu()
  2599. if (CONST.curConfig.isAutopage) {
  2600. setTimeout(() => {
  2601. PageFunc.pagerBind()
  2602. }, 2000)
  2603. }
  2604. }, 20, true)
  2605. })()
  2606. })()