页面内控制台面板
捕获所有 console 调用,并在页面角落的可滚动面板中显示。
可复制的代码
try {
const panel = document.createElement('pre');
panel.style.cssText = 'position:fixed;right:0;bottom:0;width:340px;max-height:240px;'
+ 'overflow:auto;z-index:99999;background:#1d2021;color:#a9b665;margin:0;'
+ 'font:11px monospace;padding:6px;border-top-left-radius:6px;';
document.body.appendChild(panel);
['log', 'warn', 'error', 'info'].forEach(function (level) {
const orig = console[level];
console[level] = function () {
const line = document.createElement('div');
line.textContent = '[' + level + '] '
+ Array.prototype.map.call(arguments, String).join(' ');
panel.appendChild(line);
panel.scrollTop = panel.scrollHeight;
orig.apply(console, arguments);
};
});
} catch (err) { console.error('JustZix console panel:', err); }
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。