-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
305 lines (269 loc) · 9.96 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><rect width='100' height='100' fill='%23e0e0e0' rx='16'/><text x='50%' y='50%' dominant-baseline='central' text-anchor='middle' font-size='85' font-family='Arial' font-weight='bold' fill='%231e1e1e'>白</text></svg>">
<title>Shiro</title>
<style>
body {
margin: 0;
padding: 0;
background: #1e1e1e;
color: #e0e0e0;
font-family: monospace;
font-size: 18px;
display: flex;
flex-direction: column;
height: 100vh;
transition: background 0.5s ease-in-out;
}
.header {
display: flex;
justify-content: space-between;
padding: 18px 20px;
}
.left-controls, .right-controls {
display: flex;
gap: 20px;
}
.main-content {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
.footer {
padding: 18px 20px;
display: flex;
justify-content: space-between;
}
textarea {
width: 65vw;
height: 65vh;
background: transparent;
border: none;
color: #e0e0e0;
outline: none;
resize: none;
font-size: 18px;
line-height: 1.6;
padding: 2.5vh;
user-select: none;
text-align: left;
vertical-align: top;
}
textarea::placeholder {
color: #7f7e7e;
opacity: 1;
}
.light-mode textarea::placeholder {
color: #333;
opacity: 0.5;
}
.icon {
cursor: pointer;
opacity: 0.5;
transition: opacity 0.3s, color 0.3s;
font-size: 14px;
color: #e0e0e0;
}
.light-mode .icon {
color: #333;
}
.icon:hover {
opacity: 1;
}
</style>
</head>
<body>
<div class="header">
<div class="left-controls">
<span id="downloadButton" class="icon">Download</span>
<span id="clearButton" class="icon">Clear</span>
</div>
<div class="right-controls">
<span id="fullscreenButton" class="icon">Fullscreen</span>
<span id="themeButton" class="icon">Light</span>
</div>
</div>
<div class="main-content">
<textarea id="editor" placeholder="Start writing..."></textarea>
</div>
<div class="footer">
<div class="left-controls">
<span id="aboutButton" class="icon">About</span>
</div>
<div class="right-controls">
<span id="wordCountButton" class="icon">0 words</span>
</div>
</div>
<script>
// DOM Elements
const textarea = document.getElementById("editor");
const icons = document.querySelectorAll(".icon");
const downloadButton = document.getElementById("downloadButton");
const clearButton = document.getElementById("clearButton");
const fullscreenButton = document.getElementById("fullscreenButton");
const themeButton = document.getElementById("themeButton");
const aboutButton = document.getElementById("aboutButton");
const wordCountButton = document.getElementById("wordCountButton");
// State Variables
let buttonsHidden = false;
// Utility Functions
const saveText = () => {
localStorage.setItem("shiroSavedText", textarea.value);
};
const loadText = () => {
textarea.value = localStorage.getItem("shiroSavedText") || "";
updateWordCount();
};
const hideIcons = () => {
icons.forEach(icon => icon.style.opacity = "0");
buttonsHidden = true;
};
const showIcons = () => {
icons.forEach(icon => icon.style.opacity = "0.5");
buttonsHidden = false;
};
const generateFilename = () => {
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, "0"); // Months are 0-based
const day = now.getDate().toString().padStart(2, "0");
const hours = now.getHours().toString().padStart(2, "0");
const minutes = now.getMinutes().toString().padStart(2, "0");
return `shiro_${year}-${month}-${day}_${hours}-${minutes}.txt`;
};
const downloadText = () => {
const filename = generateFilename();
const blob = new Blob([textarea.value], { type: "text/plain" });
const a = Object.assign(document.createElement("a"), {
href: URL.createObjectURL(blob),
download: filename
});
a.click();
URL.revokeObjectURL(a.href);
};
const clearText = () => {
textarea.style.transition = "opacity 0.3s";
textarea.style.opacity = "0";
// Fade out, then fade in text
setTimeout(() => {
textarea.value = "";
textarea.style.opacity = "1";
localStorage.removeItem("shiroSavedText");
updateWordCount();
}, 300);
};
const toggleFullscreen = () => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
fullscreenButton.textContent = "Normal";
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
fullscreenButton.textContent = "Fullscreen";
}
}
};
const updateFullscreenButton = () => {
if (!document.fullscreenElement) {
fullscreenButton.textContent = "Fullscreen";
}
};
const applyTheme = () => {
const usingLightMode = document.body.classList.contains("light-mode");
document.body.style.background = usingLightMode ? "#f5f5f5" : "#1e1e1e";
document.body.style.color = usingLightMode ? "#333" : "#e0e0e0";
textarea.style.color = usingLightMode ? "#333" : "#e0e0e0";
// Update button text
themeButton.textContent = usingLightMode ? "Dark" : "Light";
// Update all icons
icons.forEach(icon => {
icon.style.opacity = buttonsHidden ? "0" : "0.5";
});
// Save theme preference
localStorage.setItem("shiroTheme", usingLightMode ? "light" : "dark");
};
const toggleTheme = () => {
document.body.classList.toggle("light-mode");
applyTheme();
};
const openAboutPage = () => {
window.open("https://github.com/vsakkas/shiro", "_blank");
};
const updateWordCount = () => {
const text = textarea.value.trim();
const wordCount = text ? text.split(/\s+/).length : 0;
wordCountButton.textContent = `${wordCount} ${wordCount === 1 ? "word" : "words"}`;
};
// Event Handlers
const setupEventListeners = () => {
// Text area events
textarea.addEventListener("input", () => {
saveText();
hideIcons();
});
// Document events
document.addEventListener("mousemove", () => {
if (buttonsHidden) {
showIcons();
updateWordCount();
}
});
document.addEventListener("fullscreenchange", updateFullscreenButton);
document.body.addEventListener("click", (event) => {
if (!event.target.closest(".icon") && event.target !== textarea) {
textarea.focus(); // Focus on text area even when clicking outside of it
}
});
// Button events - focus on text area after every action
downloadButton.addEventListener("click", () => {
downloadText();
textarea.focus();
});
clearButton.addEventListener("click", () => {
clearText();
textarea.focus();
});
fullscreenButton.addEventListener("click", () => {
toggleFullscreen();
textarea.focus();
});
themeButton.addEventListener("click", () => {
toggleTheme();
textarea.focus();
});
aboutButton.addEventListener("click", () => {
openAboutPage();
textarea.focus();
});
wordCountButton.addEventListener("click", () => {
console.log("Word count clicked"); // Placeholder for word count click function
textarea.focus();
});
// Icon hover effects
icons.forEach(icon => {
icon.addEventListener("mouseenter", () => icon.style.opacity = "1");
icon.addEventListener("mouseleave", () => icon.style.opacity = buttonsHidden ? "0" : "0.5");
});
};
// Initialization
const initializeTheme = () => {
if (localStorage.getItem("shiroTheme") === "light") {
document.body.classList.add("light-mode");
}
applyTheme();
};
const initialize = () => {
initializeTheme();
loadText();
setupEventListeners();
textarea.focus(); // Focus on text area on load
};
// Start the application
window.onload = initialize;
</script>
</body>
</html>