diff options
Diffstat (limited to 'script.js')
| -rw-r--r-- | script.js | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -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); |