← All examples

JavaScript Developer & QA google.com

Google: show result rank and domain

Appends a small label with the rank number and domain to each title, handy for quick SEO analysis.

Code to copy

// Label each organic result with its host and rank for SEO checks
function labelResults() {
  let rank = 0;
  document.querySelectorAll('#search a > h3').forEach(function (h) {
    const a = h.closest('a');
    if (!a || a.dataset.jzRank) { return; }
    rank += 1;
    a.dataset.jzRank = rank;
    let host = '';
    try { host = new URL(a.href).hostname.replace(/^www\./, ''); }
    catch (e) {}
    const tag = document.createElement('span');
    tag.textContent = '#' + rank + ' ' + host;
    tag.style.cssText = 'display:inline-block;margin-left:8px;'
      + 'font:11px/1.4 monospace;color:#5f6368;background:#f1f3f4;'
      + 'padding:1px 6px;border-radius:4px;vertical-align:middle';
    h.appendChild(tag);
  });
}
labelResults();
const obs = new MutationObserver(labelResults);
obs.observe(document.documentElement, { 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