Quizlet MCQ Explanation Blur (toggle with ;)

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.

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Quizlet MCQ Explanation Blur (toggle with ;)
// @namespace    http://tampermonkey.net/
// @version      1.6
// @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.
// @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
    window.addEventListener('keydown', function(e) {
        if (e.key === ';' && !e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) {
            e.preventDefault();
            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;
                }
            });
        }
    });
})();