215 lines
3.8 KiB
HTML
215 lines
3.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Notes Application</title>
|
|
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background: #f4f6f9;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
.container {
|
|
width: 500px;
|
|
margin: 50px auto;
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
h1 {
|
|
text-align: center;
|
|
color: #333;
|
|
}
|
|
|
|
input {
|
|
padding: 10px;
|
|
margin: 5px 0;
|
|
width: 100%;
|
|
border-radius: 5px;
|
|
border: 1px solid #ccc;
|
|
}
|
|
|
|
button {
|
|
padding: 10px;
|
|
margin: 5px 0;
|
|
border-radius: 5px;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
button {
|
|
background: #007bff;
|
|
color: white;
|
|
cursor: pointer;
|
|
border: none;
|
|
}
|
|
|
|
button:hover {
|
|
background: #0056b3;
|
|
}
|
|
|
|
.upload-btn {
|
|
background: #28a745;
|
|
}
|
|
|
|
.upload-btn:hover {
|
|
background: #1e7e34;
|
|
}
|
|
|
|
ul {
|
|
list-style: none;
|
|
padding: 0;
|
|
}
|
|
|
|
li {
|
|
background: #f1f1f1;
|
|
margin: 5px 0;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
position: relative;
|
|
}
|
|
|
|
.delete-btn {
|
|
background: red;
|
|
color: white;
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
width: auto; /* VERY IMPORTANT */
|
|
}
|
|
|
|
.delete-btn:hover {
|
|
background: darkred;
|
|
}
|
|
|
|
.file-link {
|
|
margin-left: 10px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.section {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
|
|
.note-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
background: #f1f1f1;
|
|
margin: 8px 0;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
.delete-btn {
|
|
background: red;
|
|
color: white;
|
|
border: none;
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
<h1>Notes Application</h1>
|
|
|
|
<div class="section">
|
|
<input id="note" placeholder="Write a note..." />
|
|
<button onclick="addNote()">Add Note</button>
|
|
</div>
|
|
|
|
<ul id="list"></ul>
|
|
|
|
<div class="section">
|
|
<h3>Upload File</h3>
|
|
<input type="file" id="file"/>
|
|
<button class="upload-btn" onclick="uploadFile()">Upload File</button>
|
|
</div>
|
|
|
|
<h3>Files</h3>
|
|
<ul id="files"></ul>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
const API = "http://" + location.hostname + ":3000";
|
|
|
|
async function loadNotes() {
|
|
const res = await fetch(API + "/notes");
|
|
const data = await res.json();
|
|
|
|
document.getElementById("list").innerHTML =
|
|
data.map(n => `
|
|
<li class="note-item">
|
|
<span>${n.text}</span>
|
|
<button class="delete-btn" onclick="deleteNote('${n._id}')">Delete</button>
|
|
</li>
|
|
`).join("");
|
|
}
|
|
|
|
async function deleteNote(id) {
|
|
await fetch(API + "/notes/" + id, { method: "DELETE" });
|
|
loadNotes();
|
|
}
|
|
|
|
async function addNote() {
|
|
const text = document.getElementById("note").value;
|
|
|
|
if (!text) return;
|
|
|
|
await fetch(API + "/notes", {
|
|
method: "POST",
|
|
headers: {"Content-Type": "application/json"},
|
|
body: JSON.stringify({ text })
|
|
});
|
|
|
|
document.getElementById("note").value = "";
|
|
loadNotes();
|
|
}
|
|
|
|
async function uploadFile() {
|
|
const fileInput = document.getElementById("file");
|
|
|
|
if (!fileInput.files[0]) return;
|
|
|
|
const formData = new FormData();
|
|
formData.append("file", fileInput.files[0]);
|
|
|
|
await fetch(API + "/upload", {
|
|
method: "POST",
|
|
body: formData
|
|
});
|
|
|
|
alert("File uploaded successfully");
|
|
loadFiles();
|
|
}
|
|
|
|
async function loadFiles() {
|
|
const res = await fetch(API + "/files");
|
|
const files = await res.json();
|
|
|
|
document.getElementById("files").innerHTML =
|
|
files.map(f => `
|
|
<li>
|
|
${f}
|
|
<a class="file-link" href="http://${location.hostname}:3000/uploads/${f}" target="_blank">Download</a>
|
|
</li>
|
|
`).join("");
|
|
}
|
|
|
|
loadNotes();
|
|
loadFiles();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|