add eslint and change button
parent
0e688ad2e9
commit
dda626b29c
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": [
|
||||
"standard"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12
|
||||
},
|
||||
"rules": {
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
*node_modules*
|
24
booklist.js
24
booklist.js
|
@ -1,20 +1,24 @@
|
|||
const displayUsingApi = false;
|
||||
(function ($) {
|
||||
if (displayUsingApi) {
|
||||
// TODO
|
||||
|
||||
} else {
|
||||
const list = JSON.parse(localStorage.getItem('booklist'))
|
||||
console.log(list)
|
||||
const body = $('#book-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 = `<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>`;
|
||||
console.log(li)
|
||||
return li;
|
||||
body.append(makeListItem(list[bookId]))
|
||||
})
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
function makeListItem(book) {
|
||||
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>`
|
||||
console.log(li)
|
||||
return li
|
||||
}
|
||||
})(jQuery) // eslint-disable-line
|
||||
|
|
|
@ -204,6 +204,12 @@ Gutenberg metadata much faster than by scraping.
|
|||
<a onclick="printpage()" title="Print this page"><span
|
||||
class="icon icon_print"></span></a>
|
||||
</li>
|
||||
<li>
|
||||
<div class="social-button booklist">
|
||||
<button title="Add book to My Book List" id="add-to-booklist"
|
||||
style="background-color: cornflowerblue;">+</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="qr">
|
||||
|
@ -215,10 +221,10 @@ Gutenberg metadata much faster than by scraping.
|
|||
<div id="download">
|
||||
<div about="[ebook:1661]" rel="dcterms:hasFormat">
|
||||
<h2>Download This eBook</h2>
|
||||
<button id="add-to-booklist"
|
||||
<!-- <button id="add-to-booklist"
|
||||
style="float: right;padding: 3px 5px;margin-top: -50px;background-color: cornflowerblue;">Add
|
||||
to My
|
||||
Book List</button>
|
||||
Book List</button> -->
|
||||
<table class="files">
|
||||
<colgroup>
|
||||
<col class="narrow">
|
||||
|
|
|
@ -203,6 +203,12 @@ Gutenberg metadata much faster than by scraping.
|
|||
<a onclick="printpage()" title="Print this page"><span
|
||||
class="icon icon_print"></span></a>
|
||||
</li>
|
||||
<li>
|
||||
<div class="social-button booklist">
|
||||
<button title="Add book to My Book List" id="add-to-booklist"
|
||||
style="background-color: cornflowerblue;">+</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="qr">
|
||||
|
@ -214,10 +220,10 @@ Gutenberg metadata much faster than by scraping.
|
|||
<div id="download">
|
||||
<div about="[ebook:1952]" rel="dcterms:hasFormat">
|
||||
<h2>Download This eBook</h2>
|
||||
<button id="add-to-booklist"
|
||||
<!-- <button id="add-to-booklist"
|
||||
style="float: right;padding: 3px 5px;margin-top: -50px;background-color: cornflowerblue;">Add
|
||||
to My
|
||||
Book List</button>
|
||||
Book List</button> -->
|
||||
<table class="files">
|
||||
<colgroup>
|
||||
<col class="narrow">
|
||||
|
|
|
@ -196,6 +196,12 @@
|
|||
<li>
|
||||
<a onclick="printpage()" title="Print this page"><span class="icon icon_print"></span></a>
|
||||
</li>
|
||||
<li>
|
||||
<div class="social-button booklist">
|
||||
<button title="Add book to My Book List" id="add-to-booklist"
|
||||
style="background-color: cornflowerblue;">+</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="qr">
|
||||
|
@ -207,9 +213,9 @@
|
|||
<div id="download">
|
||||
<div about="[ebook:2542]" rel="dcterms:hasFormat">
|
||||
<h2>Download This eBook</h2>
|
||||
<button id="add-to-booklist"
|
||||
<!-- <button id="add-to-booklist"
|
||||
style="float: right;padding: 3px 5px;margin-top: -50px;background-color: cornflowerblue;">Add to My
|
||||
Book List</button>
|
||||
Book List</button> -->
|
||||
<table class="files">
|
||||
<colgroup>
|
||||
<col class="narrow">
|
||||
|
|
|
@ -1,58 +1,59 @@
|
|||
(function ($) {
|
||||
const addbtn = $('#add-to-booklist');
|
||||
const url = window.location && window.location.toString().split('/');
|
||||
const bookId = url[url.length - 1].match(/(\d+)/)[0];
|
||||
const addbtn = $('#add-to-booklist')
|
||||
const url = window.location && window.location.toString().split('/')
|
||||
const bookId = url[url.length - 1].match(/(\d+)/)[0]
|
||||
|
||||
const currentList = JSON.parse(localStorage.getItem('booklist'));
|
||||
const currentList = JSON.parse(localStorage.getItem('booklist'))
|
||||
if (currentList && currentList[bookId]) {
|
||||
// book already in list
|
||||
addbtn.html('Remove book from My Book List')
|
||||
addbtn.css("background-color", "indianred");
|
||||
addbtn.html('-')
|
||||
addbtn.attr('title', '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;
|
||||
removeBook()
|
||||
return
|
||||
}
|
||||
// add book to list
|
||||
let author = '';
|
||||
$("tbody>tr").each(function (index) {
|
||||
let author = ''
|
||||
$('tbody>tr').each(function (index) {
|
||||
const row = $(this)
|
||||
const rowTitle = row.find('th:first').html();
|
||||
const rowTitle = row.find('th:first').html()
|
||||
if (rowTitle === 'Author') {
|
||||
const tableRow = row.find('td:first')
|
||||
author = tableRow.find('a:first').html();
|
||||
author = tableRow.find('a:first').html()
|
||||
}
|
||||
});
|
||||
})
|
||||
const bookData = {
|
||||
title: $('h1').html(),
|
||||
bookId: bookId,
|
||||
imgSrc: $('img.cover-art').attr('src'),
|
||||
author: author,
|
||||
url: window.location.href
|
||||
};
|
||||
}
|
||||
|
||||
const newList = { ...JSON.parse(localStorage.getItem('booklist')) };
|
||||
newList[bookId] = bookData;
|
||||
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")
|
||||
addbtn.html('-')
|
||||
addbtn.attr('title', 'Remove book from My Book List')
|
||||
addbtn.css('background-color', 'indianred')
|
||||
|
||||
localStorage.setItem('booklist', JSON.stringify(newList));
|
||||
console.log(localStorage.getItem('booklist'));
|
||||
});
|
||||
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'));
|
||||
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")
|
||||
addbtn.html('+')
|
||||
addbtn.attr('title', 'Add book to My Book List')
|
||||
addbtn.css('background-color', 'cornflowerblue')
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
})(jQuery) // eslint-disable-line
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "reading-list",
|
||||
"version": "1.0.0",
|
||||
"description": "Setup is very simple as all the content as of now is static.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint ./ --fix",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://aundus@github.com/EbookFoundation/reading-lists.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/EbookFoundation/reading-lists/issues"
|
||||
},
|
||||
"homepage": "https://github.com/EbookFoundation/reading-lists#readme",
|
||||
"devDependencies": {
|
||||
"eslint": "^7.11.0",
|
||||
"eslint-config-standard": "^14.1.1",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"eslint-plugin-standard": "^4.0.1"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue