Block Sites and Redirect

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Block Sites and Redirect
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动屏蔽微博、联合早报等指定网站,跳转至百度
// @author       YourName
// @match        *://*/*
// @run-at       document-start
// @grant        none
// @license     GPL version 3
// ==/UserScript==

(function() {
    'use strict';

    // 正则表达式黑名单(支持多级子域名)
    const blockedRegex = [
        /(^|\.)weibo\.com$/,          // 匹配 weibo.com 及所有子域
        /(^|\.)zaobao\.com(\.|$)/,    // 匹配 zaobao.com 及其多级子域(如zaobao.com.sg)
        /(^|\.)tophub\.today$/        // 匹配 tophub.today 及所有子域
    ];

    // 获取当前域名(转换为小写避免大小写问题)
    const currentHost = window.location.hostname.toLowerCase();

    // 执行正则匹配检测
    const shouldBlock = blockedRegex.some(regex => regex.test(currentHost));

    // 执行屏蔽逻辑
    if (shouldBlock) {
        // 跳转前验证是否已经在目标网站(防止循环跳转)
        if (!/^www\.baidu\.com$/i.test(currentHost)) {
            window.location.replace('https://www.baidu.com/');
        }
    }
})();