← All examples

JavaScript Developer & QA vscode.dev

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

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. 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.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases