Block Sites and Redirect

自动屏蔽微博、联合早报等指定网站,跳转至百度

  1. // ==UserScript==
  2. // @name Block Sites and Redirect
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 自动屏蔽微博、联合早报等指定网站,跳转至百度
  6. // @author YourName
  7. // @match *://*/*
  8. // @run-at document-start
  9. // @grant none
  10. // @license GPL version 3
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // 正则表达式黑名单(支持多级子域名)
  17. const blockedRegex = [
  18. /(^|\.)weibo\.com$/, // 匹配 weibo.com 及所有子域
  19. /(^|\.)zaobao\.com(\.|$)/, // 匹配 zaobao.com 及其多级子域(如zaobao.com.sg)
  20. /(^|\.)tophub\.today$/ // 匹配 tophub.today 及所有子域
  21. ];
  22.  
  23. // 获取当前域名(转换为小写避免大小写问题)
  24. const currentHost = window.location.hostname.toLowerCase();
  25.  
  26. // 执行正则匹配检测
  27. const shouldBlock = blockedRegex.some(regex => regex.test(currentHost));
  28.  
  29. // 执行屏蔽逻辑
  30. if (shouldBlock) {
  31. // 跳转前验证是否已经在目标网站(防止循环跳转)
  32. if (!/^www\.baidu\.com$/i.test(currentHost)) {
  33. window.location.replace('https://www.baidu.com/');
  34. }
  35. }
  36. })();