VS Code Web:活动标签页显示行数徽章
在活动标签页上附加一个显示当前文件行数的小徽章(github.dev 也适用)。
可复制的代码
/* Append the line count of the active editor as a badge on the tab (works on github.dev too) */
(function () {
const update = () => {
const tab = document.querySelector('.monaco-workbench .tabs-container [role="tab"].active .tab-label');
const lineCount = document.querySelectorAll('.monaco-editor .view-line').length;
if (!tab || !lineCount) return;
let badge = tab.querySelector('.vsc-lines-badge');
if (!badge) {
badge = document.createElement('span');
badge.className = 'vsc-lines-badge';
Object.assign(badge.style, {
marginLeft: '6px', padding: '0 5px', borderRadius: '8px',
background: 'rgba(255,138,61,0.25)', color: '#ff8a3d',
fontSize: '10px', fontWeight: '700'
});
tab.appendChild(badge);
}
badge.textContent = lineCount + 'L';
};
update();
const obs = new MutationObserver(update);
obs.observe(document.body, { childList: true, subtree: true });
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。