立刻警戒

一键将该标签页的内容隐藏,并用其他页面伪装。

目前为 2024-08-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         立刻警戒
// @namespace    https://ez118.github.io/
// @version      0.2
// @description  一键将该标签页的内容隐藏,并用其他页面伪装。
// @author       ZZY_WISU
// @match        *://*/*
// @license      GPLv3
// @icon         data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEwLjUgMTNIOHYtM2gyLjVWNy41aDNWMTBIMTZ2M2gtMi41djIuNWgtM3pNMTIgMiA0IDV2Ni4wOWMwIDUuMDUgMy40MSA5Ljc2IDggMTAuOTEgNC41OS0xLjE1IDgtNS44NiA4LTEwLjkxVjV6IiBmaWxsPSIjMWRiNDU5Ij48L3BhdGg+PC9zdmc+
// @run-at       document-end
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_addValueChangeListener
// @grant        window.onurlchange
// @require      https://unpkg.com/[email protected]/dist/jquery.min.js
// ==/UserScript==



/* =====[ 用户自定义 ]===== */
const DICT = [
    {
        "title":"腾讯网-QQ.COM",
        "url":"https://xw.qq.com/"
    },
    {
        "title":"IT之家",
        "url":"https://www.ithome.com/"
    },
    {
        "title":"w3school 在线教程",
        "url":"https://www.w3school.com.cn/"
    },
    {
        "title":"jQuery css() 方法 | 菜鸟教程",
        "url":"https://www.runoob.com/jquery/jquery-css.html"
    },
    {
        "title":"出师表(诸葛亮作品)_百度百科",
        "url":"https://baike.baidu.com/item/%E5%87%BA%E5%B8%88%E8%A1%A8/82086"
    },
    {
        "title":"一九八四(乔治·奥威尔著长篇小说)_百度百科",
        "url":"https://baike.baidu.com/item/%E4%B8%80%E4%B9%9D%E5%85%AB%E5%9B%9B/2672"
    },
    {
        "title":"一网通办",
        "url":"https://zwdt.sh.gov.cn/"
    },
    {
        "title":"哔哩哔哩热门",
        "url":"https://www.bilibili.com/v/popular/all/"
    },
    {
        "title":"网页新闻",
        "url":"https://news.163.com/"
    },
    {
        "title":"精华区 - 博客园",
        "url":"https://www.cnblogs.com/pick/"
    },
    {
        "title":"澎湃新闻",
        "url":"https://www.thepaper.cn/news"
    },
    {
        "title":"36氪 让一部分人先看到未来",
        "url":"https://www.36kr.com/"
    },
];


/* =====[ 变量存储 ]===== */
const ICONS = {
    'safety': '<svg viewBox="0 0 24 24" width="20px" height="20px"><path d="M10.5 13H8v-3h2.5V7.5h3V10H16v3h-2.5v2.5h-3zM12 2 4 5v6.09c0 5.05 3.41 9.76 8 10.91 4.59-1.15 8-5.86 8-10.91V5z" fill="#FFF"></path></svg>'
};

var origTitle = "";



function randomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function showToast(message, duration) {
    duration = duration || 3000;
    var toast = $('<div id="userscript-instantToast"></div>');
    toast.text(message);

    $('body').append(toast);
    toast.fadeIn(100);

    setTimeout(function () {
        toast.fadeOut(100, function () {
            toast.remove();
        });
    }, duration);
}

function showCover() {
    if($("#userscript-superMask").length > 0) { return; }

    var $superMask = $('<iframe>', {
        class: 'userscript-superMask',
        id: 'userscript-superMask',
        style: 'display:none;'
    }).appendTo('body');

    $superMask.show();

    var randIndex = randomInt(1, DICT.length) - 1;
    $superMask.attr("src", DICT[randIndex].url);
    $("title").html(DICT[randIndex].title);
}


