← All examples

JavaScript Privacy scholar.google.com

Scholar: bypass click-tracking redirects

Rewrites href on result links so they go straight to the paper, skipping the Google redirect and the ping attribute.

Code to copy

// Rewrite result links to bypass Google's click-tracking redirect
(function () {
  function clean(a) {
    if (a.dataset.jzSchClean) { return; }
    var href = a.getAttribute('href') || '';
    var m = href.match(/^\/scholar_url\?url=([^&]+)/);
    if (m) {
      try { a.href = decodeURIComponent(m[1]); } catch (e) { /* ignore */ }
    }
    if (/^https?:\/\/www\.google\.[a-z.]+\/url\?/.test(href)) {
      try {
        var u = new URL(href);
        var real = u.searchParams.get('url') || u.searchParams.get('q');
        if (real) { a.href = real; }
      } catch (e) { /* ignore */ }
    }
    a.dataset.jzSchClean = '1';
    a.removeAttribute('onmousedown');
    a.removeAttribute('ping');
  }
  function scan() {
    document.querySelectorAll('h3.gs_rt a, div.gs_or_ggsm a, div.gs_ri a, div.gs_fl a').forEach(clean);
  }
  scan();
  new MutationObserver(function () {
    clearTimeout(window.__jzSchPriv);
    window.__jzSchPriv = setTimeout(scan, 350);
  }).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