Greasy Fork

Quizlet MCQ Explanation Blur (toggle with ;, blocks auto-advance)

Blurs all text after the first "(" in Quizlet multiple choice options, so you can add explanations or hints without giving away the answer. Press ";" to toggle blur for visible choices and review your notes after choosing. The semicolon key is blocked from triggering auto-advance.

当前为 2025-07-04 提交的版本,查看 最新版本

// ==UserScript==
// @name         Quizlet MCQ Explanation Blur (toggle with ;, blocks auto-advance)
// @namespace    http://tampermonkey.net/
// @version      1.7
// @description  Blurs all text after the first "(" in Quizlet multiple choice options, so you can add explanations or hints without giving away the answer. Press ";" to toggle blur for visible choices and review your notes after choosing. The semicolon key is blocked from triggering auto-advance.
// @author       OpenAI
// @match        *://*.quizlet.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const optionIds = ['option-1','option-2','option-3','option-4'];
    const selector = optionIds.map(id => `[data-testid="${id}"]`).join(',');
    const BLUR_CLASS = 'qz-blur-parentheses';

    // CSS for blurring
    if (!document.getElementById('qz-blur-style')) {
        const style = document.createElement('style');
        style.id = 'qz-blur-style';
        style.textContent = `
            .${BLUR_CLASS} {
                filter: blur(4px) !important;
                user-select: none !important;
            }
        `;
        document.head.appendChild(style);
    }

    function blurAfterFirstParen(el) {
        if (el.dataset.parenthesesBlurred) return;
        el.dataset.parenthesesBlurred = 'true';

        for (const node of Array.from(el.childNodes)) {
            if (node.nodeType === Node.TEXT_NODE && node.textContent.includes('(')) {
                const text = node.textContent;
                const idx = text.indexOf('(');
                if (idx !== -1) {
                    const frag = document.createDocumentFragment();
                    if (idx > 0) {
                        frag.appendChild(document.createTextNode(text.slice(0, idx)));
                    }
                    const span = document.createElement('span');
                    span.textContent = text.slice(idx);
                    span.classList.add(BLUR_CLASS);
                    frag.appendChild(span);
                    el.replaceChild(frag, node);
                }
            } else if (node.nodeType === Node.ELEMENT_NODE) {
                blurAfterFirstParen(node);
            }
        }
    }

    function main() {
        document.querySelectorAll(selector).forEach(blurAfterFirstParen);
    }

    setInterval(main, 500);

    // Semicolon (;) key toggles blur and blocks propagation so Quizlet can't auto-advance
    window.addEventListener('keydown', function(e) {
        if (e.key === ';' && !e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
            e.preventDefault();
            e.stopImmediatePropagation(); // Block Quizlet's listeners
            document.querySelectorAll(`.${BLUR_CLASS}, span[data-qz-blur-unblurred="true"]`).forEach(span => {
                if (span.classList.contains(BLUR_CLASS)) {
                    span.classList.remove(BLUR_CLASS);
                    span.dataset.qzBlurUnblurred = 'true';
                } else {
                    span.classList.add(BLUR_CLASS);
                    delete span.dataset.qzBlurUnblurred;
                }
            });
        }
    }, true); // Use capture to catch event before Quizlet

})();