-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
382 lines (330 loc) · 12.3 KB
/
index.html
File metadata and controls
382 lines (330 loc) · 12.3 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Poetry Grid Helper</title>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
margin: 0;
font-family: 'Playfair Display', serif;
background-color: #fff;
color: #333;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background-color: transparent;
padding: 10px 20px;
border-bottom: 1px solid #e0e0e0;
display: flex;
justify-content: space-between;
align-items: center;
}
main {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.product-info {
background-color: #fff;
padding: 40px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
}
.product-info h2 {
margin-top: 0;
color: #007BFF;
font-weight: 700;
}
.product-info p {
font-size: 1.2em;
color: #666;
line-height: 1.6;
}
.cta-button {
background-color: #FFD700;
color: #000;
border: none;
padding: 15px 30px;
font-size: 1em;
border-radius: 5px;
cursor: pointer;
margin-top: 20px;
transition: background-color 0.3s;
}
.cta-button:hover {
background-color: #e5c100;
}
footer {
background-color: #fff;
padding: 20px;
text-align: center;
border-top: 1px solid #e0e0e0;
}
footer p {
margin: 0;
color: #999;
font-size: 0.9em;
}
.container {
text-align: center;
width: 100%;
max-width: 600px;
margin: 0 auto;
}
#wordInput {
width: 100%;
max-width: 500px;
padding: 10px;
font-size: 16px;
margin-bottom: 20px;
border: 2px solid #3498db;
border-radius: 4px;
outline: none;
transition: border-color 0.3s ease;
}
#wordInput:focus {
border-color: #2980b9;
}
#statusMessage {
margin-top: 20px;
font-size: 18px;
color: #2c3e50;
}
#table-container {
width: auto;
height: auto;
overflow: visible;
}
table {
width: 100%;
border-collapse: collapse;
text-align: center;
margin: 0 auto;
background-color: #fff;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
td {
border: 1px solid #ddd;
padding: 10px;
font-size: 20px;
font-weight: bold;
color: #34495e;
transition: transform 0.3s ease, opacity 0.3s ease;
opacity: 0;
transform: scale(0.8);
white-space: nowrap;
overflow: visible;
text-align: center;
}
td.filled {
opacity: 1;
transform: scale(1);
}
td.unique {background:cyan;}
@media (max-width: 600px) {
td {
font-size: 16px;
padding: 5px;
}
}
a {text-decoration:none;}
td {
border: 1px solid #ddd;
width: 16.66%;
padding: 10px;
font-size: 20px;
font-weight: bold;
color: #34495e;
transition: transform 0.3s ease, opacity 0.3s ease;
opacity: 0;
transform: scale(0.8);
}
td.filled {
opacity: 1;
transform: scale(1);
color: #fff; /* Ensure text is readable against colored backgrounds */
}
td.warning {
border-color: red;
}
</style>
<script src="https://unpkg.com/compromise@14.14.4/builds/compromise.js"></script>
</head>
<body>
<header>
<!-- Header Content (if needed) -->
</header>
<main>
<section class="product-info"><a href="https://www.producthunt.com/posts/poetry-grid-helper?embed=true&utm_source=badge-featured&utm_medium=badge&utm_souce=badge-poetry-grid-helper" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=727103&theme=light" alt="Poetry Grid Helper - Write a Poem That Reads The Same Both Directions | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
<h2>Can You Write a Poem That Reads The Same Both Horizontally and Vertically?</h2>
<h3>It's <em>Harder</em> Than it Looks...</h3>
<p><details><summary><mark> Click here to read one by Louis Carroll</mark></summary><img src="square-stanza.png"><p>Credit for this find goes to <em><a href="https://www.futilitycloset.com/2009/05/18/7669/">Futility Closet</a></em>!</p></details></p><hr>
<div class="legend">
<span class="legend-item" style="background:#ffeb3b;padding:5px;">Pronoun</span>
<span class="legend-item" style="background:#f44336;color:#fff;padding:5px;">Noun</span>
<span class="legend-item" style="background:#2196f3;color:#fff;padding:5px;">Verb</span>
<span class="legend-item" style="background:#4caf50;color:#fff;padding:5px;">Adjective</span>
<span class="legend-item" style="background:#9c27b0;color:#fff;padding:5px;">Adverb</span>
<span class="legend-item" style="background:#00bcd4;color:#fff;padding:5px;">Preposition</span>
<span class="legend-item" style="background:#ff9800;color:#fff;padding:5px;">Conjunction</span>
<span class="legend-item" style="background:#e0e0e0;padding:5px;">Other</span>
</div>
<div class="container">
<p>Enter a six-word sentence to fill the grid. Each word will be placed both horizontally and vertically.</p>
<h3>How to Use</h3>
<p>
1. Enter exactly six words<br>
2. Press Enter to add them to the grid<br>
3. Repeat for 6 lines to complete the poem
</p>
<input type="text" id="wordInput" placeholder="Example: Roses are red violets are blue">
<div id="table-container">
<table id="wordGrid"></table>
</div><p>Still struggling? Try simple sentences with common words to start.</p>
<p><details><summary><mark>Click here to read my own attempt</mark></summary><img src="unnamed.png"></details>
<div id="statusMessage"></div>
<button id="download" class="cta-button">Download Your Poem as Image</button>
</div>
</section>
</main>
<footer>
<p>© 2024 Poetry Grid Helper. All rights reserved.</p>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
const wordInput = document.getElementById("wordInput");
const tableContainer = document.getElementById("table-container");
const statusMessage = document.getElementById("statusMessage");
let currentRow = 0;
// Build a 6×6 grid
function createTable() {
const table = document.getElementById("wordGrid");
for (let i = 0; i < 6; i++) {
const row = document.createElement("tr");
for (let j = 0; j < 6; j++) {
const cell = document.createElement("td");
cell.setAttribute("data-row", i);
cell.setAttribute("data-col", j);
row.appendChild(cell);
}
table.appendChild(row);
}
}
// Part-of-speech detection using compromise
function getWordType(word) {
const doc = nlp(word);
if (doc.pronouns().length > 0) return "pronoun";
if (doc.nouns().length > 0) return "noun";
if (doc.verbs().length > 0) return "verb";
if (doc.adjectives().length > 0) return "adjective";
if (doc.adverbs && doc.adverbs().length > 0) return "adverb";
if (doc.prepositions && doc.prepositions().length > 0) return "preposition";
if (doc.conjunctions && doc.conjunctions().length > 0) return "conjunction";
return "other";
}
function getColorForWordType(wordType) {
switch (wordType) {
case "noun":
return "#f44336"; // red
case "verb":
return "#2196f3"; // blue
case "adjective":
return "#4caf50"; // green
case "pronoun":
return "#ffeb3b"; // yellow
case "adverb":
return "#9c27b0"; // purple
case "preposition":
return "#00bcd4"; // teal
case "conjunction":
return "#ff9800"; // orange
case "other":
default:
return "#e0e0e0"; // light grey for misc/unknown
}
}
function fillCell(row, col, word) {
const cell = document.querySelector(
`td[data-row='${row}'][data-col='${col}']`
);
if (!cell) return;
const wordType = getWordType(word);
const bgColor = getColorForWordType(wordType);
cell.textContent = word;
cell.classList.add("filled");
cell.dataset.pos = wordType;
cell.style.backgroundColor = bgColor;
// Text color: dark on light backgrounds, white on strong colors
const lightBackgrounds = ["#ffffff", "#ffeb3b", "#e0e0e0"];
if (lightBackgrounds.includes(bgColor)) {
cell.style.color = "#34495e";
} else {
cell.style.color = "#ffffff";
}
}
// Live word limit: auto-truncate to 6 words
wordInput.addEventListener("input", () => {
const words = wordInput.value.trim().split(/\s+/).filter(Boolean);
if (words.length > 6) {
wordInput.value = words.slice(0, 6).join(" ");
}
});
// Add a six-word sentence to the next row/column
function addSentence() {
const sentence = wordInput.value.trim();
const words = sentence.split(/\s+/).filter(Boolean);
if (words.length < 6) {
alert("Please enter exactly six words.");
return;
}
if (currentRow >= 6) {
statusMessage.textContent = "All cells are already filled.";
wordInput.disabled = true;
return;
}
// Fill row N and column N with the same six words
for (let i = 0; i < 6; i++) {
fillCell(currentRow, i, words[i]); // row
fillCell(i, currentRow, words[i]); // column
}
currentRow++;
wordInput.value = "";
if (currentRow === 6) {
statusMessage.textContent = "All cells filled!";
wordInput.disabled = true;
}
}
// Build the table
createTable();
// Enter key submits the sentence
wordInput.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
event.preventDefault();
addSentence();
}
});
// Export the grid as an image
document.getElementById("download").addEventListener("click", () => {
html2canvas(tableContainer, {
scale: 2,
useCORS: true,
scrollY: -window.scrollY
}).then((canvas) => {
const link = document.createElement("a");
link.download = "grid-poem.png";
link.href = canvas.toDataURL("image/png");
link.click();
});
});
});
</script>
</body>
</html>