-
Notifications
You must be signed in to change notification settings - Fork 0
/
cropcircles.html
82 lines (73 loc) · 2.7 KB
/
cropcircles.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
<html>
<head>
<style>
table {
width: 100%;
height: 100%;
}
textarea {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<table>
<tr>
<td>
<textarea id="input"></textarea>
</td>
<td>
<textarea id="loveless" readonly></textarea>
</td>
<td>
<textarea id="love" readonly></textarea>
</td>
</tr>
</table>
<script>
const input = document.getElementById("input");
const love = document.getElementById("love");
const loveless = document.getElementById("loveless");
input.addEventListener("input", () => {
love.value = input.value
.split("\n")
.map(line => line.toLowerCase())
.map(line => line.split('|').map(word => word.replaceAll(/[^a-z]/g, "")).join("|"))
.map(line => `${`(${line.replaceAll(/[^a-z]/g, "").length})`.padStart(4)} ${line}`)
.map(line => line.toUpperCase())
.join("\n")
.replaceAll("(0) ", "");
loveless.value = input.value
.split("\n")
.map(line => line.toLowerCase())
.map(line => line.split('|').map(word => word.replaceAll(/[^a-z]/g, "")).join("|"))
.map(line => line.replaceAll(/[^a-z]+/g, "|"))
.map(line => line.replaceAll("o", ""))
.join("\n");
localStorage.setItem("input", input.value);
});
input.value = localStorage.getItem("input");
input.dispatchEvent(new Event("input"));
input.focus();
// Scroll the textboxes in tandem.
const textboxes = [input, love, loveless];
const scroller = (event) => {
for (const textbox of textboxes) {
if (textbox == event.target) {
continue;
}
textbox.scrollTop = event.target.scrollTop;
}
};
for (const textbox of textboxes) {
textbox.addEventListener("mouseover", () => {
textbox.addEventListener("scroll", scroller);
});
textbox.addEventListener("mouseout", () => {
textbox.removeEventListener("scroll", scroller);
});
}
</script>
</body>
</html>