Block Sites and Redirect

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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/');
        }
    }
})();