-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
207 lines (193 loc) · 7.69 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<style type="text/css" media="screen">
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
#wrapper {
flex: 1;
}
</style>
<title>Open Repair Poetry</title>
<meta name="keywords" content="Open Data, poetry, repair">
<meta name="description" content="Poems generated using Open Data from the Open Repair Alliance.">
<meta name="author" content="Zenlan">
<meta property="og:type" content="website" />
<meta property="og:image"
content="https://github.com/openrepair/tools/tree/main/poetry/android-chrome-192x192.png" />
</head>
<body class="has-navbar-fixed-top has-background-white-ter">
<nav class="navbar is-fixed-top has-background-white-ter" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<p class="navbar-item has-text-weight-bold is-size-5 is-size-6-mobile">Open Repair Poetry</p>
<div class="field navbar-item">
<div class="select is-small">
<select id="lang">
<option value="en">English</option>
<option value="fr">French</option>
<option value="nl">Dutch</option>
<option value="de">German</option>
<option value="it">Italian</option>
<option value="es">Spanish</option>
<option value="da">Danish</option>
</select>
</div>
</div>
</div>
</nav>
<div id="wrapper" class="has-background-white-ter has-text-grey has-text-centered">
<div class="hero-body">
<p class="control">
<button id="go" class="button is-small is-rounded">
Fix another one
</button>
</p>
<div class="container is-size-6-mobile">
<pre id="poem"></pre>
</div>
</div>
</div>
<footer class="footer">
<div class="content has-text-centered is-size-6-mobile">
<p>
One of the
<a href="https://openrepair.github.io/tools/" target="_blank"
class="has-text-grey has-text-weight-bold is-underlined">
Open Repair Tools</a>
<br>
using data from the
<a href="https://openrepair.org" target="_blank"
class="has-text-grey has-text-weight-bold is-underlined">
Open Repair Alliance</a>
</p>
</div>
</footer>
<script src="data.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function (event) {
const data = {};
fetch('data.json')
.then((response) => response.json())
.then((json) => {
assign(json);
})
.catch(error => {
assign(fallback);
});
document.getElementById('go').addEventListener('click', function (e) {
e.preventDefault();
generate(document.getElementById('lang').value, Math.round(Math.random() * 5));
}, false);
});
function generate(lang, seed) {
if (seed > 0) {
// Roll for more chances of 0, free form verses.
seed = Math.round(Math.random()) ? seed : 0;
}
const fifth = data[lang].length / 5;
const a = data[lang].slice(0, fifth);
const b = data[lang].slice(fifth, fifth * 2);
const c = data[lang].slice(fifth * 2, fifth * 3);
const d = data[lang].slice(fifth * 3, fifth * 4);
const e = data[lang].slice(fifth * 4, data[lang].length - 1);
document.lines = [a, b, c, d, e]
document.getElementById('poem').innerText = '';
if (seed == 5) {
// 1 stanza line by line
let j = 0;
let n = 5;
let line = document.lines[j][Math.round(Math.random() * (document.lines[j].length - 1))];
document.getElementById('poem').innerText += line + "\n";
j++;
let x = setInterval(function () {
if (j == 1) {
n = 2;
} else if (j == 2) {
n = 4;
} else if (j == 3) {
n = 2;
} else if (j == 4) {
n = 0;
} else {
clearInterval(x)
return;
}
line = document.lines[n][Math.round(Math.random() * (document.lines[n].length - 1))];
document.getElementById('poem').innerText += line + "\n";
j++;
}, 1500);
} else {
// 3 stanzas
let i = 0;
let stanza = make_stanza(document.lines, lang, seed, i);
document.getElementById('poem').innerText += stanza + "\n";
i++;
let x = setInterval(function (lines) {
if (i == 3) {
clearInterval(x);
return;
}
stanza = make_stanza(document.lines, lang, seed, i);
document.getElementById('poem').innerText += stanza + "\n";
i++;
}, 2500);
}
}
function make_stanza(lines, lang, seed, i) {
let result = ''
for (j = 0; j < 5; j++) {
if (seed == 1) {
line = lines[j][Math.round(Math.random() * (lines[j].length - 1))];
} else if (seed == 2) {
n = Math.abs(j - 4);
line = lines[n][Math.round(Math.random() * (lines[n].length - 1))];
} else if (seed == 3) {
if (j < 2) {
n = j + 1;
} else if (j == 2) {
n = 4;
} else if (j == 3) {
n = 3;
} else if (j == 4) {
n = 0;
}
line = lines[n][Math.round(Math.random() * (lines[n].length - 1))];
} else if (seed == 4) {
if (i == 0) {
n = j;
} else if (i == 1) {
if (j == 0) {
n = 3;
} else if (j == 1) {
n = 2;
} else if (j == 2) {
n = 1;
} else if (j == 3) {
n = 2;
} else if (j == 4) {
n = 3;
}
} else {
n = Math.abs(j - 4);
}
line = lines[n][Math.round(Math.random() * (lines[n].length - 1))];
} else {
line = data[lang][Math.round(Math.random() * (data[lang].length - 1))];
}
result = result + line + "\n";
}
return result
}
function assign(json) {
data = json;
generate('en', 0);
}
</script>
</body>
</html>