-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
209 lines (185 loc) · 7.99 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TayTay Lyric of the Day</title>
<script src="/assets/js/browser-window.js"></script>
<meta name="description" content="Challenge: Fill in the missing word of a Taylor Swift lyric every day.">
<meta property="og:image" content="https://screenshots.jamesg.blog?url=https://taytaylyricofthe.day">
<meta property="og:title" content="TayTay Lyric of the Day">
<meta property="og:description" content="Challenge: Fill in the missing word of a Taylor Swift lyric every day.">
<meta property="og:url" content="https://taytaylyricofthe.day">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
<link rel="alternate" type="application/rss+xml" title="TayTay Lyric of the Day" href="/feed.xml">
<link rel="icon" href="/assets/img/favicon.ico">
<style>
* {
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif
}
html, body {
padding: 0;
margin: 0;
}
main {
padding: 20px;
text-align: center;
max-width: 35em;
margin: auto;
}
fill-mask {
max-width: 500px;
display: block;
margin: auto;
border: 2px dotted royalblue;
padding: 10px;
line-height: 1.5;
}
fill-mask button {
margin: 10px;
padding: 10px 20px;
background-color: royalblue;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
fill-mask input {
padding: 10px;
border-radius: 5px;
border: 1px solid lightgray;
margin: 10px;
}
iframe {
width: 100%;
height: 300px;
border: none;
}
#buttons {
margin: auto;
}
.button-link {
display: inline-block;
padding: 10px 20px;
margin: 10px;
background-color: royalblue;
color: white;
text-decoration: none;
border-radius: 5px;
}
a {
text-decoration: none;
color: royalblue;
}
a:hover {
text-decoration: underline;
}
details {
margin-top: 20px;
border: 2px dotted royalblue;
padding: 10px;
}
details > h2, details > p {
text-align: left;
margin: 20px 0;
}
header {
background-image: url("https://i.pinimg.com/originals/82/c1/e2/82c1e2c8ef113a46b0954183b9576e90.jpg");
background-size: cover;
padding: 15px;
color: white;
height: 15px;
border-bottom: 2px solid royalblue;
}
</style>
</head>
<body>
<header></header>
<main>
<h1>TayTay Lyric of the Day 🎤</h1>
<p>Challenge: Fill in the missing word of a Taylor Swift lyric every day.</p>
<p id="check-back" style="display: none;">Check back tomorrow for another lyric.</p>
<fill-mask text="{% lyricToday %}." answer="{% answerToday %}"></fill-mask>
<script>
class FillMask extends HTMLElement {
constructor () {
super();
}
connectedCallback() {
this.innerHTML = `
<p>${this.getAttribute("text").replace("[word]", `<input type="text" data-answer="${this.getAttribute("answer")}">`)}</p>
<button id="check">Check</button>
<button id="reveal">Reveal</button>
<p>Streak: <span id="streak">0</span></p>
`;
var button = this.querySelector("#check");
var answer = this.getAttribute("answer");
answer = answer.toLowerCase().replace(/[^a-zA-Z ]/g, "");
var reveal = this.querySelector("#reveal");
button.addEventListener("click", function () {
var input = document.querySelector("input");
if (input.value.replace(/[^a-zA-Z ]/g, "") === answer) {
input.style.backgroundColor = "lightgreen";
// hide buttons
button.style.display = "none";
reveal.style.display = "none";
// update streak
var streak = localStorage.getItem("streak");
if (streak === null) {
streak = "";
}
localStorage.setItem("streak", streak + "🟢");
document.querySelector("#streak").textContent = streak + "🟢";
localStorage.setItem("lastGame", new Date().toDateString());
} else {
input.style.backgroundColor = "lightcoral";
// update streak
var streak = localStorage.getItem("streak");
localStorage.setItem("streak", steak + "🔴");
document.querySelector("#streak").textContent = streak + "🔴";
}
});
reveal.addEventListener("click", function () {
var input = document.querySelector("input");
input.style.backgroundColor = "white";
input.value = answer;
button.disabled = true;
localStorage.setItem("lastGame", new Date().toDateString());
});
var streak = localStorage.getItem("streak");
var lastGame = localStorage.getItem("lastGame");
if (streak === null) {
streak = "";
}
// streak is sequence of 1s and 0s, 1 is a win, 0 is a loss
document.querySelector("#streak").textContent = streak;
// disable if last game was today
console.log(lastGame);
if (lastGame === new Date().toDateString()) {
button.style.display = "none";
reveal.style.display = "none";
var input = document.querySelector("input");
input.value = answer;
input.disabled = true;
var checkBack = document.querySelector("#check-back");
checkBack.style.display = "block";
}
}
}
customElements.define("fill-mask", FillMask);
</script>
<section id="about">
<details>
<summary>About TayTay Lyric of the Day</summary>
<h2>About TayTay Lyric of the Day</h2>
<p>Test your comprehension of Taylor Swift's music with the TayTay Lyric of the Day challenge. Every day, a new lyric is posted with a missing word. Can you fill in the blank?</p>
<p>The quiz is reset every day, so you can test your knowledge of Taylor Swift's music every day.</p>
</details>
</section>
<footer>
<p>Made with ❤️, 🍪, and a 💻 by <a href="https://jamesg.blog">jamesg.blog</a>. <a href="https://github.com/capjamesg/taytaylyricofthe.day">View source code</a>.</p>
</footer>
</main>
</body>
</html>