generate isbn-10s if I don't have them, and load images from amazon

This commit is contained in:
David 2017-05-23 21:39:49 -04:00
parent eb06ceec87
commit 8838b53e2e
2 changed files with 19 additions and 0 deletions

View File

@ -126,6 +126,7 @@
#current img {
max-height: 400px;
max-width: 100%;
display: block;
margin: 0 auto;
}

View File

@ -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);
</script>
</head>