Skip to content

Commit 00ec7d8

Browse files
Merge pull request #721 from 2222k3060/patch-6
Create Diary_Writing.html
2 parents c5eea1d + e5f0bbc commit 00ec7d8

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

Diary_Writing.html

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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>My Digital Diary</title>
7+
<style>
8+
* {
9+
margin: 0;
10+
padding: 0;
11+
box-sizing: border-box;
12+
font-family: Arial, sans-serif;
13+
}
14+
15+
body {
16+
background-color: #f4f4f4;
17+
display: flex;
18+
justify-content: center;
19+
align-items: center;
20+
height: 100vh;
21+
}
22+
23+
.container {
24+
background-color: white;
25+
padding: 20px;
26+
width: 400px;
27+
border-radius: 10px;
28+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
29+
}
30+
31+
h1, h2 {
32+
text-align: center;
33+
color: #333;
34+
}
35+
36+
.diary-input {
37+
margin-bottom: 20px;
38+
}
39+
40+
textarea {
41+
width: 100%;
42+
height: 100px;
43+
padding: 10px;
44+
margin-bottom: 10px;
45+
border: 1px solid #ccc;
46+
border-radius: 5px;
47+
}
48+
49+
button {
50+
display: block;
51+
width: 100%;
52+
padding: 10px;
53+
background-color: #28a745;
54+
color: white;
55+
border: none;
56+
border-radius: 5px;
57+
cursor: pointer;
58+
}
59+
60+
button:hover {
61+
background-color: #218838;
62+
}
63+
64+
#diaryList {
65+
max-height: 300px;
66+
overflow-y: auto;
67+
}
68+
69+
.diary-entry {
70+
background-color: #e9ecef;
71+
padding: 10px;
72+
margin-bottom: 10px;
73+
border-radius: 5px;
74+
}
75+
</style>
76+
</head>
77+
<body>
78+
<div class="container">
79+
<h1>My Digital Diary</h1>
80+
81+
<div class="diary-input">
82+
<textarea id="diaryEntry" placeholder="Write about your day..."></textarea>
83+
<button id="saveBtn">Save Entry</button>
84+
</div>
85+
86+
<h2>Your Diary Entries</h2>
87+
<div id="diaryList">
88+
<!-- Diary entries will be displayed here -->
89+
</div>
90+
</div>
91+
92+
<script>
93+
document.getElementById('saveBtn').addEventListener('click', function() {
94+
const entry = document.getElementById('diaryEntry').value;
95+
96+
if (entry.trim()) {
97+
const diaryList = document.getElementById('diaryList');
98+
99+
// Create a new diary entry div
100+
const entryDiv = document.createElement('div');
101+
entryDiv.classList.add('diary-entry');
102+
103+
// Get the current date
104+
const date = new Date();
105+
const dateStr = `${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}`;
106+
107+
// Append date and entry text
108+
entryDiv.innerHTML = `<strong>${dateStr}</strong><br>${entry}`;
109+
110+
// Add the new entry to the diary list
111+
diaryList.prepend(entryDiv);
112+
113+
// Clear the textarea
114+
document.getElementById('diaryEntry').value = '';
115+
116+
// Store the entry in localStorage
117+
saveEntry(dateStr, entry);
118+
}
119+
});
120+
121+
function saveEntry(date, entry) {
122+
let diaryEntries = JSON.parse(localStorage.getItem('diaryEntries')) || [];
123+
diaryEntries.push({ date, entry });
124+
localStorage.setItem('diaryEntries', JSON.stringify(diaryEntries));
125+
}
126+
127+
// Load diary entries on page load
128+
window.addEventListener('load', function() {
129+
let diaryEntries = JSON.parse(localStorage.getItem('diaryEntries')) || [];
130+
diaryEntries.forEach(entry => {
131+
const diaryList = document.getElementById('diaryList');
132+
const entryDiv = document.createElement('div');
133+
entryDiv.classList.add('diary-entry');
134+
entryDiv.innerHTML = `<strong>${entry.date}</strong><br>${entry.entry}`;
135+
diaryList.prepend(entryDiv);
136+
});
137+
});
138+
</script>
139+
</body>
140+
</html>

0 commit comments

Comments
 (0)