-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (149 loc) · 4.12 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
<title>
Name Picker
</title>
<head>
<style>
body {
background-color: peachpuff;
cursor: url('hand-cursor.png'), auto;
font-family: "Comic Sans MS"
}
button {
width: 100%;
margin-top: 10px;
font-size: 36px;
color: white;
background-color: royalblue;
border-radius: 5px;
cursor: inherit;
font-family: inherit;
}
#nameList {
width: 100%;
font-size: 20px;
border: none;
background: ivory;
border-radius: 10px;
padding: 20px;
cursor: inherit;
font-family: inherit;
}
#pickedName {
font-weight: 700;
font-size: 48px;
text-align: center;
line-height: 100px;
height: 100px;
font-family: inherit;
}
.randomizingName {
animation: flash linear 1s infinite;
}
.finalName {
background: none;
border: none;
animation: pulse linear 1s infinite;
}
@keyframes flash {
0% {
opacity: .1;
}
50% {
opacity: 1;
}
100% {
opacity: .1;
}
}
@keyframes pulse {
0% {
font-size: 48px;
}
50% {
font-size: 96px;
}
100% {
font-size: 48px;
}
}
</style>
<script>
let nameSelected = false;
async function pickNameFromList() {
const nameListElement = document.getElementById('nameList');
if (!nameListElement.value) {
return;
}
nameListElement.style.display = 'none';
const nameList = getNameList();
document.getElementById('pickNameButton').style.display = 'none';
document.getElementById('pickedName').classList.add('randomizingName');
document.getElementById('selectDisplayedNameButton').style.display = 'block';
const startTime = Date.now();
while (!nameSelected) {
const pickedName = nameList[Math.floor(Math.random() * nameList.length)];
showPickedName(pickedName);
await sleep(1000);
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function getNameList() {
const nameListElement = document.getElementById('nameList');
if (!nameListElement.value) {
return;
}
let nameList = nameListElement.value.replace(/(\r\n|\n|\r)/gm, ',').split(',');
return nameList.filter((val) => val.trim());
}
function showPickedName(pickedName) {
const pickedNameElement = document.getElementById('pickedName');
pickedNameElement.innerHTML = pickedName;
pickedNameElement.style.display = 'block';
}
function showNameList() {
nameSelected = false;
document.getElementById('nameList').style.display = 'block';
document.getElementById('pickNameButton').style.display = 'block';
document.getElementById('pickedName').style.display = 'none';
document.getElementById('tryAgainButton').style.display = 'none';
document.getElementById('pickedName').classList.remove('finalName');
}
function selectDisplayedName() {
// actually randomize the name
const nameList = getNameList();
const pickedName = nameList[Math.floor(Math.random() * nameList.length)];
showPickedName(pickedName);
nameSelected = true;
document.getElementById('pickedName').classList.remove('randomizingName');
document.getElementById('pickedName').classList.add('finalName');
document.getElementById('selectDisplayedNameButton').style.display = 'none';
document.getElementById('tryAgainButton').style.display = 'block';
}
</script>
</head>
<body>
<h1>Name Picker</h1>
<textarea id="nameList" placeholder="Enter a list of names" rows="15">Chris
Simon
Grant
Lyric
Thomas
Nater
Maria
Mike
Caitlin
Derek
Marcus</textarea>
<div id="pickedName" style="display: none"></div>
<button id="pickNameButton" onclick="pickNameFromList()">
Go!
</button>
<button id="selectDisplayedNameButton" onclick="selectDisplayedName()" style="display: none;">
Select Name
</button>
<button id="tryAgainButton" onclick="showNameList()" style="display: none;">
Pick Another Name
</button>
</body>