From 8790635973ec3228a9f80e45ae0f73ff5c1aeb20 Mon Sep 17 00:00:00 2001 From: Adam Undus Date: Wed, 7 Oct 2020 20:55:50 -0400 Subject: [PATCH] functional prototype --- booklist.html | 4 +- booklist.js | 15 + ebooks/2542.html | 943 +++++++++++++++++++++++++---------------------- ebooks/book.js | 57 +++ index.html | 6 +- 5 files changed, 584 insertions(+), 441 deletions(-) create mode 100644 ebooks/book.js diff --git a/booklist.html b/booklist.html index 8c5675b..e82dcdf 100644 --- a/booklist.html +++ b/booklist.html @@ -149,7 +149,9 @@

My Booklist

- My content +
diff --git a/booklist.js b/booklist.js index e0356c2..44a4eb9 100644 --- a/booklist.js +++ b/booklist.js @@ -1,5 +1,20 @@ (function ($) { + const list = JSON.parse(localStorage.getItem('booklist')) + console.log(list) + const body = $('#book-list'); + console.log() + Object.keys(list).forEach((bookId) => { + console.log(bookId) + body.append(makeListItem(list[bookId])); + }); + + function makeListItem(book) { + const a = `

${book.title}

`; + const li = `
  • ${a}Author: ${book.author}
  • `; + console.log(li) + return li; + } })(jQuery); \ No newline at end of file diff --git a/ebooks/2542.html b/ebooks/2542.html index ce909ff..97ce531 100644 --- a/ebooks/2542.html +++ b/ebooks/2542.html @@ -1,445 +1,514 @@ - - - + DON'T USE THIS PAGE FOR SCRAPING. + Seriously. You'll only get your IP blocked. + Read http://www.gutenberg.org/feeds/ to learn how to download Project + Gutenberg metadata much faster than by scraping. + --> + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -A Doll's House : a play by Henrik Ibsen - Free Ebook - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A Doll's House : a play by Henrik Ibsen - Free Ebook + + + + -
    - -
    - -

    A Doll's House : a play by Henrik Ibsen

    -
    -
    -
    -
    -
    -Book Cover -
    -
    - -
    -
    - -
    -
    -
    -
    -
    -
    -

    Download This eBook

    - --------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Format - -UrlSize - - - - - -
    Read this book online: HTMLhttps://www.gutenberg.org/files/2542/2542-h/2542-h.htm253 kB - - - -
    EPUB (with images)https://www.gutenberg.org/ebooks/2542.epub.images112 kB - - - - - -
    EPUB (no images)https://www.gutenberg.org/ebooks/2542.epub.noimages112 kB - - - - - -
    Kindle (with images)https://www.gutenberg.org/ebooks/2542.kindle.images490 kB - - - - - -
    Kindle (no images)https://www.gutenberg.org/ebooks/2542.kindle.noimages490 kB - - - - - -
    Plain Text UTF-8https://www.gutenberg.org/ebooks/2542.txt.utf-8162 kB - - -
    More Files…https://www.gutenberg.org/files/2542/
    -
    -
    - -
    -
    -

    Bibliographic Record - -

    - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Author -Ibsen, Henrik, 1828-1906
    Uniform Title -Et dukkehjem. English -
    Title -A Doll's House : a play -
    Note -Translation of: Et dukkehjem -
    LanguageEnglish
    LoC Class -PT: Language and Literatures: Germanic, Scandinavian, and Icelandic literatures -
    Subject - -Marriage -- Drama - -
    Subject - -Man-woman relationships -- Drama - -
    Subject - -Norwegian drama -- Translations into English - -
    Subject - -Wives -- Drama - -
    CategoryText
    EBook-No.2542
    Release Date
    Copyright StatusPublic domain in the USA.
    Downloads27056 downloads in the last 30 days.
    Price$0.00
    -
    -
    -
    -
    -
    -
    - - -
    +
    + +
    + +

    A Doll's House : a play by Henrik Ibsen

    +
    +
    +
    +
    +
    + Book Cover +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    +

    Download This eBook

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Format + + + UrlSize + + + + + + + + +
    Read this book online: HTML + https://www.gutenberg.org/files/2542/2542-h/2542-h.htm253 kB + +
    EPUB (with images)https://www.gutenberg.org/ebooks/2542.epub.images112 kB + + + + + +
    EPUB (no images)https://www.gutenberg.org/ebooks/2542.epub.noimages112 kB + + + + + +
    Kindle (with images) + https://www.gutenberg.org/ebooks/2542.kindle.images490 kB + + + + + +
    Kindle (no images)https://www.gutenberg.org/ebooks/2542.kindle.noimages490 kB + + + + + +
    Plain Text UTF-8https://www.gutenberg.org/ebooks/2542.txt.utf-8162 kB
    More Files…https://www.gutenberg.org/files/2542/
    +
    +
    + + + +
    +
    +

    Bibliographic Record + + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Author + Ibsen, Henrik, 1828-1906 +
    Uniform Title + Et dukkehjem. English +
    Title + A Doll's House : a play +
    Note + Translation of: Et dukkehjem +
    LanguageEnglish
    LoC Class + PT: Language and Literatures: Germanic, Scandinavian, and Icelandic + literatures +
    Subject + + Marriage -- Drama + +
    Subject + + Man-woman relationships -- Drama + +
    Subject + + Norwegian drama -- Translations into English + +
    Subject + + Wives -- Drama + +
    CategoryText
    EBook-No.2542
    Release Date
    Copyright StatusPublic domain in the USA.
    Downloads27056 downloads in the last 30 days.
    Price$0.00
    +
    +
    +
    +
    +
    +
    + + +
    + + \ No newline at end of file diff --git a/ebooks/book.js b/ebooks/book.js new file mode 100644 index 0000000..57cf919 --- /dev/null +++ b/ebooks/book.js @@ -0,0 +1,57 @@ +(function ($) { + const addbtn = $('#add-to-booklist'); + const url = window.location && window.location.toString().split('/'); + const bookId = url[url.length - 1].match(/(\d+)/)[0]; + + if (JSON.parse(localStorage.getItem('booklist'))[bookId]) { + // book already in list + addbtn.html('Remove book from My Book List') + addbtn.css("background-color", "indianred"); + addbtn.addClass('book-in-list') + } + + + addbtn.on('click', function (event) { + if (addbtn.hasClass('book-in-list')) { + removeBook(); + return; + } + // add book to list + let author = ''; + $("tbody>tr").each(function (index) { + const row = $(this) + const rowTitle = row.find('th:first').html(); + if (rowTitle === 'Author') { + const tableRow = row.find('td:first') + author = tableRow.find('a:first').html(); + } + }); + const bookData = { + title: $('h1').html(), + bookId: bookId, + imgSrc: $('img.cover-art').attr('src'), + author: author, + url: window.location + }; + + const newList = { ...JSON.parse(localStorage.getItem('booklist')) }; + newList[bookId] = bookData; + addbtn.addClass('book-in-list') + addbtn.html('Remove book from My Book List') + addbtn.css("background-color", "indianred") + + localStorage.setItem('booklist', JSON.stringify(newList)); + console.log(localStorage.getItem('booklist')); + }); + + function removeBook() { + const newlist = JSON.parse(localStorage.getItem('booklist')) + delete newlist[bookId] + localStorage.setItem('booklist', JSON.stringify(newlist)); + console.log(localStorage.getItem('booklist')); + addbtn.removeClass('book-in-list') + addbtn.html('Add to My Book List') + addbtn.css("background-color", "cornflowerblue") + } + +})(jQuery); diff --git a/index.html b/index.html index 391758a..002f3a5 100644 --- a/index.html +++ b/index.html @@ -198,7 +198,7 @@ which contains *all* Project Gutenberg metadata in one RDF/XML file. -