Skip to content

Instantly share code, notes, and snippets.

@memosiki
Last active November 11, 2021 08:53
Show Gist options
  • Save memosiki/fa02fdda9adc15e63d788274d2456c27 to your computer and use it in GitHub Desktop.
Save memosiki/fa02fdda9adc15e63d788274d2456c27 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Bunpro: Hide Tense
// @namespace http://tampermonkey.net/
// @version 0.0.3
// @description Automatically hides the tense info in the missing phrase area
// @author yndajas
// @include *bunpro.jp/*
// @exclude *community.bunpro.jp*
// @require https://greasyfork.org/scripts/432418-wait-for-selector/code/Wait%20For%20Selector.js?version=974366
// @require https://greasyfork.org/scripts/370623-bunpro-helpful-events/code/Bunpro:%20Helpful%20Events.js?version=974369
// @grant none
// ==/UserScript==
(() => {
// btw works for both reviews and cram sessions
let hintText;
const placeholder = "_________";
// wait until we're reviewing
$('HTML')[0].addEventListener('quiz-page', function () {
$('HTML')[0].addEventListener('new-review-item', function(e) {
// get element
const studyAreaInput = document.getElementsByClassName("study-area-input")[0];
let studyAreaText = studyAreaInput.getAttribute("data-tense");
// event fires multiple times per review item, so we have to make addiional check if hint was already hidden
if (studyAreaText && studyAreaText != placeholder) {
hintText = studyAreaText;
// replace hint attribute
studyAreaInput.setAttribute("data-tense", placeholder);
}
function setHint(event){
if (event.keyCode == 32 && studyAreaInput.getAttribute("data-tense") == placeholder) {
studyAreaInput.setAttribute("data-tense", hintText);
event.stopPropagation();
}
};
// show hint back when we press space without focus on answer
$("body").keydown(setHint);
// show hint back when we press space typing in answer field
$("#study-answer-input").keydown(setHint);
});
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment