From 8838b53e2e9732b4a016c43cd8aafc672e12f3a8 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Tue, 23 May 2017 21:39:49 -0400 Subject: [PATCH] generate isbn-10s if I don't have them, and load images from amazon --- css/style.css | 1 + index.html | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/css/style.css b/css/style.css index 7c4deeb..7a36f6a 100644 --- a/css/style.css +++ b/css/style.css @@ -126,6 +126,7 @@ #current img { max-height: 400px; + max-width: 100%; display: block; margin: 0 auto; } diff --git a/index.html b/index.html index 23797be..14c4196 100644 --- a/index.html +++ b/index.html @@ -34,6 +34,12 @@ $.each(data, function(key, value) { value.sortTitle = titleCleaner(value.title); + if (!value['isbn-10'] && value['isbn-13']) { + value['isbn-10'] = generateISBNfromEAN(value['isbn-13']); + } + if (!value.coverurl && value['isbn-10']) { + value.coverurl = generateAmazonCoverUrl(value['isbn-10']); + } }); renderTable(data); @@ -95,6 +101,18 @@ .replace(/^(An?|The)\s/i, ''); } + function generateAmazonCoverUrl(ISBN) { + return "https://images-na.ssl-images-amazon.com/images/P/" + ISBN + ".01.LZZ.jpg" + } + + function generateISBNfromEAN(EAN) { + ISBN = EAN.slice(3,12); + var checkdigit = ((11 - (_.reduce(ISBN.split(''), function(sum, num, key) { + return sum + (num * (10 - key)); + }, 0) % 11)) % 11); + return ISBN + (checkdigit == 10 ? 'X' : checkdigit); + } + window.addEventListener('DOMContentLoaded', init);