-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
393 lines (347 loc) · 13.8 KB
/
index.html
File metadata and controls
393 lines (347 loc) · 13.8 KB
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
<!-- mobile client meta data -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" href="style/images/icon.png"/>
<title>Flashcards</title>
<meta property="og:type" content="website"/>
<meta property="og:title" content="Custom \"Smart\" Flashcards"/>
<meta property="og:description" content="A tool for serving and ordering flashcards based on how well you've memorized their content."/>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@Colarusso">
<meta name="twitter:creator" content="@Colarusso">
<meta name="twitter:title" content="Custom \"Smart\" Flashcards">
<meta name="twitter:description" content="A tool for serving and ordering flashcards based on how well you've memorized their content.">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-120057393-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-120057393-1');
</script>
<!-- jQuery Mobile scripts and style Sheets -->
<link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(document).on("mobileinit", function () {
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
});
</script>
<script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="style/custom.min.0.1.css" />
<!-- jQuery settings -->
<script type="text/javascript">
// set default transition
$.mobile.defaultPageTransition = 'slide';
$(document).ready(function() {
// avoid caching ajax pages in jquery
$.ajaxSetup({ cache: false });
});
</script>
<style>
.card {
font-size:36px;
text-align:center;
min-height: calc(100vh - 115px);
}
</style>
</head>
<body id="body" onLoad="loadCookies();">
<div data-role="page" id="settings">
<div data-role="header" data-id="myheader" data-theme="b">
<a href="#info" data-iconpos="notext" data-icon="info" data-transition="slide" data-direction="reverse"></a>
<h1>Flashcards (settings)</h1>
<a href="#" onClick="saveCookies();i = 0;load_card('front','slide')" data-iconpos="notext" data-icon="home" data-transition="slide" class="ui-btn-right"></a>
</div><!-- /header -->
<div id="settings_content" data-role="content" style="text-align:left;" >
<b>API Key</b> <input id="key" type=text value="">
<b>Base ID</b> <input id="base" type=text value="">
<b>Table Name</b> <input id="table" type=text value="">
<b>Cooling Off</b></br>The minimum number of of questions a card should sit out of rotation (must be fewer than the total number of cards).<input id="timeout" type=text value="10">
<input type=button value="Save & Sync" onClick="saveCookies();i = 0;load_card('front','slide')">
</div>
</div>
<div data-role="page" id="front">
<div class="ui-header ui-bar-b" data-role="header" data-id="myheader" data-theme="b">
<a href="#settings" class="ui-link ui-btn-left ui-btn ui-icon-gear ui-btn-icon-notext ui-shadow ui-corner-all" data-iconpos="notext" data-icon="gear" data-direction="reverse" data-transition="slide"></a>
<h1 class="ui-title">Front (<span id="con1">50</span>%)</h1>
</div>
<div id="front_content" data-role="content" class="card ui-content" onClick="$('#myfooter').hide();load_card('back','flip');setTimeout(function(){$('#myfooter').show()},400);">
</div>
</div>
<div data-role="page" id="back">
<div data-role="header" data-id="myheader" data-theme="b">
<h1>Back (<span id="con2">50</span>%)</h1>
</div>
<div id="back_content" data-role="content" class="card" onClick="$('#myfooter').hide();$.mobile.changePage('#front', { transition: 'flip',reverse: true});">
</div>
<div id="myfooter" data-role="footer" data-id="myfooter" data-position="fixed" data-tap-toggle="false" class="nav-glyphish-example" style="display:none;" data-theme="b">
<div data-role="navbar" data-grid="a">
<ul>
<li><a href="#" id="voteup" data-icon="custom" onClick="write_card(1,0);">Knew It</a></li>
<li><a href="#" id="votedown" data-icon="custom" onClick="write_card(0,1);">Didn't Know it</a></li>
</ul>
</div>
</div>
</div>
<div data-role="page" id="info">
<div data-role="header" data-id="myheader" data-theme="b">
<h1>About</h1>
<a href="#settings" data-iconpos="notext" data-icon="carat-r" data-transition="slide" class="ui-btn-right"></a>
</div>
<div id="settings_content" data-role="content" style="text-align:left;" >
<h3>Overview</h3>
This web app turns spreadsheets into virtual flashcards. All you have to do is: (1) make a spreadsheet with columns for the "front" and "back" of your cards; (2) add your content as rows to the sheet; (2) link that sheet to the web app; and (3) work your way through the cards. You can find more context and instructions in the <a href="https://github.com/colarusso/flashcards/blob/master/README.md#context--backstory" target="_blank">README</a> file for this project's <a href="https://github.com/colarusso/flashcards" target="_blank">GitHub repo</a>.
<h3>Credits</h3>
<p>This tool was designed and built by <a href="https://twitter.com/colarusso" target="_blank">@Colarusso</a>.</p>
<p> The thumbs up and arrow buttons you see when "voting," as well as in the homescreen icon, are the work of <a href="https://thenounproject.com/term/thumb-up/83151/" target="_blank">Antar</a>, <a href="https://thenounproject.com/term/arrow/37752/" target="_blank">Julien Miclo</a>, and <a href="https://thenounproject.com/term/e-learning/62522" target="_blank">Attilio Baghino</a> over at the Noun Project.
</p>
<h3>Privacy</h3>
<p>
We make use of Google Analytics to track visitor statistics, this includes the use of cookies. See <a href="https://policies.google.com/technologies/partner-sites">How Google uses data when you use our partner's sites or apps</a> (e.g., this site). We do not track the content of your spreadsheets. However, that data is stored with Airtable, and your use of Airtable is subject to their terms of service. Additionally, this site is hosted as a GitHub Page and presumably GitHub maintains associated server logs.
</p>
</div>
</div>
<!-- Include Dependency Scripts -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.min.js"></script>
<script type="text/javascript">
var debug = 0;
var work = 0;
var bscore = "";
var font = "";
var back = "";
var ups = 0;
var downs = 0;
var record = "";
var i = 0;
var afew = (new Date).getTime();
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function loadCookies() {
if (readCookie("key")) {
$("#key").val(readCookie("key"));
}
if (readCookie("base")) {
$("#base").val(readCookie("base"));
}
if (readCookie("table")) {
$("#table").val(readCookie("table"));
}
if (readCookie("timeout")) {
$("#timeout").val(readCookie("timeout"));
}
}
function saveCookies() {
key = $("#key").val().trim();
base = $("#base").val().trim();
table = $("#table").val().trim();
timeout = $("#timeout").val();
createCookie("key",key,365*100);
createCookie("base",base,365*100);
createCookie("table",table,365*100);
createCookie("timeout",timeout,365*100);
}
function check_written(last) {
if (work == 0) {
load_card("front","slideup");
} else if (work == 1) {
if ($.mobile.loading().is(':hidden')) {
$.mobile.loading("show");
}
apicall = "https://api.airtable.com/v0/"+app_id+"/"+table+"/?filterByFormula=AND((RECORD_ID() = '"+record+"'),({last}<='"+last+"'))"
axios.get(
apicall,
{
headers: { Authorization: "Bearer "+ app_key }
}
).then(function(response){
if (debug==1) {
console.log("---Write Check---");
console.log(apicall);
}
if (response.data.records[0] != undefined) {
if (debug==1) {
console.log("Write Check: Pass");
console.log(response);
}
work = 0;
check_written();
} else {
if (debug==1) {
console.log("Write Check: Pending");
console.log(response);
}
setTimeout(function () {
check_written(last);
}, 100);
}
}).catch(function(error){
console.log(error)
//work = -1;
alert("There was a problem contacting your Airtable. ("+error+")");
$.mobile.loading("hide");
check_written(last);
})
}
}
function load_api_data(target) {
var r = $.Deferred();
app_id = $("#base").val().trim();
app_key = $("#key").val().trim();
table = $("#table").val().trim();
record = $("#record").val();
work = 1;
if (target == "#front") {
apicall = "https://api.airtable.com/v0/"+app_id+"/"+table+"/?sort[0][field]=score&sort[0][direction]=asc&sort[1][field]=random&filterByFormula=({last}<="+afew+")&limit=1";
}
axios.get(
apicall,
{
headers: { Authorization: "Bearer "+ app_key }
}
).then(function(response){
self.items = response.data.records;
if (debug==1) {
console.log("---Load Card---");
console.log(apicall);
console.log("ID: "+self.items[0]['id']);
console.log("Front: "+self.items[0]['fields']['front']);
console.log("Back: "+self.items[0]['fields']['back']);
console.log("Score: "+self.items[0]['fields']['score']);
console.log(response);
}
record = self.items[0]['id'];
if (self.items[0]['fields']['up'] == undefined) {
ups_r = "0";
} else {
ups_r = self.items[0]['fields']['up'];
}
if (self.items[0]['fields']['down'] == undefined) {
downs_r = "0";
} else {
downs_r = self.items[0]['fields']['down'];
}
if (self.items[0]['fields']['score'] == undefined) {
bscore = "50";
} else {
bscore = self.items[0]['fields']['score'];
}
front = self.items[0]['fields']['front'];
back = self.items[0]['fields']['back'];
if ( /^http.*(\.gif|\.png|\.jpg|\.jpeg)$/.test( front.trim() ) ) {
front = "<img src=\""+front+"\" width=\"100%\"/>";
}
if ( /^http.*(\.gif|\.png|\.jpg|\.jpeg)$/.test( back.trim() ) ) {
back = "<img src=\""+back+"\" width=\"100%\"/>";
}
$("#con1").html(bscore);
$("#front_content").html(front);
work = 0;
}).catch(function(error){
console.log(error);
if (error.response.status == 422) {
alert("Make sure your table has the following columns: front, back, up, down, last, and random. Note: RANDOM is a new column as of 6/3/18. Users of this web app who set things up prior to the 3rd will need to update their tables by adding a text field named \"random.\" ("+error+")");
} else {
alert("Make sure your key and base info are correct and that your cooling-off is less than your total number of cards. ("+error+")");
}
work = -1;
$.mobile.loading("hide");
afew = (new Date).getTime();
console.log(last)
$.mobile.changePage($('#settings'), { transition: "slide", reverse: "true"})
})
return r;
}
function load_card(side,transition) {
if ($("#key").val() && $("#base").val() && $("#table").val() && $("#timeout").val()) {
if (side=="back") {
$("#con2").html(bscore);
$("#back_content").html(back);
go_to(side,transition);
} else if (side=="front") {
load_api_data("#"+side).done( go_to(side,transition) ); // h/t https://multiplestates.wordpress.com/2014/12/04/calling-one-jquery-function-only-after-another-function-has-run/
}
} else {
alert("You can't leave any of these fields blank.");
}
}
function go_to(side,transition) {
if (work == 0) {
$.mobile.changePage($('#'+side), { transition: transition})
} else if (work == 1) {
if ($.mobile.loading().is(':hidden')) {
$.mobile.loading("show");
}
setTimeout(function () {
go_to(side,transition);
}, 1);
} else {
work = 0;
}
}
function write_card(up,down) {
app_id = $("#base").val().trim();
app_key = $("#key").val().trim();
table = $("#table").val().trim();
apicall = "https://api.airtable.com/v0/"+app_id+"/"+table+"/"+record;
ups = Number(up) + Number(ups_r);
downs = Number(down) + Number(downs_r);
votes = Number(ups) + Number(downs);
score = Math.round(((Number(ups) + 2)/(votes + 4))*100);
$("#con1").html(score)
$("#con2").html(score)
i++
if (i >= $("#timeout").val()) {
afew = (new Date).getTime();
i = 0;
}
last = (new Date).getTime();
work = 1;
axios.patch(
apicall,
{ "fields": { "up": ups, "down": downs, "score": score, "last": last, "random": Math.random().toString(36).substring(2, 3) }},
{
headers: { Authorization: "Bearer "+ app_key}
}
).then(function(response){
if (debug==1) {
console.log("---Write Data---");
console.log(apicall);
console.log("New Score: "+score);
console.log(response);
}
check_written(last);
}).catch(function(error){
console.log(error)
$.mobile.loading("hide");
alert("There was a problem writing to your Airtable. ("+error+")");
check_written(last);
})
}
</script>
</body>
</html>