Skip to content

Instantly share code, notes, and snippets.

@A-gambit
Created August 7, 2014 10:43
Show Gist options
  • Select an option

  • Save A-gambit/9585238fd38d4efe12ff to your computer and use it in GitHub Desktop.

Select an option

Save A-gambit/9585238fd38d4efe12ff to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Book</title>
</head>
<script src="http://code.jquery.com/jquery-git2.js"></script>
<body>
<input type="text" name="text" value="" class="text">
<input type="button" name="find" value="find" class="find">
<script type="text/javascript">
var wordCatObj = []
function findWordCat(isbnObj){
wordCatObj = []
$.each(isbnObj, function(index, val) {
getObjWordCat(val.isbn)
})
function getObjWordCat(isbn){
var config = {
wskey: "isbvGOWBKcHL1Td6E87jL2QDLodVpBabo4xnviUIAIbGEy9KKhyIvuI3jxh7Bd4xUzjg4Mad72TX2QN0",
q: isbn,
url:"",
dataType: 'jsonp'
}
config.url = "http://xisbn.worldcat.org/webservices/xid/isbn/"+config.q+"?method=getMetadata&format=json&fl=*"
$.ajax(config)
.done(function(data){
if(data.stat == "ok") wordCatObj.push(data.list[0])
})
}
}
function getISBN(list){
var isbnObj = [];
$.each(list, function(index, val) {
identify(val)
})
function identify(val){
var inf = val.volumeInfo,
authors = inf.authors,
index = inf.industryIdentifiers;
book = {
authors: "",
title: inf.title,
isbn: ""
}
if(authors){
for (var i = 0; i < authors.length; i++){
if(authors[i]) book.authors = book.authors + authors[i]
book.authors = (i!=authors.length-1) ? book.authors + ", " : book.authors
}
} else book.authors = "No Authors"
book.isbn = index[0] ? index[0].identifier : "";
isbnObj.push(book)
}
findWordCat(isbnObj);
}
function findBook(word){
var config = {
q: "",
dataType: "jsonp",
url: "",
key: "AIzaSyDZAfYZSNJL9Ay2RngwN_0XtWDkSMfp4lk"
}
config.q = word
config.url= "https://www.googleapis.com/books/v1/volumes?q="+config.q+"&langRestrict=en&maxResults=40&key="+config.key
$.ajax(config)
.done(function(list){
console.log(list)
getISBN(list.items)
})
}
$(".find").click(function(){
var text = $(".text").val()
findBook(text)
});
$(".text").change(function(){
var text = $(this).val()
findBook(text)
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment