-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
335 lines (270 loc) · 9.34 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="A generator of malaphors">
<meta name="keywords" content="linguistics, language, metaphors, idiom, idioms, metaphor, malaphor, malaphors">
<meta name="author" content="Lumorti">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Malaphoria</title>
<style>
#title {
font-size: 1.2em;
}
body {
text-align: center;
margin: 0;
padding: 0;
font-size: 1.2em;
background-color: #ffffff;
color: black;
font-family: Arial, sans-serif;
}
#top {
text-align: center;
height: auto;
width: 100%;
}
a {
text-decoration: none;
}
a:visited {
color: blue;
}
#middle{
display: none;
}
#centerWrapper{
text-align: center;
display: inline-block;
width: 70%;
max-width: 700px;
}
#bottom {
text-align: center;
height: 50vh;
width: 100%;
display: none;
}
#generate {
margin-top: 20px;
margin-bottom: 20px;
padding: 10px;
font-size: 1.0em;
border-radius: 10px;
}
#generate:hover{
background: white;
}
#malaphor {
margin-top: 3em;
margin-bottom: 3em;
padding: 2%;
color: black;
border-radius: 10px;
font-size: 1.5em;
cursor: pointer;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#originalLeft {
text-align: center;
width: 40%;
margin-top: 3%;
margin-left: 3%;
margin-right: 3%;
float: left;
padding: 2%;
background: #eeeeee;
color: black;
border-radius: 10px;
}
#originalRight {
text-align: center;
width: 40%;
margin-top: 3%;
margin-left: 3%;
margin-right: 3%;
float: left;
padding: 2%;
background: #eeeeee;
color: black;
border-radius: 10px;
}
@media only screen and (max-width: 800px) {
#originalRight {
width: 90%;
}
#originalLeft {
width: 90%;
}
}
</style>
<script>
var phraseData = [
{"words": "Is the Pope Catholic?",
"toMove": [["the Pope", "snwa"], ["Pope", "sn"]],
"toReplace": [["the Pope", "snwa"], ["Pope", "sn"], ["Catholic", "a"]]},
{"words": "Does a bear shit in the woods?",
"toMove": [["a bear", "snwa"], ["shit", "v"]],
"toReplace": [["a bear", "snwa"], ["the woods", "pnwa"]]},
{"words": "There are plenty more fish in the sea",
"toMove": [["the fish in the sea", "pnwa"], ["fish", "pn"]],
"toReplace": [["fish", "pn"], ["the sea", "pnwa"], ["sea", "pn"]]},
{"words": "Don't beat about the bush",
"toMove": [["the bush", "snwa"], ["beat", "v"], ["beat", "ptv"]],
"toReplace": [["the bush", "snwa"], ["beat about", "v"]]},
{"words": "Bob's your uncle",
"toMove": [["your uncle", "snwa"]],
"toReplace": [["your uncle", "snwa"]]},
{"words": "We'll cross that bridge when we come to it",
"toMove": [["that bridge", "snwa"]],
"toReplace": [["cross", "v"], ["bridge", "sn"], ["that bridge", "snwa"]]},
{"words": "Don't burn your bridges",
"toMove": [["burn", "v"], ["bridges", "pn"], ["burned", "ptv"], ["your bridges", "pnwa"]],
"toReplace": [["burn", "v"], ["your bridges", "pnwa"], ["your bridges", "snwa"]]},
{"words": "Don't look a gift horse in the mouth",
"toMove": [["a gift horse", "snwa"], ["gift horse", "sn"]],
"toReplace": [["a gift horse", "snwa"], ["look", "v"]]},
{"words": "Curiosity killed the cat",
"toMove": [["the cat", "snwa"], ["cat", "sn"], ["killed", "ptv"]],
"toReplace": [["the cat", "snwa"], ["the cat", "pnwa"], ["killed", "ptv"], ["curiosity", "pnwa"], ["curiosity", "snwa"]]},
{"words": "Between a rock and a hard place",
"toMove": [["a hard place", "snwa"]],
"toReplace": [["a rock", "snwa"], ["a hard place", "snwa"]]},
{"words": "Don't put all your eggs in one basket",
"toMove": [["all your eggs", "pnwa"], ["one basket", "snwa"], ["basket", "sn"], ["eggs","pn"], ["in one basket", "a"]],
"toReplace": [["put", "v"], ["your eggs", "pnwa"], ["one basket", "snwa"]]},
{"words": "A finger in every pie",
"toMove": [["a finger", "snwa"], ["every pie", "snwa"], ["finger", "sn"], ["pie", "sn"]],
"toReplace": [["a finger", "snwa"], ["finger", "sn"], ["pie", "sn"]]},
{"words": "The grass is always greener",
"toMove": [["the grass", "snwa"], ["green", "a"]],
"toReplace": [["the grass", "snwa"]]},
{"words": "Hit the nail on the head",
"toMove": [],
"toReplace": [["hit", "v"], ["the nail", "snwa"]]},
{"words": "Kill two birds with one stone",
"toMove": [["two birds", "pnwa"], ["birds", "pn"], ["stone", "sn"], ["one stone", "snwa"]],
"toReplace": [["birds", "pn"], ["stone", "sn"]]},
{"words": "Let the cat out of the bag",
"toMove": [["the cat", "snwa"], ["cat", "sn"], ["the bag", "snwa"]],
"toReplace": [["the cat", "snwa"], ["cat", "sn"], ["the bag", "snwa"]]},
{"words": "Don't count your chickens before they hatch",
"toMove": [["your chickens", "pnwa"], ["chicken", "sn"], ["chickens", "pn"], ["count", "v"], ["hatch", "v"]],
"toReplace": [["your chickens", "pnwa"], ["count", "v"], ["hatch", "v"]]},
{"words": "An apple a day keeps the doctor away",
"toMove": [["an apple a day", "snwa"], ["doctor", "sn"], ["apple", "sn"]],
"toReplace": [["an apple", "snwa"], ["the doctor", "snwa"]]},
{"words": "You can lead a horse to water, but you can't make him drink",
"toMove": [["a horse", "snwa"], ["drink", "v"]],
"toReplace": [["a horse", "snwa"], ["horse", "sn"], ["drink", "v"]]},
{"words": "Don't beat a dead horse",
"toMove": [["a dead horse", "snwa"], ["beat", "v"]],
"toReplace": [["a dead horse", "snwa"], ["beat", "v"]]}
]
</script>
<script>
// The latest generated phrase and the indices of its originals
var customPhrase = "";
var fromLeft = -1;
var fromRight = -1;
// The elements to update with the above info
var malaphorBox = undefined;
var leftOriginalBox = undefined;
var rightOriginalBox = undefined;
var bottomSection = undefined;
var middleSection = undefined;
// Called on body load
function init(){
// Save the DOM elements needed
malaphorBox = document.getElementById("malaphor");
leftOriginalBox = document.getElementById("originalLeft");
rightOriginalBox = document.getElementById("originalRight");
bottomSection = document.getElementById("bottom");
middleSection = document.getElementById("middle");
}
// Called on main button press, generates a new malaphor using the phrase list
function generateNew(){
// Pick a saying
var fromLeft = Math.floor(Math.random()*phraseData.length);
var customPhrase = phraseData[fromLeft]["words"];
// Pick a section to replace
var toReplace = Math.floor(Math.random()*phraseData[fromLeft]["toReplace"].length);
var typeToFind = phraseData[fromLeft]["toReplace"][toReplace][1];
// Loop over the phrases
var fromRight = -1;
var toMove = -1;
var numSkips = Math.floor(Math.random()*10);
var checking = 0;
var limit = 0;
while (fromRight < 0 && limit < 100){
// To prevent it crashing just in case
limit += 1
// Check each of the portable sections
var foundSection = -1;
for (var i=0; i<phraseData[checking]["toMove"].length; i++){
// If it's valid
if (phraseData[checking]["toMove"][i][1] == typeToFind){
// Only stop after numSkips results have been passed over
if (numSkips == 0){
fromRight = checking;
toMove = i;
} else {
numSkips -= 1;
}
break;
}
}
// Keep looping
checking += 1;
// Don't use the same phrase twice
if (checking == fromLeft){
checking += 1
}
// Loop back around once the end is reached
if (checking >= phraseData.length){
checking = 0;
}
}
console.log(fromLeft, fromRight);
// Temporarily make sure everything is the right case for matching
customPhrase = customPhrase.charAt(0).toLowerCase() + customPhrase.slice(1);
// If everything went well
if (limit < 100){
// Replace the phrase
customPhrase = customPhrase.replace(phraseData[fromLeft]["toReplace"][toReplace][0], phraseData[fromRight]["toMove"][toMove][0]);
// If it didn't
} else {
customPhrase = "error: couldn't find any " + typeToFind;
}
// Make sure the first letter is capitalised
customPhrase = customPhrase.charAt(0).toUpperCase() + customPhrase.slice(1);
// Update the UI elements
bottomSection.style.display = "block";
middleSection.style.display = "block";
malaphorBox.innerHTML = customPhrase;
leftOriginalBox.innerHTML = phraseData[fromLeft]["words"];
rightOriginalBox.innerHTML = phraseData[fromRight]["words"];
}
</script>
</head>
<body onload="init()">
<div id="centerWrapper">
<p id="title">MALAPHORIA<br>(a generator of malaphors by <a href="https://github.com/Lumorti/Malaphoria">Lumorti<a/>)</p>
<div id="top">
<!--<button id="generate" onclick="generateNew()">Generate a New Malaphor</button>-->
<div id="malaphor" onclick="generateNew()">> Keep clicking here to generate malaphors <</div>
</div>
<p id="middle">from the sayings:</p>
<div id="bottom">
<div id="originalLeft"></div>
<div id="originalRight"></div>
</div>
</div>
</body>
</html>