-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
55 lines (50 loc) · 2.01 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Save Chapter</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Save Chapter</h1>
<input type="text" id="bookTitle" placeholder="Book Title" />
<input type="text" id="chapterTitle" placeholder="Chapter Title" />
<textarea id="content" placeholder="Chapter Content" rows="5"></textarea>
<button id="saveButton">Save Chapter</button>
<div id="response" style="margin-top: 10px;"></div>
</div>
<script>
const saveButton = document.getElementById('saveButton');
const responseDiv = document.getElementById('response');
saveButton.addEventListener('click', async () => {
const bookTitle = document.getElementById('bookTitle').value.trim();
const chapterTitle = document.getElementById('chapterTitle').value.trim();
const content = document.getElementById('content').value.trim();
if (!bookTitle || !chapterTitle || !content) {
responseDiv.textContent = "All fields are required.";
return;
}
try {
const res = await fetch('http://localhost:3000/api/save-to-pastebin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('jwtToken')}`, // Retrieve JWT securely
},
body: JSON.stringify({ bookTitle, chapterTitle, content }),
});
const data = await res.json();
if (data.link) {
responseDiv.innerHTML = `<p>Saved! <a href="${data.link}" target="_blank">View it</a></p>`;
} else {
responseDiv.textContent = data.error || "Error saving data.";
}
} catch (err) {
responseDiv.textContent = "An error occurred. Please try again.";
}
});
</script>
</body>
</html>