// ==UserScript== // @name Bunpro: Mistake Delay // @namespace http://tampermonkey.net/ // @version 0.2.1 // @description Prevents premature wrong answer submission. // @author Kumirei // @include *bunpro.jp* // @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012 // @require https://greasyfork.org/scripts/370623-bunpro-helpful-events/code/Bunpro:%20Helpful%20Events.js?version=615700 // @grant none // @downloadURL none // ==/UserScript== (function() { // Seconds of delay const delay = 2; // Wait until we're reviewing $('HTML')[0].addEventListener('quiz-page', function() { // Add the standard styling to the disabled button addCSS(); // Do stuff when we press enter or backspace $('#study-answer-input').on('keydown', function(event) { var elem = $('#study-answer-input'); // 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)" && !$('#submit-study-answer-disabled').length) { enableDelay(); setTimeout(function(){ disableDelay(); }, delay*1000); } // Cancel delay if we press backspace after getting an answer wrong else if (event.which == 8 && $('#submit-study-answer-disabled').length) disableDelay(); }); }); // Makes user unable to continue to the next item function enableDelay() { $('#study-answer-input')[0].blur(); $('#submit-study-answer').attr('id', 'submit-study-answer-disabled'); } // Makes user able to continue to the next item again function disableDelay() { $('#submit-study-answer-disabled').attr('id', 'submit-study-answer'); } // Adds the needed CSS function addCSS() { $('head').append('') } })();