Greasy Fork is available in English.
this script may be useful when your DevTools are disabled.
当前为
// ==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];
}
});
}
})();