-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguestbook-idea2.html
More file actions
207 lines (183 loc) · 5.77 KB
/
guestbook-idea2.html
File metadata and controls
207 lines (183 loc) · 5.77 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Guestbook | tools.eliana.lol</title>
<link rel="stylesheet" href="global.css" />
<link rel="icon" type="image/x-icon" href="favicon.svg" />
<style>
/* Specific Tool UI */
.guestbook-ui {
max-width: 600px;
margin: 0 auto;
}
canvas {
border: 2px solid var(--puny);
background: var(--bg);
cursor: crosshair;
touch-action: none;
width: 100%;
aspect-ratio: 1 / 1;
display: block;
margin-top: 15px;
}
.canvas-controls {
display: flex;
gap: 10px;
margin-top: 15px;
justify-content: center;
}
.entry-card {
border: 1px solid var(--puny);
padding: 10px;
background: var(--bg);
}
.entry-card img {
width: 100%;
border: 1px solid var(--puny);
background: white; /* Keep canvas exports readable */
display: block;
margin-bottom: 8px;
}
.past-entries {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
margin-top: 3rem;
}
@media (max-width: 600px) {
.past-entries {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<nav>
<div class="left">
<a href="index.html">home</a> | <a href="extra.html">extra</a> |
<a href="credits.html">credits</a> |
<a href="changelog.html">logs</a>
</div>
<div class="right">
<button id="theme-toggle">[theme]</button> |
<a href="https://eliana.lol">site</a>
</div>
</nav>
<main class="guestbook-ui">
<h1>Sign My Guestbook</h1>
<p class="puny">
Leave a little sketch. It'll stay here (in your browser) for next time.
</p>
<canvas id="canvas" width="500" height="500"></canvas>
<div class="canvas-controls">
<button onclick="clearCanvas()">🗑️ Clear</button>
<button
onclick="saveEntry()"
style="border-color: var(--accent); font-weight: bold"
>
✨ Save Entry
</button>
</div>
<h2 class="section-title">Past Entries</h2>
<div id="entries" class="past-entries"></div>
</main>
<script>
const html = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved =
localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light');
html.setAttribute('data-theme', saved);
if (toggle) toggle.innerText = saved === 'dark' ? '[light]' : '[dark]';
if (toggle) {
toggle.onclick = () => {
const now = html.getAttribute('data-theme');
const next = now === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
toggle.innerText = next === 'dark' ? '[light]' : '[dark]';
};
}
</script>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let isDrawing = false;
function getCoords(e) {
const rect = canvas.getBoundingClientRect();
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
const clientY = e.touches ? e.touches[0].clientY : e.clientY;
return {
x: (clientX - rect.left) * (canvas.width / rect.width),
y: (clientY - rect.top) * (canvas.height / rect.height),
};
}
function startDrawing(e) {
isDrawing = true;
ctx.beginPath();
const { x, y } = getCoords(e);
ctx.moveTo(x, y);
if (e.touches) e.preventDefault();
}
function draw(e) {
if (!isDrawing) return;
const { x, y } = getCoords(e);
const isDark = html.getAttribute('data-theme') === 'dark';
ctx.lineWidth = 3;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.strokeStyle = isDark ? '#d4d4d4' : '#000000';
ctx.lineTo(x, y);
ctx.stroke();
}
canvas.addEventListener('mousedown', startDrawing);
window.addEventListener('mouseup', () => (isDrawing = false));
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('touchstart', startDrawing, { passive: false });
canvas.addEventListener('touchend', () => (isDrawing = false));
canvas.addEventListener('touchmove', draw, { passive: false });
function clearCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function saveEntry() {
const imageData = canvas.toDataURL();
const entries = JSON.parse(
localStorage.getItem('guestbook_v2') || '[]'
);
entries.unshift({
image: imageData,
date:
new Date().toLocaleDateString() +
' ' +
new Date().toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit',
}),
});
localStorage.setItem('guestbook_v2', JSON.stringify(entries));
clearCanvas();
displayEntries();
}
function displayEntries() {
const entries = JSON.parse(
localStorage.getItem('guestbook_v2') || '[]'
);
document.getElementById('entries').innerHTML = entries
.map(
(e) => `
<div class="entry-card">
<img src="${e.image}">
<p class="puny">${e.date}</p>
</div>
`
)
.join('');
}
displayEntries();
</script>
</body>
</html>