-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.html
95 lines (70 loc) · 3.1 KB
/
profile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="downloadButton">Download Local Storage Data as JSON</button>
<button id="downloadButton2">Download currentCardAll Data as JSON</button>
<script>
document.getElementById("downloadButton").addEventListener("click", downloadLocalStorageData);
function downloadLocalStorageData() {
// Check if the variable exists in local storage
if (localStorage.getItem("answeredCardsAll") === null) {
alert("The variable does not exist in local storage.");
return;
}
// Retrieve the variable from local storage
const yourVariable = JSON.parse(localStorage.getItem("answeredCardsAll"));
// Convert the variable to a JSON string
const jsonData = JSON.stringify(yourVariable, null, 2); // The 2 is for pretty formatting, you can change it to 0 for compact format
// Create a Blob with the JSON data
const blob = new Blob([jsonData], { type: "application/json" });
// Create a URL for the Blob
const url = URL.createObjectURL(blob);
// Create a temporary link and set its properties
const link = document.createElement("a");
link.href = url;
link.download = "data.json"; // Set the filename for the downloaded file
// Append the link to the document and click it programmatically to trigger the download
document.body.appendChild(link);
link.click();
// Remove the temporary link from the document
document.body.removeChild(link);
// Release the URL object
URL.revokeObjectURL(url);
}
</script>
<script>
document.getElementById("downloadButton2").addEventListener("click", downloadLocalStorageData2);
function downloadLocalStorageData2() {
// Check if the variable exists in local storage
if (localStorage.getItem("currentCardAll") === null) {
alert("The variable does not exist in local storage.");
return;
}
// Retrieve the variable from local storage
const yourVariable = JSON.parse(localStorage.getItem("currentCardAll"));
// Convert the variable to a JSON string
const jsonData = JSON.stringify(yourVariable, null, 2); // The 2 is for pretty formatting, you can change it to 0 for compact format
// Create a Blob with the JSON data
const blob = new Blob([jsonData], { type: "application/json" });
// Create a URL for the Blob
const url = URL.createObjectURL(blob);
// Create a temporary link and set its properties
const link = document.createElement("a");
link.href = url;
link.download = "data.json"; // Set the filename for the downloaded file
// Append the link to the document and click it programmatically to trigger the download
document.body.appendChild(link);
link.click();
// Remove the temporary link from the document
document.body.removeChild(link);
// Release the URL object
URL.revokeObjectURL(url);
}
</script>
</body>
</html>