Wanikani Mistake Delay

Adds a delay after wrong answers to prevent double-tapping <enter>

当前为 2017-10-17 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Wanikani Mistake Delay
// @namespace   wkmistakedelay
// @description Adds a delay after wrong answers to prevent double-tapping <enter>
// @include     https://www.wanikani.com/review/session*
// @include     https://www.wanikani.com/lesson/session*
// @version     2.0.0
// @author      Robin Findley
// @copyright   2017+, Robin Findley
// @license     MIT; http://opensource.org/licenses/MIT
// @run-at      document-end
// @grant       none
// ==/UserScript==

window.wkmistakedelay = {};

(function(gobj) {

    // The amount of time to disable 2nd <enter> after a mistake (in milliseconds).
    var DELAY_PERIOD = 2000;

    var old_submit_handler, old_answer_checker, ignore_submit = false;

    function new_answer_checker() {
        // Call the original answer checker.
        var result = old_answer_checker.apply(this, arguments);

        // If we didn't pass,
        if (!result.passed) {
            ignore_submit = true;
            setTimeout(function() {
                ignore_submit = false;
                $('#user-response').attr('disabled','disabled');
            }, DELAY_PERIOD);
        }
        return result;
    }

    function new_submit_handler(e) {
        if (ignore_submit) return false;
        return old_submit_handler.apply(this, arguments);
    }

    function startup() {
        // Check if we can intercept the submit button handler.
        try {
            old_submit_handler = $._data( $('#answer-form button')[0], 'events').click[0].handler;
            old_answer_checker = answerChecker.evaluate;
        } catch(err) {
        }
        if (typeof old_submit_handler !== 'function' || typeof old_answer_checker !== 'function') {
            alert('Wanikani Mistake Delay script is not working.');
            return;
        }

        // Replace the handlers.
        $._data( $('#answer-form button')[0], 'events').click[0].handler = new_submit_handler;
        answerChecker.evaluate = new_answer_checker;
    }

    // Run startup() after window.onload event.
    if (document.readyState === 'complete')
        startup();
    else
        window.addEventListener("load", startup, false);

})(window.wkselfstudy);