Bunpro: Toggle Tense Tip

Automatically hides the tense tip on review and cram pages - press spacebar to toggle

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Bunpro: Toggle Tense Tip
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  Automatically hides the tense tip on review and cram pages - press spacebar to toggle
// @author       yndajas, durtle9831/memosiki (draft toggle logic)
// @license      MIT
// @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==

(() => {
  const placeholder = "_________";
  let tense;
  let studyAreaInput;
  let currentTenseAttribute;

  const toggleTenseAttribute = () => {
    const newTenseAttribute = (currentTenseAttribute === tense ? placeholder : tense);
    studyAreaInput.setAttribute("data-tense", newTenseAttribute);
    currentTenseAttribute = newTenseAttribute;
  }

  const html = document.getElementsByTagName('HTML')[0];

  // wait until reviewing
  html.addEventListener('quiz-page', () => {
    // wait for new review item
    html.addEventListener('new-review-item', (event) => {
      // get element and current tense attribute
      studyAreaInput = document.getElementsByClassName("study-area-input")[0];
      currentTenseAttribute = studyAreaInput.getAttribute("data-tense");

      // set tense if attribute exists and isn't the placeholder; hide tense inititally
      if (currentTenseAttribute && currentTenseAttribute !== placeholder) {
        tense = currentTenseAttribute;
        toggleTenseAttribute();
      }
    });
  })

  const handleSpaceKey = (event) => {
    if (event.keyCode === 32 && currentTenseAttribute) {
      toggleTenseAttribute();
    }
  }

  // toggle tense on space bar
  const studyAnswerInput = document.getElementById("study-answer-input");
  [html, studyAnswerInput].forEach((element) => {
    element.addEventListener('keydown', handleSpaceKey);
  });
})();