-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSidebar.html
568 lines (498 loc) · 18.1 KB
/
Sidebar.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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit.min.css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.4.1/github-markdown.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/github-gist.min.css" />
<style>
.cardsList
{
overflow: scroll;
margin: 0px;
padding: 0px;
}
.cardItem
{
border-style: solid;
border-width: 1px;
font-size: 18px;
padding: 5px;
list-style-type: none;
}
.htmlPreview
{
overflow: scroll;
}
#app
{
display: grid;
height: 100vh;
max-width: 100vw;
grid-template-columns: 100%;
grid-template-rows: 1fr 12fr 6fr 1fr;
}
.centeredContent
{
display: flex;
flex-direction: column;
align-content: space-evenly;
justify-content: space-evenly;
max-width: 100vw;
padding: 0px 5px 0px 5px;
}
.alignedHorizontally
{
display: flex;
flex-direction: row;
align-content: space-evenly;
justify-content: space-evenly;
max-width: 100vw;
padding: 0px 5px 0px 5px;
}
.topp
{
grid-row-start: 1;
grid-row-end: 1;
padding: 5px;
margin: 5px;
}
.cardscontainer
{
grid-row-start: 2;
grid-row-end: 2;
padding: 0px 5px 0px 5px;
overflow: scroll;
max-width: 100vw;
}
.selectedcard
{
grid-row-start: 3;
grid-row-end: 3;
overflow: scroll;
padding: 0px 5px 0px 5px;
}
.bottomButtonBar
{
grid-row-start: 4;
grid-row-end: 4;
padding: 5px;
margin: 5px;
}
.monospace
{
overflow: scroll;
}
.monospace h1
{
font-family: monospace; font-size: 24px; font-style: normal; font-variant: normal; font-weight: 700; line-height: 26.4px;
}
.monospace h3
{
font-family: monospace; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 700; line-height: 15.4px;
}
.monospace h4
{
font-family: monospace; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 700; line-height: 13.4px;
}
.monospace p
{
font-family: monospace; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; line-height: 12px;
}
.monospace blockquote
{
font-family: monospace; font-size: 21px; font-style: normal; font-variant: normal; font-weight: 400; line-height: 30px;
}
.monospace pre
{
font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400; line-height: 12.5714px; }
}
.monospace ul
{
font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400;}
}
.monospace li
{
font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400; }
}
.monospace li li
{
font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400;}
}
.monospace li li li
{
font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400;}
}
.monospace li li li li
{
font-family: monospace; font-size: 13px; font-style: normal; font-variant: normal; font-weight: 400;}
}
.monospace ul, ol, li
{
padding: 0;
margin: 0;
line-height: 0;
}
#cards .ui-selecting { background: #FECA40; }
#cards .ui-selected { background: #FFC678; }
</style>
</head>
<div v-cloak id="app">
<div class="topp">
<div class="centeredContent">
<button :disabled="progress>=0" class="blue" id="refresh">Find cards</button>
<progress v-if="progress > 0" id="progressbar" class="uk-progress" :value="progress" min="0" max="100" style="margin: 5px 0px 5px 0px; padding: 1px;"></progress>
<p style="margin:5px; padding:0px;" v-if="status"> {{ status }} </p>
</div>
</div>
<div class="cardscontainer">
<!--ul id="cards" class="cardsList"/-->
<table v-if="cards.length>0" id="cards" style="margin:5px;padding:0px;" class="uk-table uk-table-small uk-table-hover">
<thead>
<tr>
<th>Front</th>
</tr>
</thead>
<tbody id="table-body">
<tr v-for="item in cards" @click="selectCard(item)">
<td>{{ item.front }}</td>
</tr>
</tbody>
</table>
</div>
<div class="selectedcard">
<hr v-if="selectedCard" style="margin:0;padding:0px;">
<h4 class="monospace" style="margin:0;padding:5px;" v-if="selectedCard">{{ selectedCard.front }}</h4>
<div v-if="selectedCard" class="monospace" v-html="selectedCard.html"></div>
</div>
<div class="bottomButtonBar">
<div class="alignedHorizontally">
<button v-if="exportEnabled" @click="downloadApkg()" class="blue" id="export">Download .apgk</button>
<button v-if="exportEnabled" @click="downloadCsv()" class="blue" id="export">Download zipped .csv</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script>
<!-- Please replace the src below with the URL to a hosted bundle.js -->
<script src="[URL TO REACH bundle.js]"></script>
<script>
$(function() {
$('#refresh').click(findFlashcards);
});
var app = new Vue({
el: '#app',
data:
{
status: "",
progress: -1, // < 0 == hidden
cards: [],
selectedCard: null,
exportEnabled: false
},
methods:
{
selectCard:function(card)
{
app.selectedCard = card;
},
exportToGoogleDrive()
{
app.status = "Exporting to Drive...";
google.script.run
.withSuccessHandler(onExportSuccess)
.withFailureHandler(onExportFailed)
.exportToGoogleDrive({cards: flashCards, images:imagesJson});
},
downloadApkg()
{
// add cards
//var formats = [ ankiFrontTemplate, ankiBackTemplate, ankiCss];
//var json = JSON.stringify(formats);
//console.log(json);
//var ankiTemplate = new AppLib.Template({questionFormat: ankiFrontTemplate, answerFormat: ankiBackTemplate, css: ankiCss});
//console.log(ankiTemplate);
var apkg = new AppLib.AnkiExport(deckName);
for(var i=0;i<flashCards.length;i++)
{
var card = card = flashCards[i];
apkg.addCard(card.front, card.html);
}
// add images to anki package
for(var j=0;j<images.length;j++)
{
var image = images[j];
var imgBlob = base64toBlob(image.data, image.type);
apkg.addMedia(image.name, imgBlob);
}
apkg
.save()
.then(zip =>
{
saveAs(zip, deckName + ".apkg");
app.status = ".apkg file generated!";
})
// .catch(err > console.log(err.stack || err));
},
downloadCsv()
{
var csv = createCsvFromCards(flashCards);
var zip = new AppLib.JSZip();
zip.file(deckName + ".csv", csv);
for(var i=0;i<images.length;i++)
{
var imgBlob = base64toBlob(images[i].data, images[i].type);
zip.file(images[i].name, imgBlob);
}
zip.generateAsync({type:"blob"})
.then(function(content) {
// see FileSaver.js
saveAs(content, deckName +".zip");
});
}
}
});
var deckName = "";
var flashCards = [];
var images;
var imagesJson;
var timer;
/* function exportToGoogleDrive()
{
app.status = "Exporting to Drive...";
google.script.run
.withSuccessHandler(onExportSuccess)
.withFailureHandler(onExportFailed)
.exportToGoogleDrive({cards: flashCards, images:images});
}*/
function onExportSuccess()
{
app.status = "Files exported to Drive!";
}
function onExportFailed()
{
app.status = "Export failed!";
}
function findFlashcards()
{
app.cards = [];
app.selectedCard = null;
app.exportEnabled = false;
app.progress = 0;
app.status = "Scanning document";
google.script.run
.withSuccessHandler(onFlashcardsFound)
.withFailureHandler(onNoFlashcardsFound)
.extractHtmlCardsFromDocument();
timer = setInterval(function()
{
google.script.run
.withSuccessHandler(function(status)
{
if(status.total != "unknown" && app.progress >= 0)
{
app.progress = (status.current/status.total)*100.0;
app.status = "Processing card: " + status.current + " of " + status.total;
}
})
.readStatusFromCache();
}, 500);
}
function onNoFlashcardsFound()
{
app.status = "No cards found in document";
app.progress = -1;
app.exportEnabled = false;
clearInterval(timer);
}
function onFlashcardsFound(cardsAndImages)
{
// stop status update timer
clearInterval(timer);
// update status text and progress bar
app.status = "";
app.progress = -1;
deckName = cardsAndImages.deckName;
flashCards = cardsAndImages.cards;
app.cards = flashCards;
imagesJson = cardsAndImages.images;
images = JSON.parse(imagesJson);
app.selectedCard = flashCards[0];
app.exportEnabled = true;
}
function base64toBlob(base64Data, contentType)
{
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex)
{
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset)
{
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
function createCsvFromCards(cards)
{
var output = [];
for(var i=0;i<cards.length;i++)
{
output.push(cards[i].front);
output.push('§');
output.push(cards[i].html);
output.push("\n\n");
}
return output.join('');
}
/**
* Inserts a div that contains an error message after a given element.
*
* @param msg The error message to display.
* @param element The element after which to display the error.
*/
function showError(msg, element) {
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
}
var ankiFrontTemplate = `<div id="io-header">
<table>
</tr>
<th>{{Image1}}</th>
<th>{{Image2}}</th>
<tr>
</table>
{{Framsida}}
</div>
<br>
<span class="timer" id="s2" style="font-size:16px; color: #A6ABB9;"></span>
<script>
function countdown( elementName, minutes, seconds )
{
var element, endTime, hours, mins, msLeft, time;
function twoDigits( n )
{
return (n <= 9 ? "0" + n : n);
}
function updateTimer()
{
msLeft = endTime - (+new Date);
if ( msLeft < 1000 ) {
element.innerHTML = "<span style='color:#CC5B5B'>ÖKA!</span>";
} else {
time = new Date( msLeft );
hours = time.getUTCHours();
mins = time.getUTCMinutes();
element.innerHTML = (hours ? hours + ':' + twoDigits( mins ) : mins) + ':' + twoDigits( time.getUTCSeconds() );
setTimeout( updateTimer, time.getUTCMilliseconds() + 500 );
}
}
element = document.getElementById( elementName );
endTime = (+new Date) + 1000 * (60*minutes + seconds) + 500;
updateTimer();
}
countdown("s2", 0, 15 ); //2nd value is the minute, 3rd is the seconds
<\/script>`;
var ankiBackTemplate = `{{FrontSide}}
{{Baksida}}
<br>
{{#Extra 1}}
Alt:
<hr>
{{/Extra 1}}
{{Extra 1}}
<span class="timer" id="s2" style='font-size:16px; color: #A6ABB9;'></span>
<script>
function countdown( elementName, minutes, seconds )
{
var element, endTime, hours, mins, msLeft, time;
function twoDigits( n )
{
return (n <= 9 ? "0" + n : n);
}
function updateTimer()
{
msLeft = endTime - (+new Date);
if ( msLeft < 1000 ) {
element.innerHTML = "<span style='color:#CC5B5B'>skynda på, inte maska så!</span>";
} else {
time = new Date( msLeft );
hours = time.getUTCHours();
mins = time.getUTCMinutes();
element.innerHTML = (hours ? hours + ':' + twoDigits( mins ) : mins) + ':' + twoDigits( time.getUTCSeconds() );
setTimeout( updateTimer, time.getUTCMilliseconds() + 500 );
}
}
element = document.getElementById( elementName );
endTime = (+new Date) + 1000 * (60*minutes + seconds) + 500;
updateTimer();
}
countdown("s2", 0, 15 ); //2nd value is the minute, 3rd is the seconds
<\/script>`;
var ankiCss = `html { overflow: scroll; overflow-x: hidden; }
/* CONTAINER FOR YOUR CARDS */
#kard {
padding: 0px 0px;
max-width: 700px; /* CHANGE CARD SIZE HERE */
margin: 0 auto; /* CENTERS THE CARD IN THE MIDDLE OF THE WINDOW */
word-wrap: break-word; /* BREAKS UP LONG WORKS */
}
/* APPLIES TO THE WHOLE CARD */
.card {
font-family: Menlo, baskerville, sans;
font-size: 18px; /* FONT SIZE */
text-align: left; /* ALIGN TEXT */
color: #D7DEE9; /* FONT COLOR */
line-height: 1.6em;
background-color: #333B45; /* BACKGROUND COLOR */
}
/* STYLE FOR CLOZE DELETIONS */
.cloze, .cloze b, .cloze u, .cloze i { font-weight: bold; color: MediumSeaGreen !important;}
/* STYLE FOR EXTRA PORTION ON BACK OF CARD */
#extra, #extra i { font-size: 15px; color:#D7DEE9; font-style: italic; }
/* STYLE TAGS TO APPEAR WHEN HOVERING OVER TOP OF CARD */
.tags {
color: #A6ABB9;
opacity: 0;
font-size: 10px;
width: 100%;
text-align: center;
text-transform: uppercase;
position: fixed;
padding: 0;
top:0;
right: 0;}
.tags:hover { opacity: 1; position: fixed;}
/* Colors for typed answer comparison */
.typeGood { background: green; }
.typeBad { background: blue; }
.typeMissed { background: red; }
/* IMAGE STYLE */
img { display: block; max-width:80%; max-height:80vh; margin-left: auto; margin: 10px auto 10px auto;}
img:active { width: 50%; max-height: 50% }
tr {font-size: 12px; }
/* COLOR ACCENTS FOR BOLD-ITALICS-UNDERLINE */
b { color: #C695C6 !important; } /* BOLD STYLE */
u { text-decoration: none; color: #5EB3B3;} /* UNDERLINE STYLE */
i { color: IndianRed; } /* ITALICS STYLE */
a { color: LightGray !important; text-decoration: none; font-size: 10px; font-style: normal; } /* LINK STYLE */
/* ADJUSTMENT FOR MOBILE DEVICES */
.mobile .card { color: #D7DEE9; background-color: #333B45; }
.mobile .tags:hover { opacity: 1; position: relative;}
.mobile .card img:active { width: inherit; max-height: none;}`;
</script>
</div>
</html>