Greasy Fork

Greasy Fork is available in English.

Bunpro: Mistake Delay

Prevents premature wrong answer submission.

当前为 2018-08-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         Bunpro: Mistake Delay
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  Prevents premature wrong answer submission.
// @author       Kumirei
// @include      *bunpro.jp*
// @require      http://greasyfork.icu/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// @require      http://greasyfork.icu/scripts/370623-bunpro-helpful-events/code/Bunpro:%20Helpful%20Events.js?version=615700
// @grant        none
// ==/UserScript==

(function() {
		const delay = 2;  // Seconds of delay

		// Wait until we're reviewing
		$('HTML')[0].addEventListener('quiz-page', function() {
				// Make placeholder look like the answer
				$('head').append('<style>#study-answer-input.delay::placeholder {color: white;}</style>');

				// Do stuff when we press enter or backspace
				$(document).on('keydown', function(event) {
						var elem = $('#study-answer-input');
						var ans = elem[0].value;
						// Initiate delate when we press enter, get the answer wrong, and no delay is already active
						if (event.which == 13 && elem[0].style.background == "rgba(255, 77, 77, 0.8)" && elem[0].placeholder == "Your Answer") {
								startDelay(elem, ans);
								setTimeout(function(){
										cancelDelay(elem, ans);
								}, delay*1000);
						}
						// Cancel delay if we press backspace after getting an answer wrong
						else if (event.which == 8) cancelDelay(elem, ans);
				});
		});

		// Makes user unable to continue to the next item
		function startDelay(elem, ans) {
				elem.addClass('delay');
				elem[0].value = "";
				elem[0].placeholder = ans;
				elem.blur();
		}

		// Makes user able to continue to the next item again
		function cancelDelay(elem, ans) {
				if (elem[0].placeholder != "Your Answer") {
						elem[0].value = ans;
						elem.removeClass('delay');
						elem[0].placeholder = "Your Answer";
				}
		}
})();