add opds fetching

master
Adam Undus 2020-10-14 17:03:50 -04:00
parent e61f6f4ca2
commit c057e7b42d
1 changed files with 13 additions and 3 deletions

View File

@ -1,13 +1,23 @@
const displayUsingApi = false; const displayUsingApi = true;
(function ($) { (function ($) {
if (displayUsingApi) { if (displayUsingApi) {
// TODO // TODO
const list = JSON.parse(localStorage.getItem('booklist'))
console.log(list)
const body = $('#book-list')
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')
})
} else { } else {
const list = JSON.parse(localStorage.getItem('booklist')) const list = JSON.parse(localStorage.getItem('booklist'))
console.log(list) console.log(list)
const body = $('#book-list') const body = $('#book-list')
console.log()
Object.keys(list).forEach((bookId) => { Object.keys(list).forEach((bookId) => {
console.log(bookId) console.log(bookId)
@ -15,7 +25,7 @@ const displayUsingApi = false;
}) })
} }
function makeListItem (book) { function makeListItem(book) {
const a = `<a href="${book.url}"><h3>${book.title}</h3></a>` 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></li>` const li = `<li><div class="list-item"><img src="${book.imgSrc}"/>${a}<span>Author: ${book.author}</span><div></li>`
console.log(li) console.log(li)