← All examples

JavaScript Productivity scholar.google.com

Scholar: quick "Last year" filter button

Adds a button next to the search bar that limits results to the last year of publications with a single click.

Code to copy

// Add a quick "Last year" filter button next to the search bar
(function () {
  if (document.getElementById('jzSchLastYear')) { return; }
  function host() {
    return document.querySelector('#gs_ab, #gs_hdr_act, #gs_hdr');
  }
  var h = host();
  if (!h) {
    new MutationObserver(function (m, obs) {
      if (host()) { obs.disconnect(); mount(); }
    }).observe(document.body, { childList: true, subtree: true });
    return;
  }
  mount();
  function mount() {
    var h2 = host();
    if (!h2 || document.getElementById('jzSchLastYear')) { return; }
    var btn = document.createElement('a');
    btn.id = 'jzSchLastYear';
    var y = new Date().getFullYear();
    var params = new URLSearchParams(location.search);
    params.set('as_ylo', String(y - 1));
    params.set('scisbd', '1');
    btn.href = location.pathname + '?' + params.toString();
    btn.textContent = 'Last year';
    btn.style.cssText = 'display:inline-block;margin:6px 10px;padding:6px 14px;background:#1a73e8;color:#fff;font-size:13px;font-weight:700;text-decoration:none;border-radius:4px;';
    h2.appendChild(btn);
  }
})();

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