自研 - 多个站点 - 反外站拦截

去除某些网站的外站拦截。目前已适配知乎、Pixiv(予素)、Gitee、天眼查、百度贴吧、插画世界或森空岛。

目前为 2024-06-02 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 自研 - 多个站点 - 反外站拦截
  3. // @name:en_US Self-made - Multi-site - Anti-External Site Interception
  4. // @description 去除某些网站的外站拦截。目前已适配知乎、Pixiv(予素)、Gitee、天眼查、百度贴吧、插画世界或森空岛。
  5. // @description:en_US Remove external site interception for some websites. Currently compatible with Zhihu, Pixiv, Gitee, TianYanCha, Baidu Tieba, Vlipix, and SKLAND.
  6. // @version 1.0.2
  7. // @author CPlayerCHN
  8. // @license MulanPSL-2.0
  9. // @namespace https://www.gitlink.org.cn/CPlayerCHN
  10. // @match *://*.zhihu.com/*
  11. // @match *://www.pixiv.net/*
  12. // @match *://gitee.com/*
  13. // @match *://www.tianyancha.com/*
  14. // @match *://jump2.bdimg.com/safecheck/index
  15. // @match *://www.vilipix.com/*
  16. // @match *://www.skland.com/*
  17. // @run-at document-start
  18. // @noframes
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23.  
  24. // 定义「配置」变量,「解码」「暂停执行」「点击器」函数。
  25.  
  26. const config = [
  27. // {
  28. // "name": "站点名",
  29. // "matchLink": /匹配链接/,
  30. // "target": "目标",
  31. // "reproduce": "复现链接"
  32. // },
  33. {
  34. "name": "知乎",
  35. "matchLink": /^link.zhihu.com/,
  36. "target": "target",
  37. "reproduce": "https://www.zhihu.com/question/646179463/answer/3411700328"
  38. },
  39. {
  40. "name": "Pixiv(予素)",
  41. "matchLink": /^www.pixiv.net\/jump.php/,
  42. "target": "$withoutParamKey",
  43. "reproduce": "https://www.pixiv.net/users/10885193 > 查看个人资料"
  44. },
  45. {
  46. "name": "Gitee",
  47. "matchLink": /^gitee.com\/link/,
  48. "target": "target",
  49. "reproduce": "https://gitee.com/rmbgame/SteamTools#从移动端-steam-app-导入令牌指南"
  50. },
  51. {
  52. "name": "天眼查",
  53. "matchLink": /^www.tianyancha.com\/security/,
  54. "target": "target",
  55. "reproduce": "https://www.tianyancha.com/company/2347945472"
  56. },
  57. {
  58. "name": "百度贴吧",
  59. "matchLink": /^jump2.bdimg.com\/safecheck\/index/,
  60. "target": ".warning_info a",
  61. "reproduce": "https://tieba.baidu.com/p/8459041179 > 5楼 > 彼梦Archi"
  62. },
  63. {
  64. "name": "插画世界",
  65. "matchLink": /^www.vilipix.com\/jump/,
  66. "target": "$withoutParamKey",
  67. "reproduce": "https://www.vilipix.com/illust/108871691"
  68. },
  69. {
  70. "name": "森空岛",
  71. "matchLink": /^www.skland.com\/third-link/,
  72. "target": "target",
  73. "reproduce": "https://www.skland.com/ > 工具箱 > 塞壬唱片"
  74. }
  75. ];
  76.  
  77. function decode(data) {
  78.  
  79. // 判断状况并解码。
  80. if(/^http(s)/.test(data)) {
  81.  
  82. return decodeURIComponent(data);
  83.  
  84. }else {
  85.  
  86. return atob(data);
  87.  
  88. }
  89.  
  90. };
  91.  
  92. function sleep(ms) {
  93.  
  94. return new Promise(resolve => setTimeout(resolve, ms));
  95.  
  96. }
  97.  
  98. async function clicker(elm) {
  99.  
  100. // 定义「按钮元素」变量
  101. const btn = document.querySelector(elm);
  102.  
  103. // 如果「按钮元素」存在就点击,不存在就等待 .1 秒后再次判断
  104. if(btn) {
  105.  
  106. btn.click();
  107.  
  108. }else {
  109.  
  110. await sleep(100);
  111. clicker(elm);
  112.  
  113. }
  114.  
  115. };
  116.  
  117.  
  118. // 遍历「配置」
  119. config.forEach((data) => {
  120.  
  121. // 当链接匹配,就判断目标执行方法并执行对应操作。
  122. if(data.matchLink.test(location.href.replace(/http(s):\/\//, ""))) {
  123.  
  124. // 定义「目标」变量
  125. const target = data.target;
  126.  
  127. // 内容中有 .、# 或 ] 结尾的判断为元素点击;其他字符串判断为链接参数;函数判断为自定义参数
  128. if(typeof target === "string" && /\.|#|\]/.test(target)) {
  129.  
  130. clicker(target);
  131.  
  132. }else if(typeof target === "string" && location.search !== "" && target === "$withoutParamKey") {
  133.  
  134. // 停止网页继续加载
  135. window.stop();
  136.  
  137. // 访问页面
  138. window.open(decode(location.search.substring(1)), "_self");
  139.  
  140. }else if(typeof target === "string" && location.search !== "") {
  141.  
  142. // 停止网页继续加载
  143. window.stop();
  144.  
  145. // 定义「网页参数」变量
  146. const params = new URLSearchParams(location.search.substring(1));
  147.  
  148. // 访问页面
  149. window.open(decode(params.get(target)), "_self");
  150.  
  151. }else if(typeof target === "function") {
  152.  
  153. target();
  154.  
  155. }
  156.  
  157. }
  158.  
  159. });
  160.  
  161. // 定义「侦测器」变量
  162. const observer = new MutationObserver(() => {
  163.  
  164. // 遍历所有未被修改的链接元素
  165. document.querySelectorAll('a:not(.removeIntercepted)').forEach((link) => {
  166.  
  167. // 遍历「配置」
  168. config.forEach((data) => {
  169.  
  170. // 定义「目标」变量
  171. const target = data.target;
  172.  
  173. // 如果链接匹配、「目标」是字符串、「目标」不是 CSS 选择器、「目标」不是特殊执行方式且链接网页参数不是空的就
  174. // $withoutParamKey 之后再写
  175. if(data.matchLink.test(link.href.replace(/https?:\/\//, "")) && typeof target === "string" && !/\.|#|\]/.test(target) && target !== "$withoutParamKey" && new URL(link.href).search !== "") {
  176.  
  177. // 定义「网页参数」变量
  178. const params = new URLSearchParams(new URL(link.href).search.substring(1));
  179.  
  180. // 修改链接地址并添加「removeIntercepted」类,防止重复检测
  181. link.href = decode(params.get(target));
  182. link.classList.add("removeIntercepted");
  183.  
  184. }
  185.  
  186. });
  187.  
  188. });
  189.  
  190. });
  191.  
  192. // 当页面加载了 Body 元素,就配置「侦测器」侦测目标节点
  193. document.addEventListener('DOMContentLoaded', () => {
  194. observer.observe(document.body, {
  195. "subtree": true,
  196. "childList": true
  197. });
  198. });
  199.  
  200. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址