reading-lists/booklist.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-10-22 14:17:12 +00:00
const displayUsingApi = false;
2020-10-07 23:21:32 +00:00
(function ($) {
2020-10-14 14:13:32 +00:00
if (displayUsingApi) {
// TODO
2020-10-14 21:03:50 +00:00
const list = JSON.parse(localStorage.getItem('booklist'))
console.log(list)
const body = $('#book-list')
2020-10-07 23:21:32 +00:00
2020-10-14 21:03:50 +00:00
Object.keys(list).forEach((bookId) => {
console.log(bookId)
jQuery.get(`https://www.gutenberg.org/ebooks/${bookId}.opds`, null, (data, status, jqxhr) => { // eslint-disable-line
// TODO parse
console.log(data)
body.html(data)
}, 'text')
})
2020-10-14 14:13:32 +00:00
} else {
2020-10-08 00:55:50 +00:00
const list = JSON.parse(localStorage.getItem('booklist'))
console.log(list)
2020-10-14 14:13:32 +00:00
const body = $('#book-list')
2020-10-07 23:21:32 +00:00
2020-10-08 00:55:50 +00:00
Object.keys(list).forEach((bookId) => {
2020-10-14 14:13:32 +00:00
console.log(bookId)
body.append(makeListItem(list[bookId]))
})
}
2020-10-08 00:55:50 +00:00
2020-10-14 21:03:50 +00:00
function makeListItem(book) {
2020-10-14 14:13:32 +00:00
const a = `<a href="${book.url}"><h3>${book.title}</h3></a>`
const li = `<li><div class="list-item"><img src="${book.imgSrc}"/>${a}<span>Author: ${book.author}</span><div><div class="social-button booklist">
<button title="Add book to My Book List" id="add-to-booklist"
style="background-color: cornflowerblue;">+</button>
</div></li>`
2020-10-14 14:13:32 +00:00
console.log(li)
return li
}
})(jQuery) // eslint-disable-line