Disable Enter on Wrong Answer

Blocks proceeding with the enter key when getting an answer wrong.

当前为 2022-04-18 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Disable Enter on Wrong Answer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Blocks proceeding with the enter key when getting an answer wrong.
// @author       panda-byte
// @license      MIT
// @match        https://www.kaniwani.com/*
// @icon         https://www.google.com/s2/favicons?domain=kaniwani.com
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    let inReviewSession = false;
    let box = null;
    const red = 'rgb(226, 50, 91)';

    window.addEventListener('keydown', event => {
        if (event.key === 'Enter' && inReviewSession && box !== null
                && window.getComputedStyle(box).backgroundColor
                   === red) {
            event.stopPropagation();
        }
    }, true);

    // check if user entered review session
    setInterval(() => {
        const hasSessionStarted = document.URL.endsWith('/reviews/session');

        if (hasSessionStarted === inReviewSession) return;

        if (hasSessionStarted) {
            // try to find answer element
            const findAnswerElementInterval = setInterval(() => {
                const answer = document.getElementById('answer');

                if (answer === null) return;

                clearInterval(findAnswerElementInterval);
                box = answer.parentElement;
            }, 100);
        } else {
            box = null;
        }

        inReviewSession = hasSessionStarted;
    }, 200);
})();