控制台EZ

用于在环境严重受限(如手机) 或 有较强 Anti-DevTools 的网站使用

目前为 2023-11-15 提交的版本。查看 最新版本

// ==UserScript==
// @name:zh-CN  控制台EZ
// @name        EZ Console
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @license     MPL-2.0
// @grant       GM_registerMenuCommand
// @grant       GM_unregisterMenuCommand
// @grant       GM_addElement
// @version     0.4.1
// @author      -
// @description:zh-cn 用于在环境严重受限(如手机) 或 有较强 Anti-DevTools 的网站使用
// @description:en -
// @description this script may be useful when your DevTools are disabled.
// ==/UserScript==

const evaler = sandbox => code => {
    with (sandbox)
        try {eval(code);}
        catch(e) {console.error(e);}
};


(() => {
    'use strict';

    const rereg = (() => {
        const cap = GM_registerMenuCommand("Test", Function.prototype, {id: '123'});
        GM_unregisterMenuCommand(cap);
        return "123" == cap;
    })() ? GM_registerMenuCommand : ((cap, cb, options) => {
        GM_unregisterMenuCommand(options.id);
        return GM_registerMenuCommand(cap, cb);
    });

    const proxi = (obj, props) => new Proxy(obj, {
        get: (o, p) => {
            if (p in props) return props[p];
            return o[p];
        }
    });

    let div_;

    const umain = () => (div_?.remove(), x = rereg("开启控制台 Open console", main, {id: x}));

    let x = GM_registerMenuCommand("控制台 EZ Console", main);

    function main() {
        x = rereg("关闭控制台 Close console", umain, {id: x});

        const div = GM_addElement("div", {
            style: "left: 0px;position: fixed; top: 0px;z-index: 9999; display:flex; flex-direction: column; width: 30vw;"
        });
        const ipt = GM_addElement(div, "input", {
            style: "border: solid;flex: 0 0 auto;"
        });
        const ppt = GM_addElement(div, "textarea", {style: "flex: 1 0 auto;"});
        const log = (...args) => (args.forEach(t => ppt.value += t), ppt.value += "\n");
        const eval2 = evaler({
            console: proxi(console, {
                log,
                warn: (...args) => log("[WARN] ", ...args),
                error: (...args) => log("[ERR] ", ...args),
                clear: () => ppt.value = "",
            })
        });
        ipt.addEventListener("keypress", e => {
            if (e.key === "Enter") {
                let t = ipt.value;
                eval2(t);
                ipt.value = "";
            }
        });
        div_ = div;
    }

})();

QingJ © 2025

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