-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
282 lines (265 loc) · 11.8 KB
/
Copy pathindex.html
File metadata and controls
282 lines (265 loc) · 11.8 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AWKward</title>
<style>
body {
max-width: 720px;
margin: 40px auto;
padding: 0 16px;
font-family: system-ui, sans-serif;
line-height: 1.4;
}
label, textarea, input, button, select { font: inherit; }
label { display: block; margin-bottom: 6px; font-weight: 700; }
input, textarea {
width: 100%;
box-sizing: border-box;
border: 1px solid #aaa;
padding: 8px;
}
textarea {
height: 84px;
margin: 12px 0 8px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
resize: vertical;
}
button { padding: 8px 12px; }
hr { margin: 32px 0; border: 0; border-top: 1px solid #aaa; }
h2 { margin: 0 0 12px; }
iframe { display: block; margin: 18px 0; max-width: 100%; }
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.swatch {
width: 28px;
height: 28px;
border: 1px solid #aaa;
background: var(--fill);
cursor: pointer;
}
.swatch[aria-pressed="true"] { outline: 2px solid #171717; outline-offset: 2px; }
.board-wrap { width: 100%; overflow-x: auto; }
#place-board svg {
display: block;
width: 100%;
box-sizing: border-box;
height: auto;
background: #f2f2ee;
border: 1px solid #aaa;
}
#place-board .px { cursor: crosshair; shape-rendering: crispEdges; stroke: rgba(0, 0, 0, .18); stroke-width: .035; }
#place-board .px:hover { stroke: #171717; stroke-width: .12; }
.manual { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 12px 0 8px; }
.manual label { display: grid; gap: 4px; margin: 0; }
.manual input { width: 76px; }
.manual select { border: 1px solid #aaa; background: #fff; padding: 8px; }
.guestbook-list {
min-height: 84px;
margin: 12px 0;
padding: 8px;
border: 1px solid #aaa;
}
.guestbook-list ol { margin: 0; padding-left: 24px; }
.guestbook-list li { margin-bottom: 6px; }
.guestbook-list time { color: #555; }
.empty { margin: 0; color: #555; }
.status { margin-left: 8px; color: #555; }
footer { margin: 32px 0 0; color: #555; }
</style>
</head>
<body>
<h1>AWKward</h1>
<p>The world's worst website. Everything you see is powered by pure POSIX AWK, served by CGI via HTML, CSS, and a regrettable amount of JS.</p>
<hr>
<section aria-labelledby="increment-heading">
<h2 id="increment-heading">increment.awk</h2>
<p>The world's most advanced increment button.</p>
<label for="key">Key</label>
<input id="key" value="changeme" autocomplete="off">
<iframe id="preview" title="increment.awk" width="88" height="31" frameborder="0"></iframe>
<textarea id="embed" readonly></textarea>
<button id="copy" type="button">Copy</button><span id="status" class="status"></span>
</section>
<hr>
<section aria-labelledby="place-heading">
<h2 id="place-heading">place.awk</h2>
<p>A shared 88x31 pixel board.</p>
<nav class="palette" aria-label="Palette">
<button type="button" class="swatch" data-color="." aria-label="Erase" title="Erase" style="--fill:#f2f2ee"></button>
<button type="button" class="swatch" data-color="R" aria-label="Red" title="Red" style="--fill:#e23b3b"></button>
<button type="button" class="swatch" data-color="G" aria-label="Green" title="Green" style="--fill:#2e9d59"></button>
<button type="button" class="swatch" data-color="B" aria-label="Blue" title="Blue" style="--fill:#3478d4"></button>
<button type="button" class="swatch" data-color="Y" aria-label="Yellow" title="Yellow" style="--fill:#f2c84b"></button>
<button type="button" class="swatch" data-color="C" aria-label="Cyan" title="Cyan" style="--fill:#34b8ba"></button>
<button type="button" class="swatch" data-color="M" aria-label="Magenta" title="Magenta" style="--fill:#c45ac4"></button>
<button type="button" class="swatch" data-color="K" aria-label="Black" title="Black" style="--fill:#171717"></button>
<button type="button" class="swatch" data-color="W" aria-label="White" title="White" style="--fill:#ffffff"></button>
</nav>
<div class="board-wrap" id="place-board"></div>
<form class="manual" id="place-form" method="post" action="/cgi-bin/place.awk">
<label>x<input id="place-x" name="x" type="number" min="0" max="87" value="0"></label>
<label>y<input id="place-y" name="y" type="number" min="0" max="30" value="0"></label>
<label>c
<select id="place-c" name="c">
<option value=".">erase</option>
<option value="R" selected>red</option>
<option value="G">green</option>
<option value="B">blue</option>
<option value="Y">yellow</option>
<option value="C">cyan</option>
<option value="M">magenta</option>
<option value="K">black</option>
<option value="W">white</option>
</select>
</label>
<button type="submit">Place</button>
</form>
<textarea id="place-embed" readonly></textarea>
<button id="place-copy" type="button">Copy</button><span id="place-status" class="status"></span>
</section>
<hr>
<section aria-labelledby="guestbook-heading">
<h2 id="guestbook-heading">guestbook.awk</h2>
<p>Leave a tiny note.</p>
<div id="guestbook-list" class="guestbook-list" aria-live="polite"></div>
<p><a href="/cgi-bin/guestbook.awk?full=1" target="_blank" rel="noopener">Open full guestbook</a></p>
<form id="guestbook-form" method="post" action="/cgi-bin/guestbook.awk">
<label for="guestbook-name">Name</label>
<input id="guestbook-name" name="name" maxlength="40" autocomplete="name">
<label for="guestbook-message">Message</label>
<textarea id="guestbook-message" name="message" maxlength="240"></textarea>
<button type="submit">Sign</button><span id="guestbook-status" class="status"></span>
</form>
</section>
<hr>
<footer><a href="https://github.com/mchalunderscore/awkward">open source</a>. made with malice</footer>
<script>
const key = document.getElementById("key");
const preview = document.getElementById("preview");
const embed = document.getElementById("embed");
const status = document.getElementById("status");
const placeBoard = document.getElementById("place-board");
const placeButtons = [...document.querySelectorAll(".swatch")];
const placeSelect = document.getElementById("place-c");
const placeEmbed = document.getElementById("place-embed");
const placeStatus = document.getElementById("place-status");
const guestbookList = document.getElementById("guestbook-list");
const guestbookStatus = document.getElementById("guestbook-status");
const placeColors = new Set(placeButtons.map((button) => button.dataset.color));
const savedPlaceColor = (() => {
try { return localStorage.getItem("place-color"); } catch (_) { return ""; }
})();
let placeColor = placeColors.has(savedPlaceColor) ? savedPlaceColor : "R";
async function copy(textarea, statusNode) {
try {
if (!navigator.clipboard) throw new Error("clipboard unavailable");
await navigator.clipboard.writeText(textarea.value);
statusNode.textContent = "Copied";
} catch (_) {
textarea.select();
statusNode.textContent = document.execCommand("copy") ? "Copied" : "Copy failed";
}
}
function safeKey(value) {
const cleaned = (value || "changeme").replace(/[^A-Za-z0-9_.-]/g, "_").slice(0, 64) || "changeme";
return cleaned === "." || cleaned === ".." ? "changeme" : cleaned;
}
function localDate() {
const now = new Date();
const month = String(now.getMonth() + 1).padStart(2, "0");
const day = String(now.getDate()).padStart(2, "0");
return `${now.getFullYear()}-${month}-${day}`;
}
function setPlaceColor(next) {
if (!placeColors.has(next)) next = "R";
placeColor = next;
try { localStorage.setItem("place-color", placeColor); } catch (_) {}
placeSelect.value = placeColor;
for (const button of placeButtons) {
button.setAttribute("aria-pressed", String(button.dataset.color === placeColor));
}
}
async function requireOk(response) {
const cgiStatus = response.headers.get("Status");
if (response.ok && (!cgiStatus || cgiStatus.startsWith("2"))) return response;
throw new Error(await response.text() || response.statusText || `HTTP ${response.status}`);
}
async function loadPlaceBoard() {
const response = await requireOk(await fetch(`/cgi-bin/place.awk?badge=1&_=${Date.now()}`, { cache: "no-store" }));
placeBoard.innerHTML = await response.text();
}
async function placePixel(x, y, c) {
placeStatus.textContent = "Placing";
try {
const params = new URLSearchParams({ x, y, c });
await requireOk(await fetch(`/cgi-bin/place.awk?${params}`, {
method: "POST",
cache: "no-store"
}));
await loadPlaceBoard();
placeStatus.textContent = "Placed";
} catch (_) {
placeStatus.textContent = "Place failed";
}
}
async function loadGuestbook() {
const response = await requireOk(await fetch(`/cgi-bin/guestbook.awk?_=${Date.now()}`, { cache: "no-store" }));
guestbookList.innerHTML = await response.text();
}
function update() {
const src = `${location.origin}/cgi-bin/increment.awk?key=${encodeURIComponent(safeKey(key.value))}`;
preview.src = src;
embed.value = `<iframe src="${src}" title="increment.awk" width="88" height="31" frameborder="0"></iframe>`;
status.textContent = "";
}
key.addEventListener("input", update);
document.getElementById("copy").addEventListener("click", () => copy(embed, status));
document.getElementById("place-copy").addEventListener("click", () => copy(placeEmbed, placeStatus));
for (const button of placeButtons) {
button.addEventListener("click", () => setPlaceColor(button.dataset.color));
}
placeSelect.addEventListener("change", () => setPlaceColor(placeSelect.value));
placeBoard.addEventListener("click", (event) => {
const pixel = event.target.closest(".px");
if (!pixel) return;
placePixel(pixel.dataset.x, pixel.dataset.y, placeColor);
});
document.getElementById("place-form").addEventListener("submit", (event) => {
event.preventDefault();
if (!event.currentTarget.reportValidity()) return;
placePixel(document.getElementById("place-x").value, document.getElementById("place-y").value, placeSelect.value);
});
document.getElementById("guestbook-form").addEventListener("submit", async (event) => {
event.preventDefault();
const name = document.getElementById("guestbook-name").value;
const date = localDate();
const message = document.getElementById("guestbook-message").value;
if (!message.trim()) {
guestbookStatus.textContent = "Message required";
return;
}
guestbookStatus.textContent = "Signing";
try {
const params = new URLSearchParams({ name, date, message });
await requireOk(await fetch(`/cgi-bin/guestbook.awk?${params}`, {
method: "POST",
cache: "no-store"
}));
document.getElementById("guestbook-message").value = "";
await loadGuestbook();
guestbookStatus.textContent = "Signed";
} catch (_) {
guestbookStatus.textContent = "Sign failed";
}
});
const placeSrc = `${location.origin}/cgi-bin/place.awk?badge=1`;
placeEmbed.value = `<img src="${placeSrc}" width="88" height="31">`;
setPlaceColor(placeColor);
loadPlaceBoard().catch(() => { placeStatus.textContent = "Board failed"; });
loadGuestbook().catch(() => { guestbookStatus.textContent = "Load failed"; });
update();
</script>
</body>
</html>