|
|
|
@ -6,33 +6,33 @@
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
var msg = i18n_msg;
|
|
|
|
|
var msg = i18nMsg;
|
|
|
|
|
var douban = "https://api.douban.com";
|
|
|
|
|
var db_search = '/v2/book/search';
|
|
|
|
|
var db_get_info = '/v2/book/';
|
|
|
|
|
var db_get_info_by_isbn = '/v2/book/isbn/ ';
|
|
|
|
|
var db_done = false;
|
|
|
|
|
var dbSearch = "/v2/book/search";
|
|
|
|
|
var db_get_info = "/v2/book/";
|
|
|
|
|
var db_get_info_by_isbn = "/v2/book/isbn/ ";
|
|
|
|
|
var dbDone = false;
|
|
|
|
|
|
|
|
|
|
var google = 'https://www.googleapis.com/';
|
|
|
|
|
var gg_search = '/books/v1/volumes';
|
|
|
|
|
var gg_get_info = '/books/v1/volumes/';
|
|
|
|
|
var google = "https://www.googleapis.com/";
|
|
|
|
|
var gg_search = "/books/v1/volumes";
|
|
|
|
|
var gg_get_info = "/books/v1/volumes/";
|
|
|
|
|
var gg_done = false;
|
|
|
|
|
|
|
|
|
|
var db_results = [];
|
|
|
|
|
var gg_results = [];
|
|
|
|
|
var show_flag = 0;
|
|
|
|
|
String.prototype.replaceAll = function (s1, s2) {
|
|
|
|
|
return this.replace(new RegExp(s1, "gm"), s2);
|
|
|
|
|
return this.replace(new RegExp(s1, "gm"), s2);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gg_search_book = function (title) {
|
|
|
|
|
title = title.replaceAll(/\s+/, '+');
|
|
|
|
|
var url = google + gg_search + '?q=' + title;
|
|
|
|
|
function gg_search_book (title) {
|
|
|
|
|
title = title.replaceAll(/\s+/, "+");
|
|
|
|
|
var url = google + gg_search + "?q=" + title;
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: url,
|
|
|
|
|
url,
|
|
|
|
|
type: "GET",
|
|
|
|
|
dataType: "jsonp",
|
|
|
|
|
jsonp: 'callback',
|
|
|
|
|
jsonp: "callback",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
gg_results = data.items;
|
|
|
|
|
},
|
|
|
|
@ -43,15 +43,16 @@ $(document).ready(function () {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_meta = function (source, id) {
|
|
|
|
|
function get_meta (source, id) {
|
|
|
|
|
var meta;
|
|
|
|
|
if (source == "google") {
|
|
|
|
|
var tags;
|
|
|
|
|
if (source === "google") {
|
|
|
|
|
meta = gg_results[id];
|
|
|
|
|
$("#description").val(meta.volumeInfo.description);
|
|
|
|
|
$("#bookAuthor").val(meta.volumeInfo.authors.join(' & '));
|
|
|
|
|
$("#bookAuthor").val(meta.volumeInfo.authors.join(" & "));
|
|
|
|
|
$("#book_title").val(meta.volumeInfo.title);
|
|
|
|
|
if (meta.volumeInfo.categories) {
|
|
|
|
|
var tags = meta.volumeInfo.categories.join(',');
|
|
|
|
|
tags = meta.volumeInfo.categories.join(",");
|
|
|
|
|
$("#tags").val(tags);
|
|
|
|
|
}
|
|
|
|
|
if (meta.volumeInfo.averageRating) {
|
|
|
|
@ -59,10 +60,10 @@ $(document).ready(function () {
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (source == "douban") {
|
|
|
|
|
if (source === "douban") {
|
|
|
|
|
meta = db_results[id];
|
|
|
|
|
$("#description").val(meta.summary);
|
|
|
|
|
$("#bookAuthor").val(meta.author.join(' & '));
|
|
|
|
|
$("#bookAuthor").val(meta.author.join(" & "));
|
|
|
|
|
$("#book_title").val(meta.title);
|
|
|
|
|
var tags = '';
|
|
|
|
|
for (var i = 0; i < meta.tags.length; i++) {
|
|
|
|
@ -84,7 +85,7 @@ $(document).ready(function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db_search_book = function (title) {
|
|
|
|
|
var url = douban + db_search + '?q=' + title + '&fields=all&count=10';
|
|
|
|
|
var url = douban + dbSearch + '?q=' + title + '&fields=all&count=10';
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: url,
|
|
|
|
|
type: "GET",
|
|
|
|
@ -97,18 +98,18 @@ $(document).ready(function () {
|
|
|
|
|
$('#meta-info').html('<p class="text-danger">'+ msg.search_error+'!</p>');
|
|
|
|
|
},
|
|
|
|
|
complete: function () {
|
|
|
|
|
db_done = true;
|
|
|
|
|
dbDone = true;
|
|
|
|
|
show_result();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
show_result = function () {
|
|
|
|
|
function show_result () {
|
|
|
|
|
show_flag++;
|
|
|
|
|
if (show_flag == 1) {
|
|
|
|
|
$('#meta-info').html('<ul id="book-list" class="media-list"></ul>');
|
|
|
|
|
}
|
|
|
|
|
if (gg_done && db_done) {
|
|
|
|
|
if (gg_done && dbDone) {
|
|
|
|
|
if (!gg_results && !db_results) {
|
|
|
|
|
$('#meta-info').html('<p class="text-danger">'+ msg.no_result +'</p>');
|
|
|
|
|
return;
|
|
|
|
@ -140,7 +141,7 @@ $(document).ready(function () {
|
|
|
|
|
}
|
|
|
|
|
gg_done = false;
|
|
|
|
|
}
|
|
|
|
|
if (db_done && db_results.length > 0) {
|
|
|
|
|
if (dbDone && db_results.length > 0) {
|
|
|
|
|
for (var i = 0; i < db_results.length; i++) {
|
|
|
|
|
var book = db_results[i];
|
|
|
|
|
var book_html = '<li class="media">' +
|
|
|
|
@ -155,24 +156,24 @@ $(document).ready(function () {
|
|
|
|
|
'<p>' + msg.description + ':' + book.summary + '</p>' +
|
|
|
|
|
'<p>' + msg.source + ':<a href="https://book.douban.com" target="_blank">Douban Books</a></p>' +
|
|
|
|
|
'</div>' +
|
|
|
|
|
'</li>';
|
|
|
|
|
"</li>";
|
|
|
|
|
$("#book-list").append(book_html);
|
|
|
|
|
}
|
|
|
|
|
db_done = false;
|
|
|
|
|
dbDone = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#do-search').click(function () {
|
|
|
|
|
var keyword = $('#keyword').val();
|
|
|
|
|
$("#do-search").click(function () {
|
|
|
|
|
var keyword = $("#keyword").val();
|
|
|
|
|
if (keyword) {
|
|
|
|
|
do_search(keyword);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#get_meta').click(function () {
|
|
|
|
|
var book_title = $('#book_title').val();
|
|
|
|
|
$("#get_meta").click(function () {
|
|
|
|
|
var book_title = $("#book_title").val();
|
|
|
|
|
if (book_title) {
|
|
|
|
|
$('#keyword').val(book_title);
|
|
|
|
|
$("#keyword").val(book_title);
|
|
|
|
|
do_search(book_title);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|