From 2951f96f34ab1532db0fba9f32f7d4305e9d5bc6 Mon Sep 17 00:00:00 2001 From: hungriesthippo <76754485+hungriesthippo@users.noreply.github.com> Date: Thu, 18 Feb 2021 11:16:11 -0500 Subject: [PATCH 1/4] Update stable.js allow custom methods for showing card and answer #17 --- js/stable.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/js/stable.js b/js/stable.js index 49d241c..3e87753 100644 --- a/js/stable.js +++ b/js/stable.js @@ -539,6 +539,10 @@ roamsr.goToCurrentCard = async () => { await roamsr.sleep(50); roamsr.addContainer(); roamsr.addShowAnswerButton(); + if (typeof window.roamsrUserSettings.onShowCard === "function") { + window.roamsrUserSettings.onShowCard(roamsr.getCurrentCard()); + // TODO: receive signal from this function while the card is still active + } } await doStuff(); @@ -728,13 +732,22 @@ 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); }; +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 +884,7 @@ roamsr.processKey = (e) => { } if (e.code == "Space") { - roamsr.showAnswerAndCloze(false); roamsr.addResponseButtons(); + roamsr.requestAnswer(); return; } From b98dab321a1fde07ee9f763d537cf9ffaae01847 Mon Sep 17 00:00:00 2001 From: hungriesthippo <76754485+hungriesthippo@users.noreply.github.com> Date: Thu, 18 Feb 2021 11:47:34 -0500 Subject: [PATCH 2/4] onShowCard: after doStuff --- js/stable.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/stable.js b/js/stable.js index 3e87753..e2a5782 100644 --- a/js/stable.js +++ b/js/stable.js @@ -539,10 +539,6 @@ roamsr.goToCurrentCard = async () => { await roamsr.sleep(50); roamsr.addContainer(); roamsr.addShowAnswerButton(); - if (typeof window.roamsrUserSettings.onShowCard === "function") { - window.roamsrUserSettings.onShowCard(roamsr.getCurrentCard()); - // TODO: receive signal from this function while the card is still active - } } await doStuff(); @@ -551,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(); From f0b8564af9a62d9b207bd4c737fbc4c3dd0a5ff3 Mon Sep 17 00:00:00 2001 From: hungriesthippo <76754485+hungriesthippo@users.noreply.github.com> Date: Fri, 26 Feb 2021 19:01:31 -0500 Subject: [PATCH 3/4] Add custom buttons on card show --- js/stable.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/js/stable.js b/js/stable.js index e2a5782..8bf16a1 100644 --- a/js/stable.js +++ b/js/stable.js @@ -737,6 +737,23 @@ roamsr.addShowAnswerButton = () => { 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 + }); + extraButton.style.cssText = "margin: 5px"; + responseArea.append(extraButton); + } + } }; roamsr.requestAnswer = () => { From 8a9997045ac5959b94ddc3f31515fa2f679857de Mon Sep 17 00:00:00 2001 From: hungriesthippo <76754485+hungriesthippo@users.noreply.github.com> Date: Fri, 26 Feb 2021 19:04:21 -0500 Subject: [PATCH 4/4] [extra buttons] Pass card to click fn --- js/stable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/stable.js b/js/stable.js index 8bf16a1..b0b432c 100644 --- a/js/stable.js +++ b/js/stable.js @@ -748,7 +748,7 @@ roamsr.addShowAnswerButton = () => { const extraButton = Object.assign(document.createElement("button"), { className: "bp3-button", innerHTML: button.text, - onclick: button.onClick + onclick: () => button.onClick(card) }); extraButton.style.cssText = "margin: 5px"; responseArea.append(extraButton);