← All examples

JavaScript Productivity google.com

Google: collapse knowledge panel to a button

Hides the knowledge panel by default and adds a small button to expand it when needed.

Code to copy

// Collapse the right knowledge panel into a small toggle strip
const ID = 'jz-gsr-kp-toggle';
function setup() {
  const rhs = document.getElementById('rhs');
  if (!rhs || document.getElementById(ID)) { return; }
  rhs.style.display = 'none';
  const btn = document.createElement('button');
  btn.id = ID;
  btn.textContent = 'Show knowledge panel';
  btn.style.cssText = 'margin:8px 0;padding:6px 12px;cursor:pointer;'
    + 'border:1px solid #dadce0;border-radius:18px;background:#fff';
  btn.addEventListener('click', function () {
    const on = rhs.style.display === 'none';
    rhs.style.display = on ? '' : 'none';
    btn.textContent = on ? 'Hide knowledge panel' : 'Show knowledge panel';
  });
  const col = document.getElementById('center_col') || rhs.parentElement;
  col.insertBefore(btn, col.firstChild);
}
setup();
const obs = new MutationObserver(setup);
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