function initEle() {
    var $toggleMask = $('<div>', {
        class: 'userscript-toggleMask',
        id: 'userscript-toggleMask',
        'toggle-status': 'idle'
    }).appendTo('body');
    $toggleMask.html(ICONS.safety);


    if(GM_getValue('aid_broadcast').status == 'active') {
        $toggleMask.attr("toggle-status", "active");
        $toggleMask.css("right", "calc(50vw - 30px)");
        origTitle = $("title").html();
        showCover();
    }

    // 添加点击事件监听器
    $toggleMask.click(function(e) {
        if($toggleMask.attr("toggle-status") == 'idle'){
            $toggleMask.attr("toggle-status", "active");
            $toggleMask.css("right", "calc(50vw - 30px)");
            origTitle = $("title").html();
            showCover();
        } else {
            $toggleMask.attr("toggle-status", "idle");
            $toggleMask.css("right", "10px");
            $("title").html(origTitle);
            $("#userscript-superMask").remove();
        }
    });

    $toggleMask.on("contextmenu", function(e) {
        e.preventDefault();

        //alert( JSON.stringify(GM_getValue('aid_broadcast')));
        if(GM_getValue('aid_broadcast').status == 'idle'){
            $toggleMask.attr("toggle-status", "active");
            GM_setValue('aid_broadcast', {"status":"active","url":window.location.href, "type":"cover"});

            showToast("开始警戒", 500);
        } else {
            $toggleMask.attr("toggle-status", "idle");
            GM_setValue('aid_broadcast', {"status":"idle","url":window.location.href, "type":"cover"});

            showToast("警戒取消");
        }
    });
}


(function () {
    'use strict';

    if(window.self !== window.top){ return; }

    /* 初始化 全局脚本广播信息(type可选:cover(遮罩), close(关闭窗口)) */
    if(!GM_getValue('aid_broadcast')){ GM_setValue('aid_broadcast', {"status":"idle","url":"", "type":"cover"}); }


    GM_addStyle(`
        body{ -webkit-appearance:none!important; }

        #userscript-instantToast{ display:none; position:fixed; bottom:40px; left:50%; transform:translateX(-50%); background-color:#333333; color:#FFF; padding:8px 20px; border-radius:5px; z-index:999999; box-shadow:0px 2px 5px #555; }

        .userscript-toggleMask{ position:fixed; bottom:10px; right:10px; z-index:999999; padding:6px; background-color:#3b82f690; height:18px; width:18px; border-radius:15px; opacity:0.9; box-shadow:0 0 5px #3b82f6; line-height:initial; display:inline-block; cursor:pointer; box-sizing:initial; user-select:none; }
        .userscript-toggleMask:hover{ opacity:1; }
        .userscript-toggleMask svg{ height:18px; width:18px; }
        .userscript-superMask{ position:fixed; top:0; left:0; right:0; bottom:0; width:100vw; height:100vh; z-index:999998; background-color:#86b4ff90; backdrop-filter:blur(15px); border:none; padding:none; box-sizing:initial; }
    `);

    initEle();

    setTimeout(()=>{
        if($("#userscript-toggleMask").length == 0){
            /* 如果在页面加载时未完成初始化 */
            initEle();
        }
    }, 1000);

    GM_addValueChangeListener('aid_broadcast', function(name, old_value, new_value, remote) {
        if(!new_value.url || !new_value.type){ return; }

        var $toggleMask = $("#userscript-toggleMask");
        if(new_value.status == "idle"){
            $toggleMask.attr("toggle-status", "idle");
            $toggleMask.css("right", "10px");
            $("title").html(origTitle);
            $("#userscript-superMask").remove();
        } else {
            $toggleMask.attr("toggle-status", "active");
            $toggleMask.css("right", "calc(50vw - 30px)");
            origTitle = $("title").html();
            showCover();
        }
    })

    window.addEventListener('urlchange', (info) => {
        if($("#userscript-toggleMask").length == 0){
            /* 如果在页面加载时未完成初始化 */
            setTimeout(() => {
                initEle();
            }, 1000)
        }
    });
})();