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