VS Code Web: line-count badge on the active tab
Pins a small badge with the line count of the current file onto the active tab (works on github.dev too).
Code to copy
/* 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 });
})();
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Paste the code into the rule's JavaScript panel and save — it runs on every page visit.
Rate this example
No ratings yet — be the first.