HTTP TO HTTPS with Blacklist

自动将HTTP网页跳转为HTTPS,并支持黑名单功能

// ==UserScript==
// @name         HTTP TO HTTPS with Blacklist
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  自动将HTTP网页跳转为HTTPS,并支持黑名单功能
// @license MIT
// @include      /.*/
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-start
// ==/UserScript==

!function() {
    "use strict";
    const host = location.host;
    const isHttps = location.protocol === "https:";
    
    // 黑名单管理
    const blacklist = (() => {
        const get = () => GM_getValue("blacklist", []);
        const set = list => GM_setValue("blacklist", list);
        return { get, set };
    })();

    // 重定向判断逻辑
    const shouldRedirect = () => 
        !blacklist.get().includes(host) && 
        !isHttps && 
        GM_getValue(host, 1) === 1;

    function redirectToHttps() {
        if (shouldRedirect()) {
            location.href = location.href.replace(/^http/, "https");
        }
    }

    // 菜单命令系统
    const createMenu = () => {
        const isBlacklisted = blacklist.get().includes(host);
        GM_registerMenuCommand(
            `[${host}] ${isBlacklisted ? '移除黑名单' : '加入黑名单'}`,
            () => {
                const newList = isBlacklisted 
                    ? blacklist.get().filter(h => h !== host)
                    : [...new Set([...blacklist.get(), host])];
                blacklist.set(newList);
                alert(isBlacklisted ? '已移出黑名单' : '已加入黑名单');
            }
        );
    };

    redirectToHttps();
    createMenu();
}();

QingJ © 2025

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