← All examples

JavaScript Productivity scholar.google.com

Scholar: one-click Copy BibTeX

Adds a button in the Cite popup that fetches the BibTeX entry and copies it straight to the clipboard without opening another tab.

Code to copy

// Rewrite the "Cite" popup so BibTeX copies to the clipboard with one click
(function () {
  function watch() {
    document.querySelectorAll('div#gs_citd, div.gs_citi, div.gs_citr').forEach(function (popup) {
      if (popup.dataset.jzSchBib) { return; }
      var bibLink = popup.querySelector('a[href*="output=bibtex"], a[href*="scisig=bibtex"], a[href*="q=info"][href*="bibtex"]');
      if (!bibLink) { return; }
      popup.dataset.jzSchBib = '1';
      var btn = document.createElement('button');
      btn.type = 'button';
      btn.textContent = 'Copy BibTeX';
      btn.style.cssText = 'margin:8px 4px;padding:6px 14px;background:#1a73e8;color:#fff;border:0;border-radius:4px;font-size:14px;font-weight:600;cursor:pointer;';
      btn.addEventListener('click', function (e) {
        e.preventDefault();
        fetch(bibLink.href, { credentials: 'include' })
          .then(function (r) { return r.text(); })
          .then(function (html) {
            var m = html.match(/@\w+\{[\s\S]*?\n\}/);
            var bibtex = m ? m[0] : html.replace(/<[^>]+>/g, '').trim();
            return navigator.clipboard.writeText(bibtex);
          })
          .then(function () {
            btn.textContent = 'Copied!';
            setTimeout(function () { btn.textContent = 'Copy BibTeX'; }, 1500);
          })
          .catch(function () { btn.textContent = 'Failed'; });
      });
      popup.insertBefore(btn, popup.firstChild);
    });
  }
  new MutationObserver(watch).observe(document.body, { childList: true, subtree: true });
  watch();
})();

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