Spaces:
Runtime error
Runtime error
office-365
commited on
Commit
•
62e75c2
1
Parent(s):
35587cb
Create link.html
Browse files
link.html
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Edit and Save Text</title>
|
7 |
+
</head>
|
8 |
+
<body>
|
9 |
+
<h1>Edit and Save Text to JSONBlob</h1>
|
10 |
+
|
11 |
+
<textarea id="textEditor" rows="20" cols="80"></textarea>
|
12 |
+
<br>
|
13 |
+
<button onclick="saveText()">Save</button>
|
14 |
+
|
15 |
+
<script>
|
16 |
+
const jsonBlobUrl = 'https://jsonblob.com/api/jsonBlob/5226571730043f8b22dadc20';
|
17 |
+
|
18 |
+
// Function to fetch and display the current text from the JSONBlob
|
19 |
+
async function loadText() {
|
20 |
+
try {
|
21 |
+
const response = await fetch(jsonBlobUrl);
|
22 |
+
const data = await response.json();
|
23 |
+
document.getElementById('textEditor').value = data.text || '';
|
24 |
+
} catch (error) {
|
25 |
+
console.error('Error fetching the text:', error);
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
// Function to save the edited text back to the JSONBlob
|
30 |
+
async function saveText() {
|
31 |
+
const newText = document.getElementById('textEditor').value;
|
32 |
+
const updatedData = { text: newText };
|
33 |
+
|
34 |
+
try {
|
35 |
+
const response = await fetch(jsonBlobUrl, {
|
36 |
+
method: 'PUT',
|
37 |
+
headers: {
|
38 |
+
'Content-Type': 'application/json'
|
39 |
+
},
|
40 |
+
body: JSON.stringify(updatedData)
|
41 |
+
});
|
42 |
+
|
43 |
+
if (response.ok) {
|
44 |
+
alert('Text successfully saved!');
|
45 |
+
} else {
|
46 |
+
alert('Failed to save text. Please try again.');
|
47 |
+
}
|
48 |
+
} catch (error) {
|
49 |
+
console.error('Error saving the text:', error);
|
50 |
+
}
|
51 |
+
}
|
52 |
+
|
53 |
+
// Load the text when the page is loaded
|
54 |
+
window.onload = loadText;
|
55 |
+
</script>
|
56 |
+
</body>
|
57 |
+
</html>
|