Greasy Fork

Greasy Fork is available in English.

控制台EZ

this script may be useful when your DevTools are disabled.

当前为 2023-11-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name:zh-CN  控制台EZ
// @name        EZ Console
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @license     AGPL-3.0-or-later
// @grant       GM_registerMenuCommand
// @grant       GM_unregisterMenuCommand
// @grant       GM_addElement
// @version     0.4
// @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 inplace = (() => {
        const cap = GM_registerMenuCommand("Test", Function.prototype, {id: '123'});
        GM_unregisterMenuCommand(cap);
        return "123" == cap;
    })();

    const rereg = inplace ? GM_registerMenuCommand : ((cap, cb, options) => {
        GM_unregisterMenuCommand(options.id);
        return GM_registerMenuCommand(cap, cb);
    });

    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;
    }

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

})();