← All examples

JavaScript Reading & focus quora.com

Quora: focus on a single answer

Dims every answer except the one under the cursor, making it easier to focus on one at a time.

Code to copy

// Focus mode: dim every answer except the one under the cursor
function setupFocus() {
  document.querySelectorAll('div[class*="puppeteer_test_answer_content"]').forEach(function (a) {
    if (a.dataset.jzFocus) { return; }
    a.dataset.jzFocus = '1';
    const wrap = a.closest('[class*="q-box"]') || a;
    wrap.style.transition = 'opacity 0.2s ease';
    wrap.addEventListener('mouseenter', function () {
      document.querySelectorAll('div[class*="puppeteer_test_answer_content"]').forEach(function (o) {
        const ow = o.closest('[class*="q-box"]') || o;
        ow.style.opacity = (ow === wrap) ? '1' : '0.3';
      });
    });
  });
  document.addEventListener('mouseleave', function () {
    document.querySelectorAll('div[class*="puppeteer_test_answer_content"]').forEach(function (o) {
      const ow = o.closest('[class*="q-box"]') || o;
      ow.style.opacity = '1';
    });
  });
}
setupFocus();
const obs = new MutationObserver(setupFocus);
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