diff --git a/js/stable.js b/js/stable.js index 49d241c..b0b432c 100644 --- a/js/stable.js +++ b/js/stable.js @@ -547,6 +547,10 @@ roamsr.goToCurrentCard = async () => { await roamsr.sleep(500); await doStuff(); + if (typeof window.roamsrUserSettings.onShowCard === "function") { + window.roamsrUserSettings.onShowCard(roamsr.getCurrentCard()); + // TODO: receive signal from this function while the card is still active + } window.onhashchange = () => { roamsr.removeContainer(); @@ -728,13 +732,39 @@ roamsr.addShowAnswerButton = () => { var showAnswerAndClozeButton = Object.assign(document.createElement("button"), { className: "bp3-button roamsr-container__response-area__show-answer-button", innerHTML: "Show answer.", - onclick: () => { roamsr.showAnswerAndCloze(false); roamsr.addResponseButtons(); } + onclick: roamsr.requestAnswer }) showAnswerAndClozeButton.style.cssText = "margin: 5px;"; responseArea.append(showAnswerAndClozeButton); + + if (typeof window.roamsrUserSettings.extraButtons === "object") { + for (let i = 0; i < window.roamsrUserSettings.extraButtons.length; i++) { + const button = window.roamsrUserSettings.extraButtons[i]; + const card = roamsr.getCurrentCard(); + if (!button.onShow) continue; + if (button.hasOwnProperty('decks') && card.decks.findIndex(deck => button.decks.includes(deck)) === -1) + continue; + const extraButton = Object.assign(document.createElement("button"), { + className: "bp3-button", + innerHTML: button.text, + onclick: () => button.onClick(card) + }); + extraButton.style.cssText = "margin: 5px"; + responseArea.append(extraButton); + } + } }; +roamsr.requestAnswer = () => { + roamsr.showAnswerAndCloze(false); + roamsr.addResponseButtons(); + if (typeof window.roamsrUserSettings.onShowAnswer === "function") { + window.roamsrUserSettings.onShowAnswer(); + // TODO: receive signal from this function while the card is still active + } +} + roamsr.addResponseButtons = () => { var responseArea = roamsr.clearAndGetResponseArea(); @@ -871,7 +901,7 @@ roamsr.processKey = (e) => { } if (e.code == "Space") { - roamsr.showAnswerAndCloze(false); roamsr.addResponseButtons(); + roamsr.requestAnswer(); return; }