-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
291 lines (273 loc) · 13.3 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
<!DOCTYPE html>
<html lang="en">
<!--TODO:
* Add line numbers for reading section
* Make line number getter
-->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SAT QOTD</title>
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#87cefa"/>
<link rel="stylesheet" href="main.css">
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css" media="screen,projection"/>
<style>
h1 {
font-size: 1.2rem;
}
</style>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-180251239-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-180251239-1');
</script>
</head>
<body>
<div id="app">
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card-panel small teal lighten-2">
<span class="card-title">INFORMATION</span>
<p>Date: {{ questionDate }}</p>
<p>Section: {{ section }}{{ sub_section }}</p>
<p>Question Difficulty: {{ difficulty }}</p>
<p v-html="instructions"></p>
</div>
</div>
<div class="col s12 m6 offset-m3">
<div class="card white-grey darken-1 sticky-action">
<div class="card-content black-text">
<span class="card-title activator" @click="showHintText()">QUESTION</span>
<div class="FullQuestion" v-html="question"></div>
<div id="choiceList" class="card-action" style="padding-bottom: 0px;">
<ol type="A" class="collection">
<li style="background-color: transparent;" v-for="choice in choices">
<p class="choice" v-html="choice.body" style="width: 85%"></p>
<button class="btn-small waves-effect selectButton" @click="select($event, choice)">Select</button>
</li>
</ol>
<div id="SubmitButton">
<button class="btn submitButton" v-if="this.userAnswer!='' && !this.submitted" @click="submit()">Submit</button>
<button class="btn submitButton disabled" v-else>Submit</button>
</div>
</div>
</div>
<div id="showHint">
<button class="btn hintButton activator" @click="showHintText()" v-if="!this.showHintActive">Show hint</button>
<button class="btn hintButton activator" @click="showHintText()" v-else>Hide hint</button>
</div>
<div class="card-reveal">
<span class="card-title" @click="showHintText()">Hint<i class="material-icons right">close</i></span>
<p v-html="hint"/>
</div>
</div>
</div>
</div>
<p align="center">Made with ❤️ by <a href="https://github.com/amin-codes">Amin</a></p>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
<script>
//URL for json: https://data-sat-origin.collegeboard.org/api/v1/views/qotd.json
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
var gLines = []
function pixelToCharacter(ele)
{
return parseFloat(window.getComputedStyle(ele).getPropertyValue("max-width").replace("px","")) / 8.0;
}
function questiontoLines(theDOM)
{
var lines = [];
var paragraphs = theDOM.getElementsByClassName("FullQuestion")[0].children;
var tracker = 0;
for (var i = 1; i < paragraphs.length; i++) //Skip attributes
{
var paragraph = paragraphs[i];
if (paragraph.outerHTML.includes("<p class=\"firstLine\">") || paragraph.outerHTML.includes("<p class=\"everyLine\">"))
{
var eachTag = paragraph.outerHTML.substring(paragraph.outerHTML.indexOf("\">")+2).split("</a>");
for (var j = 0; j < eachTag.length; j++)
{
var lineID = eachTag[j].substring(eachTag[j].indexOf("<a id=\"")+"<a id=\"".length);
lineID = lineID.substring(lineID.indexOf("\""),lineID.indexOf("\\\""));
if (!(lineID===""))
{
var lineContentStart = -1;
var lineContentEnd = -1;
if (lineID.includes("start"))
{
var paragraphPixelSize = pixelToCharacter(paragraph);
var startIndex = paragraph.textContent.indexOf(eachTag[j+1].substring(0,eachTag[j+1].indexOf("<"))) / paragraphPixelSize;
var endIndex = eachTag[j+1].substring(0,eachTag[j+1].indexOf("<")).indexOf(".") / paragraphPixelSize;
console.log("TAG: " + lineID);
console.log("P SIZE: "+paragraphPixelSize);
console.log(" "+startIndex);
lineContentStart = Math.floor(startIndex);
lineContentEnd = Math.floor(endIndex) + lineContentStart;
console.log(" "+lineContentEnd);
lines[lineID] = tracker + lineContentStart + 1;
lines[lineID.replace("start", "end")] = tracker + lineContentEnd + 1;
}
}
}
tracker += Math.floor(paragraph.textContent.length/pixelToCharacter(paragraph));
}
}
return lines;
}
function replaceQuestionLines(question)
{
var q = question;
while (true)
{
var exists = q.indexOf("{line:");
var p = q.substring(exists+6);
if ((exists > -1) && p.includes("}"))
{
var tag = p.substring(0, p.indexOf("}"));
q = q.replace("{line:"+tag+"}", gLines[tag]);
}
else{
break;
}
}
return q;
}
function getParentUntil(starting, html)
{
if (starting.href.startsWith(html)) return starting;
return getParentUntil(starting.parentElement, hml);
}
function isAuto(event)
{
return event.attributes[0] === undefined || event.attributes[0].nodeValue==="background-color: transparent;";
}
function changeColor(event, color)
{
var isAutoColor = isAuto(event);
if (isAutoColor)
{
event.style.backgroundColor = color;
}
else
event.attributes[0].nodeValue = "background-color: transparent;";
}
function forceChangeColor(event, color)
{
event.style.backgroundColor = color;
}
const app = new Vue({
el: '#app',
data: {
questionDate: "",
question: "",
difficulty: "",
correctAnswer: "",
hint: "",
choices: [],
instructions: "Instructions: ",
section: "",
sub_section: "",
userAnswer: "",
showHintActive: false,
submitted: false,
attribution: "",
prompt: "",
globalLines: []
},
methods:
{
select: function(event, userA)
{
var answer = userA;
var target = event.target;
for (var i = 0; i < event.target.parentElement.parentElement.children.length; i++)
{
if (!isAuto(event.target.parentElement.parentElement.children[i]))
changeColor(event.target.parentElement.parentElement.children[i], "yellow");
}
changeColor(target.parentElement, "yellow");
this.userAnswer = answer;
},
showHintText: function()
{
this.showHintActive = !this.showHintActive;
},
submit : function()
{
this.submitted = true;
var elements = document.getElementById('choiceList').children[0].children;
var alphabet = "abcde";
correctChoiceIndex = alphabet.indexOf(this.correctAnswer);
for (var i = 0; i <elements.length; i++)
{
if (correctChoiceIndex==i)
forceChangeColor(elements[i], "green");
else{
if (this.choices[alphabet[i]]===this.userAnswer)
forceChangeColor(elements[i], "red")
}
elements[i].innerHTML += "<p>Rationale: " + this.choices[alphabet[i]].rationale.replace("<p>","").replace("</p>","") + "</p>";
}
}
}
,
created() {
//fetch("./question.json")
fetch( ("https://data-sat-origin.collegeboard.org/api/v1/views/qotd.json") )
.then(response => response.json())
.then(json => {
this.questionDate = json[0].date;
this.section = json[0].section;
if (this.section==="Math")
{
this.question = json[0].prompt;
this.sub_section = json[0].sub_section;
}
else
{
this.question = json[0].passage.body;
this.sub_section = json[0].skill;
}
this.difficulty = json[0].difficulty;
this.correctAnswer = json[0].answer.correct_choice;
this.hint = json[0].answer.hint.replace("<p>","").replace("</p>","");
this.choices = json[0].answer.choices; //choice[0][0]=Abody, choice[0][1] = Arationale
this.instructions += json[0].instructions[0].replace("<p>", "").replace("</p>", "")+"\n";
if (this.section==="Reading")
{
this.attribution = json[0].passage.attribution;
this.prompt = json[0].prompt;
var q = "<!DOCTYPE html><html><head></head><body><div class=\"FullQuestion\">" +
this.attribution.replace("<p>", "<p class=\"attribution\">") +
this.question.replace(/<p>/, "<br><p class=\"firstLine\"> " ).replace(/<p>/g, "</p>" +"<p class=\"everyLine\">" + " ").replace(/<\/p>/g, "</p>").replace("<p class=\"everyLine\"> Adapted from", "\n<p>Adapted from") + "</p><br>" +
this.prompt +
"</div></body></html>";
var doc = document.createElement( 'html' );
doc.innerHTML = q;
this.globalLines = questiontoLines(doc);
gLines = this.globalLines;
var newPrompt = this.attribution.replace("<p>", "<p class=\"attribution\">") + this.question.replace(/<p>/, "<br><p class=\"firstLine\"> " ).replace(/<p>/g, "</p>" +"<p class=\"everyLine\">" + " ").replace(/<\/p>/g, "</p>").replace("<p class=\"everyLine\"> Adapted from", "\n<p>Adapted from") + "</p><br>" + replaceQuestionLines(this.prompt);
this.question = newPrompt;
}
if (!(this.sub_section === "") && !(this.sub_section===undefined))
{
this.sub_section = " (" + this.sub_section + ")";
}
})
}
})
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</body>
</html>