-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
337 lines (295 loc) · 14 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
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
<!doctype html>
<html lang="en" class="h-100" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="description" content="Generate a phrase with three random words.">
<meta name="keywords" content="Random, Phrase, Generator, Words, Word">
<meta name="author" content="CleverCarpet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Three Word Phrase</title>
<link rel="icon" type="image/png" href="logo.png">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD"
crossorigin="anonymous"></script>
</head>
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
/*
* Globals
*/
/* Custom default button */
.btn-light,
.btn-light:hover,
.btn-light:focus {
color: #333;
text-shadow: none;
/* Prevent inheritance from `body` */
}
/*
* Base structure
*/
body {
text-shadow: 0 .05rem .1rem rgba(0, 0, 0, .5);
box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5);
}
.cover-container {
max-width: 42em;
}
/*
* Header
*/
.nav-masthead .nav-link {
color: rgba(255, 255, 255, .5);
border-bottom: .25rem solid transparent;
}
.nav-masthead .nav-link:hover,
.nav-masthead .nav-link:focus {
border-bottom-color: rgba(255, 255, 255, .25);
}
.nav-masthead .nav-link+.nav-link {
margin-left: 1rem;
}
.nav-masthead .active {
color: #fff;
border-bottom-color: #fff;
}
.nav-link {
cursor: pointer;
}
</style>
<body class="d-flex h-100 text-center text-bg-dark" data-bs-theme="dark">
<div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
<header class="mb-auto">
<div>
<h3 class="float-md-start mb-0">
<a href="/" style="display: inline-flex;" class="align-items-center text-decoration-none">
<img class="bi me-2" width="40" height="40" src="logo.png" alt="Logo">
<span style="margin-left: 4px;color: white;" class="fs-4 nav-link">TWP</span>
</a>
</h3>
<nav class="nav nav-masthead justify-content-center float-md-end">
<a class="nav-link fw-bold py-1 px-0 active" aria-current="page" href="#">Home</a>
<a class="nav-link fw-bold py-1 px-0" id="aboutButton">About</a>
<a class="nav-link fw-bold py-1 px-0" href="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/CleverCarpet">Developer</a>
</nav>
</div>
</header>
<main class="px-3">
<h1>Three Word Phrase</h1>
<p class="lead">Need a random phrase? Look no futher than the TWP Generator.</p>
<div id="errorbox"></div>
<p class="lead">
<div class="mb-3">
<label for="wordBox" class="form-label">Your Random Phrase</label>
<div class="input-group mb-3" id="wordbox" aria-describedby="emailHelp">
<input type="text" class="form-control" id="wordOutput" aria-describedby="copyButton" readonly>
<button class="btn btn-secondary" type="button" id="copyButton" data-bs-toggle="copyToolTip"
data-bs-placement="top" data-bs-title="Copied">Copy</button>
</div>
<div id="generatorHelp" class="form-text" style="display: none;">This is taking longer than expected.
Try refreshing the page.</div>
</div>
<div class="input-group mb-3" style="justify-content: center;">
<button type="submit" class="btn btn-primary" id="generateButton">Generate Phrase</button>
<button id="optionsButton" type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split"
aria-expanded="false">
<span class="visually-hidden">Toggle Options</span>
</button>
</div>
</p>
</main>
<div class="modal fade" id="optionsModal" tabindex="-1" aria-labelledby="aboutModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="aboutModalLabel">Generation Options</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="input-group mb-3">
<span class="input-group-text">Words</span>
<input type="number" class="form-control numparam param" id="exactly"
placeholder="How Many Strings to Generate" value="3">
</div>
<div class="input-group mb-3">
<span class="input-group-text">Min Length</span>
<input type="number" class="form-control numparam param" id="minlength"
placeholder="Minimum Length of Each Word" value="2">
</div>
<div class="input-group mb-3">
<span class="input-group-text" >Max Length</span>
<input type="number" class="form-control numparam param" id="maxlength"
placeholder="Maximum Length of Each Word" value="10">
</div>
<div class="form-floating">
<select class="form-select selectparam param" id="format"
aria-label="Floating label select example ">
<option selected value="beginning">Beginning</option>
<option value="complete">Complete</option>
<option value="none">None</option>
</select>
<label for="floatingSelect">Text Formatting</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="aboutModal" tabindex="-1" aria-labelledby="aboutModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="aboutModalLabel">About</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h4>Why?</h4>
<p>Have you ever been stumped when trying to come up with an idea for a username or title for
something? Well the TWP Generator fixes that by generating a random phrase for you to use.
Also, because I can.</p>
<h4>How?</h4>
<p>TWP Generator was made using HTML, CSS, Vannila Javascript, and <a
href="https://nodejs.org">Node.JS</a> The backend is hosted using a <a
href="https://repl.it">Repl.it</a> server at the moment and the frontend is hosted on
the <a href="https://carbondev.cf">Carbon Dev</a> Domain using <a
href="https://netlify.com">Netfliy</a>.</p>
<h4>Who?</h4>
<p>This generator was made by <strong><a
href="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/CleverCarpet">CleverCarpet</a></strong> himself.</p>
<h4>Credits</h4>
<a href="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/sindresorhus/random-word">Random Word Library</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
const copyToolTip = new bootstrap.Tooltip(document.getElementById('copyButton'), { 'trigger': 'manual focus' })
const aboutModal = new bootstrap.Modal(document.getElementById('aboutModal'))
const optionsModal = new bootstrap.Modal(document.getElementById('optionsModal'))
let exactly = 3
let minlength = 2
let maxlength = 20
let format = 'Beginning'
let paramelements = document.getElementsByClassName('param')
let paramselelements = document.getElementsByClassName('selectparam')
for (var i = 0; i < paramelements.length; i++) {
paramelements[i].addEventListener('input', function (e) {
if (e.id = 'exactly') {
exactly = document.getElementById(e.id).value
}else if (e.id = 'maxlength') {
maxlength = document.getElementById(e.id).value
} else if (e.id = 'minlength') {
minlength = document.getElementById(e.id).value
}
})
}
for (var i = 0; i < paramselelements.length; i++) {
paramselelements[i].addEventListener('change', function (e) {
if (e.id = 'format') {
format = document.getElementById(e.id).value
}
})
}
let isFetching = false
let options = {}
async function fetchWord() {
let genparams = 'exactly=' + exactly + '&minlength=' + minlength + '&maxlength=' + maxlength + '&format=' + format
let get = await fetch('https://randomwords.carboncdn.cf/api/generate?' + genparams, { timeout: 5000 }).catch(error => {
document.getElementById('errorBox').innerHTML = `<div class="alert alert-danger" role="alert"> There seems to be an issue fetching words from the dictionary. Try to <button type="button" class="btn btn-link" onclick="window.location.reload()">Refresh</button> </div>`
});
let res = await get.json()
return res
}
function testConnection() {
if (isFetching == true) {
document.getElementById('generatorHelp').style.display = 'block'
}
}
function runConnection() {
setTimeout(testConnection, 5000)
}
document.getElementById('generateButton').onclick = async function () {
isFetching = true
runConnection()
document.getElementById('generateButton').classList.add('placeholder')
document.getElementById('generateButton').disabled = true
document.getElementById('generateButton').innerText = "Fetching Phrase"
let wordsjson = await fetchWord()
let words = wordsjson.join(' ')
document.getElementById('generateButton').disabled = false
document.getElementById('generateButton').innerText = "Generate Phrase"
document.getElementById('generateButton').classList.remove('placeholder')
document.getElementById('wordOutput').value = words
isFetching = false
}
document.getElementById('copyButton').onclick = function () {
navigator.clipboard.writeText(document.getElementById('wordOutput').value)
copyToolTip.show()
}
document.getElementById('aboutButton').onclick = function () {
aboutModal.show()
}
document.getElementById('optionsButton').onclick = function () {
optionsModal.show()
}
</script>
<footer class="mt-auto text-white-50">
<p>TWP was made with ❤️ by <a href="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/CleverCarpet" class="text-white">CleverCarpet</a>.
</p>
</footer>
</div>
</body>
</html>