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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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;
                }
            });
        }
    });
})();