generated from fastai/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flashcards.html
214 lines (199 loc) · 6.16 KB
/
flashcards.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
---
layout: default
permalink: /flashcards/
title: Flashcards
search_exclude: false
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/png" href="flashcard.png" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<title>Flashcards</title>
</head>
<body>
<main>
<span id="ruler"></span>
<div id="reload">
<button class="btn" id="refresh"><i class="fas fa-sync-alt"></i></button>
</div>
<div class="container">
<div id="flashcards">
<div class="topic">
<p class="leftSide"></p>
<p class="rightSide"></p>
</div>
<div class="card">
<div class="front">
<h2 id="front"></h2>
</div>
<div class="back">
<h2 id="back"></h2>
</div>
</div>
</div>
</div>
<script>
function splitString(string){
if(string.toLowerCase().includes('set')){
string = string.replace(' Set', '') ?? string.replace(' set', '');
}
if(string.toLowerCase().includes('ap')){
string = string.replace('AP', 'AP ');
}
//split the string in half based on the number of characters it has. If it has a space, split it there. If it doesn't, split it in half.
let split = string.includes(' ') ? string.split(' ') : [string.slice(0, Math.ceil(string.length / 2)), string.slice(Math.ceil(string.length / 2))];
const firstHalf = split[0];
const secondHalf = split[1];
return [firstHalf, secondHalf];
}
const front = document.getElementById('front')
const back = document.getElementById('back')
const leftSide = document.querySelector('.leftSide')
const rightSide = document.querySelector('.rightSide')
fetch(`https://quizme.nighthawkcoders.tk/test`, { method: 'GET', }).then(res => {
return res.text();
}).then(html => {
const htmlArray = JSON.parse(html) //converts data received into an JSON obj
const randomTopic = htmlArray[Math.floor(Math.random() * (htmlArray.length - 1))]
const randomId = Math.floor(Math.random() * randomTopic.flashcards.length) //random id number between 0 and lastElementId
const randomElement = randomTopic.flashcards[randomId] //gets the last element id in the array
front.innerHTML = randomElement.term
back.innerHTML = randomElement.definition
leftSide.innerHTML = splitString(randomTopic.name)[0]
rightSide.innerHTML = splitString(randomTopic.name)[1]
back.style.display = 'none';
})
.catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
});
const card = document.querySelector('.card')
card.addEventListener('click', () => {
if (back.style.display === 'none') {
front.style.display = 'none';
card.style.transform = 'rotateY(180deg)'
function showBack(){
back.style.transform = 'rotateY(180deg)'
back.style.display = 'block';
}
setTimeout(showBack, 300)
} else if(back.style.display === 'block') {
back.style.display = 'none';
card.style.transform = 'rotateY(360deg)'
function hideBack(){
front.style.transform = 'rotateY(360deg)'
front.style.display = 'block';
}
setTimeout(hideBack, 300)
}
})
console.log(rightSide.offsetWidth)
if(leftSide.style.width > rightSide.style.width){
console.log('a')
while(leftSide.offsetWidth > rightSide.offsetWidth){
rightSide.style.fontSize = `${parseInt(rightSide.style.fontSize) - 1}px`
}
}
const refresh = document.getElementById('refresh')
refresh.addEventListener('click', () => {
location.reload()
})
</script>
</script>
</main>
</body>
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@800&display=swap');
#ruler { visibility: hidden; white-space: nowrap; }
#flashcards {
position: relative;
z-index: 1;
}
/* style the text in topic to be behind the card. The text should be just outside the card*/
.topic {
display: none;
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 92%;
height: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
}
.leftSide {
display: none;
font-family: 'Open Sans', sans-serif;
font-size: 6rem;
color: #121212;
margin-left: -10rem;
letter-spacing: .8rem;
text-shadow: 0 0 10px rgb(255, 255, 255);
}
.rightSide {
display: none;
font-family: 'Open Sans', sans-serif;
font-size: 6rem;
color: #121212;
margin-right: -13rem;
text-shadow: 0 0 10px rgb(255, 255, 255);
}
.container {
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.card {
font-family: 'Roboto', sans-serif;
color: black;
width: 30rem;
height: 30rem;
justify-content: center;
align-items: center;
display: flex;
background: rgb(255, 238, 218);
border-radius: 10px;
box-shadow: 0 10px 15px rgba(255, 238, 218, 0.651);
transition: 0.6s;
}
.card:hover {
transform: scale(1.05);
}
.front {
font-size: 3rem;
text-align: center;
font-weight:lighter;
}
.back {
font-size: 1rem;
text-align:center;
font-weight:lighter;
}
#reload{
display: flex;
justify-content: center;
align-items: center;
margin-top:3%;
margin-bottom: 2%;
}
.btn {
background: rgba(255, 238, 218, 0);
border: none;
outline: none;
font-size: 2rem;
color: rgb(224, 224, 224);
cursor: pointer;
transition: 0.6s;
}
.btn:hover {
transform: rotate(360deg);
}
</style>
</html>