Spaces:
Runtime error
Runtime error
LE Quoc Dat
commited on
Commit
·
06b9685
1
Parent(s):
99e180d
##
Browse files- templates/index.html +33 -3
templates/index.html
CHANGED
@@ -56,6 +56,7 @@
|
|
56 |
<a href="#" id="add-to-collection-option">Add to Collection (0)</a>
|
57 |
<a href="#" id="clear-collection-option">Clear Collection</a>
|
58 |
<a href="#" id="export-csv-option" style="display: none;">Export Flashcards to CSV</a>
|
|
|
59 |
</div>
|
60 |
</div>
|
61 |
<div id="recent-files">
|
@@ -492,7 +493,7 @@
|
|
492 |
}
|
493 |
} catch (error) {
|
494 |
console.error('Error calling LLM API:', error);
|
495 |
-
alert(`Failed to generate ${mode === 'flashcard' ? 'flashcards' : 'explanation'}. Please check your API key and try again.`);
|
496 |
} finally {
|
497 |
setTimeout(() => {
|
498 |
document.body.removeChild(notification);
|
@@ -657,9 +658,16 @@
|
|
657 |
});
|
658 |
|
659 |
function updateExportButtonVisibility() {
|
660 |
-
var
|
|
|
661 |
var currentCollection = mode === 'language' ? collectedLanguageFlashcards : collectedFlashcards;
|
662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
663 |
}
|
664 |
|
665 |
function exportToCSV() {
|
@@ -687,11 +695,29 @@
|
|
687 |
document.body.removeChild(link);
|
688 |
}
|
689 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
document.getElementById('export-csv-option').addEventListener('click', function(e) {
|
691 |
e.preventDefault();
|
692 |
exportToCSV();
|
693 |
});
|
694 |
|
|
|
|
|
|
|
|
|
|
|
695 |
function clearCollection() {
|
696 |
if (confirm('Are you sure you want to clear the entire collection? This action cannot be undone.')) {
|
697 |
if (mode === 'language') {
|
@@ -1375,6 +1401,10 @@
|
|
1375 |
e.preventDefault();
|
1376 |
exportToCSV();
|
1377 |
});
|
|
|
|
|
|
|
|
|
1378 |
});
|
1379 |
</script>
|
1380 |
</body>
|
|
|
56 |
<a href="#" id="add-to-collection-option">Add to Collection (0)</a>
|
57 |
<a href="#" id="clear-collection-option">Clear Collection</a>
|
58 |
<a href="#" id="export-csv-option" style="display: none;">Export Flashcards to CSV</a>
|
59 |
+
<a href="#" id="export-json-option" style="display: none;">Export Flashcards to JSON</a>
|
60 |
</div>
|
61 |
</div>
|
62 |
<div id="recent-files">
|
|
|
493 |
}
|
494 |
} catch (error) {
|
495 |
console.error('Error calling LLM API:', error);
|
496 |
+
alert(`Failed to generate ${mode === 'flashcard' ? 'flashcards' : 'an explanation'}. Please check your API key and try again.`);
|
497 |
} finally {
|
498 |
setTimeout(() => {
|
499 |
document.body.removeChild(notification);
|
|
|
658 |
});
|
659 |
|
660 |
function updateExportButtonVisibility() {
|
661 |
+
var csvExportOption = document.getElementById('export-csv-option');
|
662 |
+
var jsonExportOption = document.getElementById('export-json-option');
|
663 |
var currentCollection = mode === 'language' ? collectedLanguageFlashcards : collectedFlashcards;
|
664 |
+
var count = currentCollection.length;
|
665 |
+
|
666 |
+
csvExportOption.style.display = count > 0 ? 'block' : 'none';
|
667 |
+
csvExportOption.textContent = `Export Flashcards to CSV (${count})`;
|
668 |
+
|
669 |
+
jsonExportOption.style.display = count > 0 ? 'block' : 'none';
|
670 |
+
jsonExportOption.textContent = `Export Flashcards to JSON (${count})`;
|
671 |
}
|
672 |
|
673 |
function exportToCSV() {
|
|
|
695 |
document.body.removeChild(link);
|
696 |
}
|
697 |
|
698 |
+
// New function: Export flashcards as JSON
|
699 |
+
function exportToJSON() {
|
700 |
+
const currentCollection = mode === 'language' ? collectedLanguageFlashcards : collectedFlashcards;
|
701 |
+
const dataStr = JSON.stringify(currentCollection, null, 2);
|
702 |
+
const jsonContent = "data:text/json;charset=utf-8," + encodeURIComponent(dataStr);
|
703 |
+
const link = document.createElement("a");
|
704 |
+
link.setAttribute("href", jsonContent);
|
705 |
+
link.setAttribute("download", `${mode}_flashcards.json`);
|
706 |
+
document.body.appendChild(link);
|
707 |
+
link.click();
|
708 |
+
document.body.removeChild(link);
|
709 |
+
}
|
710 |
+
|
711 |
document.getElementById('export-csv-option').addEventListener('click', function(e) {
|
712 |
e.preventDefault();
|
713 |
exportToCSV();
|
714 |
});
|
715 |
|
716 |
+
document.getElementById('export-json-option').addEventListener('click', function(e) {
|
717 |
+
e.preventDefault();
|
718 |
+
exportToJSON();
|
719 |
+
});
|
720 |
+
|
721 |
function clearCollection() {
|
722 |
if (confirm('Are you sure you want to clear the entire collection? This action cannot be undone.')) {
|
723 |
if (mode === 'language') {
|
|
|
1401 |
e.preventDefault();
|
1402 |
exportToCSV();
|
1403 |
});
|
1404 |
+
document.getElementById('export-json-option').addEventListener('click', function(e) {
|
1405 |
+
e.preventDefault();
|
1406 |
+
exportToJSON();
|
1407 |
+
});
|
1408 |
});
|
1409 |
</script>
|
1410 |
</body>
|