-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
326 lines (292 loc) · 19 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
<!DOCTYPE html>
<html>
<head>
<title>Eminem's "Lose Yourself"</title>
</head>
<body>
<header>
<h1>Eminem's "Lose Yourself"</h1>
</header>
<section>
<h2>Bridge</h2>
<ul>
<li>You can do anything you set your mind to, man</li>
<li>Look, if you had one shot, or one opportunity</li>
<li>To seize everything you ever wanted in one moment</li>
<li>Would you capture it, or just let it slip? Yo</li>
</ul>
<h2>Verse 1</h2>
<p>His palms are sweaty, knees weak, arms are heavy<br>
There's vomit on his sweater already, mom's spaghetti<br>
He's nervous, but on the surface he looks calm and ready<br>
To drop bombs, but he keeps on forgettin'<br>
What he wrote down, the whole crowd goes so loud<br>
He opens his mouth, but the words won't come out<br>
He's chokin', how, everybody's jokin' now<br>
The clock's run out, time's up, over, blaow!</p>
<h2>Chorus</h2>
<p>Snap back to reality, oh, there goes gravity<br>
Oh, there goes Rabbit, he choked, he's so mad but he won't<br>
Give up that easy? No, he won't have it, he knows<br>
His whole back's to these ropes, it don't matter, he's dope<br>
He knows that but he's broke, he's so stagnant, he knows<br>
When he goes back to his mobile home, that's when it's<br>
Back to the lab again, yo, this whole rhapsody<br>
Better go capture this moment and hope it don't pass him, and</p>
<h2>Verse 2</h2>
<p>You better lose yourself in the music, the moment<br>
You own it, you better never let it go<br>
You only get one shot, do not miss your chance to blow<br>
This opportunity comes once in a lifetime, yo<br>
You better lose yourself in the music, the moment<br>
You own it, you better never let it go<br>
You only get one shot, do not miss your chance to blow<br>
This opportunity comes once in a lifetime, yo</p>
</section>
<footer>
<p>Lyrics adapted from "Lose Yourself" by Eminem.</p>
</footer>
</body>
<script>
const config = {
'fontSize' : 60,
'speed': 500,
'colorObj' : {
'h1' : 'red',
'h2' : 'red',
'h3' : 'red',
'h4' : 'red',
'h5' : 'red',
'h6' : 'red',
'p' : 'blue',
'ul' : 'green'
},
'wordPosition' : 0,
'tagPosition' : 0,
'intervalId' : null,
'lock': false,
'previousWord' : null
}
const modalContainer = document.createElement("div");
modalContainer.style.display = "flex";
modalContainer.style.flexWrap = "wrap";
modalContainer.style.alignContent = "center";
modalContainer.style.justifyContent = "center";
modalContainer.style.flex = "1";
modalContainer.style.fontSize = "60px";
modalContainer.style.fontFamily = "monospace";
const modalLogo = document.createElement("div");
modalLogo.style.position = "relative";
modalLogo.style.display = "flex";
modalLogo.style.justifyContent = 'flex-end'
modalLogo.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" style="width:100px" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Foreground" x="0px" y="0px" viewBox="-272 404.2 145.5 32.7" style="enable-background:new -272 404.2 145.5 32.7;" xml:space="preserve">
<g>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1,0,0.3,0,0.4,0c0.1,0,0.3,0,0.4,0v1.8c-0.3,0-0.5,0-0.8,0c-0.2,0-0.5,0-0.8,0c-0.6,0-1.1-0.1-1.4-0.2 c-0.3-0.1-0.6-0.3-0.8-0.5c-0.2-0.2-0.3-0.6-0.3-1c0-0.4-0.1-0.9-0.1-1.5v-3.6h-1.1V422h1.1v-3H-143.2z"/>
<path class="st2" style="fill:#231F20" d="M-138.8,426.7c0,0.3,0,0.6,0.1,0.9c0.1,0.3,0.2,0.6,0.3,0.8c0.2,0.2,0.4,0.4,0.6,0.6c0.2,0.2,0.6,0.2,0.9,0.2 c0.5,0,0.9-0.1,1.2-0.4c0.3-0.3,0.5-0.6,0.6-1.1h2.1c-0.1,0.6-0.3,1.1-0.6,1.5c-0.3,0.4-0.6,0.7-0.9,0.9c-0.3,0.2-0.7,0.4-1.1,0.5 c-0.4,0.1-0.8,0.1-1.2,0.1c-0.7,0-1.4-0.1-1.9-0.4c-0.5-0.2-1-0.6-1.3-1c-0.3-0.4-0.6-0.9-0.8-1.5s-0.3-1.1-0.3-1.8 c0-0.6,0.1-1.2,0.3-1.8c0.2-0.6,0.4-1,0.8-1.5c0.3-0.4,0.8-0.8,1.3-1c0.5-0.2,1.1-0.4,1.8-0.4c0.8,0,1.5,0.1,2,0.4 c0.5,0.3,1,0.6,1.3,1.1c0.3,0.5,0.5,1,0.7,1.6c0.1,0.6,0.2,1.3,0.1,2H-138.8z M-134.8,425.1c-0.1-0.6-0.2-1.1-0.5-1.4 c-0.3-0.3-0.7-0.5-1.3-0.5c-0.7,0-1.2,0.2-1.5,0.5c-0.3,0.3-0.5,0.8-0.6,1.4H-134.8z"/>
</g>
</svg>`
const modal = document.createElement("div");
modal.setAttribute("id", "modal")
modal.style.position = "fixed";
modal.style.top = "50%";
modal.style.left = "50%";
modal.style.minWidth = '600px';
modal.style.maxWidth = '100%';
modal.style.height = '400px';
modal.style.transform = "translate(-50%, -50%)";
modal.style.background = "white";
modal.style.padding = "20px";
modal.style.border = "1px solid black";
modal.style.zIndex = "999999";
modal.style.borderRadius = "10px";
modal.style.display = "flex";
modal.style.flexDirection = "column";
modal.style.opacity = "0";
modal.style.transition = "opacity 0.2s linear";
modal.appendChild(modalContainer);
modal.appendChild(modalLogo);
const legend = document.createElement("div");
legend.setAttribute("id", "legend")
legend.style.position = "fixed";
legend.style.bottom = "20px";
legend.style.right = "20px";
legend.style.minWidth = '200px';
legend.style.maxWidth = '100%';
legend.style.background = "white";
legend.style.padding = "20px";
legend.style.border = "1px solid black";
legend.style.zIndex = "999999";
legend.style.borderRadius = "10px";
legend.style.display = "flex";
legend.style.flexDirection = "column";
legend.style.opacity = "0";
legend.style.transition = "opacity 0.2s linear";
legend.innerHTML = `
<h4 style="margin-top: 0; margin-bottom:10px">Venetian Legend</h4>
<ul style="padding-left:0; list-style-type: none; font-family: monospace">
<li style="display:flex; justify-content:space-between;"><span>Size</span>Option and + / - </li>
<li style="display:flex; justify-content:space-between;"><span>Speed</span>Option and < / > </li>
<li style="display:flex; justify-content:space-between;"><span>Cancel</span>Option and Q</li>
<li style="display:flex; justify-content:space-between;"><span>Rewind</span>Option and N </li>
<li style="display:flex; justify-content:space-between;"><span>Forward</span>Option and M </li>
</ul>`
const tagsUsed = Object.keys(config.colorObj).join(',');
const tags = document.querySelectorAll(tagsUsed);
displayNextWord = () => {
if (config.wordPosition < words.length) {
modalContainer.innerHTML = words[config.wordPosition].word;
modalContainer.style.color = config.colorObj[`${words[config.wordPosition].tag.toLowerCase()}`];
config.colorObj[`${words[config.wordPosition].tag}`]
if(config.previousWord && words[config.wordPosition].tagPosition !== config.previousWord.tagPosition){
//todo work
}
config.previousWord = words[config.wordPosition]
config.wordPosition++;
} else {
clearInterval(config.intervalId);
}
}
createModal = () => {
document.body.appendChild(modal);
document.body.appendChild(legend)
setTimeout(() => {
modal.style.opacity = "1";
legend.style.opacity = "1"
}, 100)
}
let words = [];
// Loop through each tag
for (let i = 0; i < tags.length; i++) {
let tagName = tags[i].tagName
tags[i].addEventListener('mouseover', (e) => handleElementMouseOver(e, tags[i]));
tags[i].addEventListener('click', (e) => handleElementClick(e, tags[i]))
tags[i].addEventListener('mouseout', (e) => handleElementMouseOut(e, tags[i]));
var textContent = tags[i].textContent;
textContent = tags[i].textContent.replace(/(?:\r\n|\r|\n)/g, " ")
var textContentArray = textContent.split(" ");
for (var j = 0; j < textContentArray.length; j++) {
words.push({ word: textContentArray[j], tag: tagName, tagPosition: i });
}
}
const keyMapping = (e) => {
console.log(e.code)
if (e.altKey) {
switch(e.code) {
case 'Equal':
handleFontSizeChange('+')
break;
case 'Minus':
handleFontSizeChange('-')
break;
case 'Period':
handleSpeedChange('-')
break;
case 'Comma':
handleSpeedChange('+')
break;
case 'KeyQ':
handleCancel('KeyQ')
break;
case 'KeyG':
handleWordScrubChange('-')
break;
case 'KeyH':
handleWordScrubChange('+')
break;
default:
return
}
}
}
const clearTags = () => {
for (let i = 0; i < tags.length; i++) {
tags[i].style.backgroundColor = null
tags[i].style.color = null
tags[i].style.transition = null
}
}
function handleElementClick(e, tag) {
console.log(tag)
if (e.altKey) {
if(!document.getElementById('modal')){
createModal()
}
clearTags()
tag.style.backgroundColor = config.colorObj[`${tag.tagName.toLowerCase()}`];
tag.style.color = 'black';
tag.style.transition = "background-color 0.2s linear";
if(config.intervalId) {
clearInterval(config.intervalId)
}
let tagPosition = 0
for (let i = 0; i < tags.length; i++) {
if(tags[i].textContent === e.target.textContent && tags[i].tagName === e.target.tagName) {
config.tagPosition = i
}
}
config.wordPosition = words.findIndex(word => word.tagPosition === config.tagPosition)
config.intervalId = setInterval(displayNextWord, config.speed);
}
}
function handleElementMouseOver (e, tag){
if (e.altKey) {
tag.style.backgroundColor = config.colorObj[`${tag.tagName.toLowerCase()}`];
tag.style.color = 'black';
tag.style.transition = "background-color 0.2s linear";
}
}
function handleElementMouseOut (e, tag) {
if(e.altKey){
tag.style.backgroundColor = '';
tag.style.color = '';
}
}
handleFontSizeChange = (size) => {
config.fontSize = size === '+' ? config.fontSize + 10 : config.fontSize - 10
modalContainer.style.fontSize = `${config.fontSize}px`
}
handleSpeedChange = (size) => {
config.speed = size === '+' ? config.speed + 50 : config.speed - 50
clearInterval(config.intervalId);
config.intervalId = setInterval(displayNextWord, config.speed);
}
handleWordScrubChange = (direction) => {
if(!config.lock){
config.lock = true
clearInterval(config.intervalId)
modal.style.backgroundColor = "red";
modalContainer.style.color = "white";
modalContainer.style.fontSize = config.fontSize * 3
modalContainer.innerHTML = `${Math.round((config.wordPosition / words.length) * 100)}%` ;
setTimeout(() => {
modal.style.backgroundColor = "white";
config.wordPosition = direction === '+' ? config.wordPosition + 5 : config.wordPosition - 5
config.intervalId = setInterval(displayNextWord, config.speed);
config.lock = false
} , 500)
}
}
handleCancel = () => {
modalElement = document.getElementById('modal')
config.elementSelected = false
if(modalElement)
modalElement.remove()
clearInterval(config.intervalId);
}
document.addEventListener("keypress", keyMapping);
</script>
</html>