remove more cruft
This commit is contained in:
parent
3e20c3a51e
commit
b3ccda7885
@ -23,33 +23,29 @@
|
|||||||
function init() {
|
function init() {
|
||||||
fetch("/api")
|
fetch("/api")
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then(showInfo);
|
.then((books) => {
|
||||||
}
|
// prepare response
|
||||||
|
books.forEach((book) => {
|
||||||
function showInfo(books) {
|
book.sortTitle = titleCleaner(book.title);
|
||||||
books.forEach((book) => {
|
if (!book["isbn-10"] && book["isbn-13"]) {
|
||||||
book.sortTitle = titleCleaner(book.title);
|
book["isbn-10"] = ISBNfromEAN(book["isbn-13"]);
|
||||||
if (!book["isbn-10"] && book["isbn-13"]) {
|
}
|
||||||
book["isbn-10"] = ISBNfromEAN(book["isbn-13"]);
|
if (!book.coverurl && book["isbn-10"]) {
|
||||||
}
|
book.coverurl =
|
||||||
if (!book.coverurl && book["isbn-10"]) {
|
`https://images-na.ssl-images-amazon.com/images/P/` +
|
||||||
book.coverurl = amazonCoverUrl(book["isbn-10"]);
|
book["isbn-10"] +
|
||||||
}
|
`.01.LZZ.jpg`;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
$("#search")
|
return books;
|
||||||
.unbind("input")
|
})
|
||||||
.on("input", (e) => {
|
.then((books) => {
|
||||||
search(books, e.target.value);
|
document.getElementById("search").addEventListener("input", (e) => {
|
||||||
});
|
search(books, e.target.value);
|
||||||
|
});
|
||||||
$("#reloadLink")
|
return books;
|
||||||
.unbind("click")
|
})
|
||||||
.on("click", () => {
|
.then(renderTable);
|
||||||
init();
|
|
||||||
});
|
|
||||||
|
|
||||||
renderTable(books);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(books, searchBy) {
|
function search(books, searchBy) {
|
||||||
@ -88,15 +84,19 @@
|
|||||||
if (sortState.sortOrder === "desc") {
|
if (sortState.sortOrder === "desc") {
|
||||||
books.reverse();
|
books.reverse();
|
||||||
}
|
}
|
||||||
books.forEach((e, i) => (e.rowNumber = i)); // re-key for new sort
|
books.forEach((e, i) => (e.rowNumber = i)); // re-key
|
||||||
|
|
||||||
$("#books").html(TableTemplate(books));
|
// rendering
|
||||||
|
document.getElementById("books").innerHTML = TableTemplate(books);
|
||||||
$("#books tbody tr")
|
$("#books tbody tr")
|
||||||
.not(":first") // ignore the headers
|
.not(":first") // ignore the headers
|
||||||
.on("click", function () {
|
.on("click", (e) => {
|
||||||
updateCurrentBook(books[$(this)[0].id]);
|
document.getElementById("current").innerHTML = BookTemplate(
|
||||||
|
books[e.currentTarget.id]
|
||||||
|
);
|
||||||
});
|
});
|
||||||
$("#books tbody tr th[data-sort-by]").on("click", function () {
|
$("#books tbody tr th[data-sort-by]").on("click", function (e) {
|
||||||
|
console.log(e);
|
||||||
renderTable(books, $(this).data("sortBy")); // only add callback when there's a sortBy attribute
|
renderTable(books, $(this).data("sortBy")); // only add callback when there's a sortBy attribute
|
||||||
});
|
});
|
||||||
$("#books tbody tr th[data-sort-by=" + sortState.sortBy + "]").addClass(
|
$("#books tbody tr th[data-sort-by=" + sortState.sortBy + "]").addClass(
|
||||||
@ -104,10 +104,6 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCurrentBook(book) {
|
|
||||||
$("#current").html(BookTemplate(book));
|
|
||||||
}
|
|
||||||
|
|
||||||
function titleCleaner(title) {
|
function titleCleaner(title) {
|
||||||
return title
|
return title
|
||||||
.replace('"', "")
|
.replace('"', "")
|
||||||
@ -124,10 +120,6 @@
|
|||||||
.replace(" ", "");
|
.replace(" ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function amazonCoverUrl(ISBN) {
|
|
||||||
return `https://images-na.ssl-images-amazon.com/images/P/${ISBN}.01.LZZ.jpg`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ISBNfromEAN(EAN) {
|
function ISBNfromEAN(EAN) {
|
||||||
ISBN = EAN.slice(3, 12);
|
ISBN = EAN.slice(3, 12);
|
||||||
var checkdigit =
|
var checkdigit =
|
||||||
@ -209,7 +201,9 @@
|
|||||||
}, "")} </table>`;
|
}, "")} </table>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", () => {
|
||||||
|
init();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -219,7 +213,6 @@
|
|||||||
<a target="_blank" href="https://git.yetaga.in/alazyreader/library"
|
<a target="_blank" href="https://git.yetaga.in/alazyreader/library"
|
||||||
>git</a
|
>git</a
|
||||||
>
|
>
|
||||||
<a id="reloadLink" href="#">reload</a>
|
|
||||||
<div id="searchBox">
|
<div id="searchBox">
|
||||||
<input
|
<input
|
||||||
id="search"
|
id="search"
|
||||||
|
Loading…
Reference in New Issue
Block a user