← All examples

JavaScript Developer & QA vscode.dev

VS Code Web: sticky line-count badge

Shows a fixed corner badge with the line count of the active file (works on github.dev too).

Code to copy

/* Sticky badge on the editor toolbar showing total line count (works on github.dev too) */
(function () {
  if (document.getElementById('vsc-line-badge')) return;
  const badge = document.createElement('div');
  badge.id = 'vsc-line-badge';
  Object.assign(badge.style, {
    position: 'fixed', right: '20px', top: '60px', zIndex: 99999,
    padding: '4px 10px', background: '#1f2328', color: '#7ee787',
    borderRadius: '12px', fontFamily: 'ui-monospace, monospace',
    fontSize: '11px', boxShadow: '0 2px 6px rgba(0,0,0,0.3)',
    pointerEvents: 'none'
  });
  document.body.appendChild(badge);
  const update = () => {
    const lines = document.querySelectorAll('.monaco-editor .view-line').length;
    badge.textContent = lines + ' lines';
    badge.style.display = lines ? '' : 'none';
  };
  update();
  new MutationObserver(update).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