-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
430 lines (379 loc) · 16.2 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Alther Alves">
<title>Annota</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.2/font/bootstrap-icons.css">
<link href="assets/css/annota.css" rel="stylesheet">
</head>
<body class="bg-light">
<ul class="list-group" id="year-list"></ul>
<!-- Back to top button -->
<button onclick="topFunction()" id="buttonTop" title="Go to top">
<i class="bi bi-arrow-up-circle-fill"></i>
Top
</button>
<!-- Header -->
<div>
<header class="navbar bd-header bg-gradient py-3 d-flex align-items-stretch" style='background-color: #FFAD06;'>
<div class="container-fluid d-flex align-items-center">
<nav class="navbar-brand container bd-gutter flex-wrap flex-lg-nowrap" aria-label="Main navigation">
<h1 class="align-items-center text-dark fs-2 mt-2 mb-0 fw-bolder">
<i class="bi bi-book pe-3"></i>
Annota
</h1>
<p class="text-white">
What I've been reading
</p>
<p class="text-white" style="font-size: 14px;">
Updated
<span id="updated_at"></span>
</p>
</nav>
<form class="d-flex" role="search" id="formSearch">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-sm btn-outline-success" type="submit">Search</button>
</form>
</div>
</header>
</div>
<!-- Offcanvas: Highlights & Notes -->
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="nav nav-tabs">
<li class="nav-item">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Highlights & Notes</button>
</li>
<li class="nav-item">
<button class="nav-link" id="vocabulary-tab" data-bs-toggle="tab" data-bs-target="#vocabulary" type="button" role="tab" aria-controls="vocabulary" aria-selected="false">Vocabulary</button>
</li>
<li class="nav-item">
<button class="nav-link" id="idioms-tab" data-bs-toggle="tab" data-bs-target="#idioms" type="button" role="tab" aria-controls="idioms" aria-selected="false">Idioms</button>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab" tabindex="0">
<div id="highlightBody"></div>
</div>
<div class="tab-pane" id="vocabulary" role="tabpanel" aria-labelledby="vocabulary-tab" tabindex="0">
<ol class="list-group list-group-numbered" id="vocabularyBody">
</div>
<div class="tab-pane" id="idioms" role="tabpanel" aria-labelledby="idioms-tab" tabindex="0">
<div class="list-group" id="idiomBody"></div>
</div>
</div>
</div>
</div>
<main class="container mt-3">
<!-- Quotes -->
<div class="row">
<div id="carouselQuotes" class="carousel slide" data-bs-ride="true">
<div class="carousel-indicators" id="carouselIndicators"></div>
<div class="carousel-inner" id="carouselInner"></div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselQuotes" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselQuotes" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
<!-- Filters -->
<ul class="nav justify-content-center nav-pills bg-light shadow-sm m-2 sticky-top">
<li class="nav-item p-2" role="button">
<a id="all" class="nav-link" aria-current="true" onclick="mountAll(this)">All</a>
</li>
<li class="nav-item p-2" role="button">
<a id="progress" class="nav-link" aria-current="true" onclick="mountInProgress(this)">In Progress</a>
</li>
<li class="nav-item p-2" role="button">
<a id="finished" class="nav-link" aria-current="true" onclick="mountFinished(this)">Finished</a>
</li>
</ul>
<!-- Library -->
<div id="library" class="row">
</div>
</main>
<footer class="py-3 my-4 text-center border-top">
<p class="text-muted"><a href="#">Back to top</a></p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
<script type="text/javascript" src="data/ibook_history.js"></script>
<script type="text/javascript" src="assets/js/helper.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.6.2"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.29.3/moment.min.js"></script>
<script>
var global_year = moment().year();
$(function() {
main();
mountCarousel()
});
function main() {
$("#all").empty().append(`All (${allBooks().length})`);
$("#progress").empty().append(`In Progress (${inProgressBooks().length})`);
$("#finished").empty().append(`Finished (${finishedBooks().length})`);
$("#updated_at").empty().append('Updated '+moment(ibook_history.updated_at, "YYYY-MM-DD h:mm:ss -0700").fromNow());
mountAll();
mountYearList()
}
function mountCarousel() {
// If there's any note at all
if (!!booksWithNotes()) {
for (let i = 0; i < 6; i++) {
let book = getRandomBookWithNote();
$("#carouselInner").append(mountBigQuote(book.notes[0], book));
var indicator = `<button type="button" data-bs-target="#carouselQuotes" data-bs-slide-to="${i}" aria-label="Slide ${i}"></button>`;
$("#carouselIndicators").append(indicator);
}
$('#carouselInner > .carousel-item:first').addClass('active');
$('#carouselIndicators>button:first').addClass('active').attr('aria-current', true);
} else {
$('#carouselQuotes').remove();
}
}
function mountAll(element=null) {
$(element).tab('show');
// DOC: It wasnt clicked by the user.
let query
if (!element) {
query = (new URL(document.location)).searchParams.get('q');
if (!query) $('#all').tab('show');
}
mountLib(searchBooks(query));
}
function mountInProgress(element) {
$(element).tab('show');
mountLib(inProgressBooks());
}
function mountFinished(element) {
$(element).tab('show');
mountLib(finishedBooks());
}
function mountLib(books) {
$('#library').hide();
$('#library').empty();
for (var index=0; index < books.length; index++) {
$("#library").append(mountCard(books[index]));
}
$('#library').slideDown('slow');
}
function mountYearList() {
const start_year = 2022;
const total_years = (moment().year() - start_year) + 1;
const query = (new URL(document.location)).searchParams.get('year') || String(global_year);
let li_array = []
for(var i = 0; i < total_years; i++) {
const year = start_year+i
li_array.push(`
<li type="button" onclick="filterYear(${year})" class="fs-6 list-group-item ${(String(year)===query)? 'active' : ''}">
${year}
</li>
`);
}
li_array.push(
`<li type="button" onclick="filterYear('all');" class="fs-6 list-group-item" id='all_years'>All</li>`
)
$("#year-list").empty().append(li_array.reverse());
if (query==='all') $('#all_years').tab('show');
}
function notesCountTag(notesCounter) {
if (!notesCounter) return ''
return `<span class="badge text-wrap text-bg-secondary">${notesCounter} highlights</span>`
}
function langTag(lang) {
if (!lang) return ''
return `<span class="badge text-wrap text-secondary bg-white border-secondary">${lang.toUpperCase()}</span>`
}
function pageCountTag(pageCount) {
if (!pageCount) return ''
return `<span class="badge text-wrap text-secondary bg-white border-secondary">${pageCount} pages</span>`
}
function progressBar(percent, finished, hasNotes) {
if (!percent && !finished && !hasNotes) return ''
if (percent === 1 || finished === 1) {
return `<span class="badge text-bg-success">Finished</span>`
} else if (hasNotes && !percent) {
return `<span class="badge text-bg-primary">In Progress</span>`
} else {
return `
<p>
<div class="progress" style="height: 3px;">
<div class="progress-bar" role="progressbar" style="width: ${percent*100}%;" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</p>
`
}
}
function mountFakeCover(book) {
return `
<div class="card shadow-sm text-white bg-gradient" style="height: 380px; width: 250px;background-color:var(--bs-indigo);">
<div class="card-body">
<div class="card-body h-75">
<h5 class="card-title text-capitalize">${title(book)}</h5>
</div>
<div class="card-footer bg-transparent">
<p class="card-text text-capitalize">${author(book)}</p>
</div>
</div>
</div>
`
}
function displayCoverAndTitle(book){
var src = book?.cover?.src
if (!src) {
return mountFakeCover(book);
} else {
return `
<img src="${src}" class="card-img-top shadow border">
`
}
}
// Main Component
function mountCard(book) {
return `
<div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
<div class="card mb-3 mx-2 bg-light border-light">
<div class="card-body">
<div onclick="showHighlights('${book.book_id}')" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
${displayCoverAndTitle(book)}
</div>
<p class="fw-semibold text-capitalize">${shortTitle(book)}</p>
${progressBar(book.reading_progress, book.marked_as_finished, !!book.notes.length)}
${pageCountTag(book.page_count)}
${notesCountTag(book.notes.length)}
${langTag(book.lang)}
</div>
</div>
</div>
`
}
function mountIdiomItem(highlight) {
let idiom = highlight.text || highlight.sentence
let note = highlight.note || ''
if (note != '')
note = `<b>(${note})</b>`
return `
<li class="list-group-item">
<p class="mb-2">${idiom} ${note}</p>
</li>
`
}
function mountVocItem(highlight) {
let word = highlight.text || highlight.sentence
let definition = highlight.note || ''
if (definition != '') definition = ' - '+definition
return `
<li class="list-group-item">
<b class="text-capitalize">${word}</b>
${definition}
<span class="badge">
<a class="nav-link" href="https://www.dicio.com.br/${word}/" target='_blank'>
<i class="bi bi-box-arrow-up-right" style="font-size: 10px;"></i>
</a>
</span>
</li>
`
}
function mountHighlightItem(highlight) {
let className = HIGHLIGHTS[highlight.color];
let chapter = ''
if (highlight.chapter) chapter = `<p><small><span class="badge rounded-pill text-bg-dark">${highlight.chapter}</span></small></p>`
let note = ''
if (highlight.note) note = '- '+highlight.note
return `
<div class="alert ${className}">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">${note}</h5>
<small class="text-end">${moment(highlight.updated_at, "YYYY-MM-DD h:mm:ss -0700").fromNow()}</small>
</div>
${highlight.text || highlight.sentence}
${chapter}
</div>
`
}
function mountIdiomList(book) {
let notes = book.notes.filter(note => note.color == 0)
let items = notes.map(function(note){
return mountIdiomItem(note)
});
if (!items.length) return `<p>Nothing was found.</p>`
return (items).join('');
}
function mountHighlightList(book) {
let notes = book.notes.filter(note => note.color !== 0)
let items = notes.map(function(note){
return mountHighlightItem(note)
});
if (!items.length) return `<p>Nothing was found.</p>`
return (items).join('');
}
function mountVocList(book) {
let items = book.new_words.map(function(note){
return mountVocItem(note)
});
if (!items.length) return `<p>Nothing was found.</p>`
return (items).join('');
}
function showHighlights(bookId){
let book = bookByID(bookId);
$("#highlightBody").empty();
$('#highlightBody').append(mountHighlightList(book));
$("#vocabularyBody").empty();
$('#vocabularyBody').append(mountVocList(book));
$("#idiomBody").empty();
$('#idiomBody').append(mountIdiomList(book));
}
function mountBigQuote(note, book){
return `
<div class="carousel-item">
<div class="w-100 bg-success text-light text-wrap" alt="test" style="height: 300px;">
<figure class="position-absolute top-50 start-50 translate-middle">
<blockquote class='lead fs-5'>${note.text || note.sentence}</blockquote>
<figcaption class='fs-6 text-capitalize'>
${author(book)} <cite title="Source Title">(${title(book)})</cite>
</figcaption>
</figure>
</div>
</div>
`
}
function filterYear(value) {
global_year = value;
var location = document.location.href.replace(window.location.search, '');
var redirectTo = location + '?year=' + value;
history.pushState({}, null, redirectTo);
main();
}
$("#formSearch").submit(function( event ) {
var location = document.location.href.replace(window.location.search, '');
var redirectTo = location + '?q=' + $('#formSearch>input').val();
window.location.href = redirectTo;
event.preventDefault();
});
//Back to top button
buttonTop = document.getElementById("buttonTop");
window.onscroll = function() { scrollFunction() };
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
buttonTop.style.display = "block";
} else {
buttonTop.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
</body>
</html>