From e47dd1eae351aed5a434645ad90d7c4a57f26c85 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Sat, 19 Jul 2025 17:32:35 -0400 Subject: Download JSON with updated scheduler params --- script.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 86874d3..1ff9fbb 100644 --- a/script.js +++ b/script.js @@ -164,7 +164,7 @@ function endReview() { window.flashcard.style.display = "none"; window.buttons.style.display = "none"; updateAllCards(); - console.log(window.allCards); + downloadJSON(window.allCards); } function rateCard(difficulty) { @@ -226,6 +226,32 @@ function updateAllCards() { } } +function downloadJSON(obj) { + // Convert the object to a JSON string (with default formatting) + const jsonString = JSON.stringify(obj, null, 2); // 'null, 2' adds indentation for readability + + // Create a Blob with the JSON content + const blob = new Blob([jsonString], { type: 'application/json' }); + + // Generate a URL for the Blob + const url = URL.createObjectURL(blob); + + // Create an anchor element + const a = document.createElement('a'); + a.href = url; + a.download = 'data.json'; // Default filename + + // Append the anchor to the body (required for some browsers) + document.body.appendChild(a); + + // Simulate a click on the anchor to trigger the download + a.click(); + + // Clean up + document.body.removeChild(a); + URL.revokeObjectURL(url); +} + function today() { let today = new Date(); today.setHours(0, 0, 0, 0); -- cgit v1.3