var extractThumbnail = function(html) {
    return html;
}

var getThumbnail = function(url, success) {
    $.get('/get_picture?' + $.param({'url': url}), function(data) {
        var image = new Image();
        image.src = 'data:image/png;base64,' + data;
        success(image);
    });
}

var bookCover = function(target_id, url) {
    getThumbnail(url, function(result) {
        $(target_id).text('');
        $(target_id).append(result);
    });
    $(target_id).text('please wait');
}

// var getSimilarBooks = function(url, success) {
//     $.get('/get_picture?' + $.param({'url': url}), function(data) {
//         var image = new Image();
//         image.src = 'data:image/png;base64,' + data;
//         success(image);
//     });
// }

var bookInfo = function(bookId, bookJSON) {
    bookCover('#'+ bookId + '-cover', bookJSON.url);
    $('#' + bookId + '-title').text(bookJSON.title);
    $('#' + bookId + '-author').text(bookJSON.author);
    // $('#book-words').text(bookJSON.words);
}

var booksInfo = function(JSON) {
    bookInfo("book", JSON.book);                   
    for(var index in JSON.recommended){
        var target_id = "recommended" + index;
        var bookJSON = JSON.recommended[index];
        bookInfo(target_id, bookJSON);
    }
}

$(document).ready(function() {
    $('#get-similar').click(function(){
    var JSON = {"book": {"title":"Gs", "author":"Bash Gs", "url":"https://chitanka.info/text/1"},
            "recommended":[{"title":"Gs1", "author":"Bash Gs1", "url":"https://chitanka.info/text/2"},
                           {"title":"Gs2", "author":"Bash Gs2", "url":"https://chitanka.info/text/17472"}]}
        booksInfo(JSON)
    });
});


@@ -487,19 +487,16 @@
 t');%0A%7D%0A%0A
-// 
 var getS
@@ -510,35 +510,37 @@
 ooks = function(
-url
+title
 , success) %7B%0A// 
@@ -540,34 +540,50 @@
 ) %7B%0A
-//
     
- $.get('/get_picture
+console.log(title);%0A    $.get('/search
 ?' +
@@ -589,33 +589,37 @@
 + $.param(%7B'
-url': url
+query': title
 %7D), function
@@ -631,103 +631,8 @@
 ) %7B%0A
-//         var image = new Image();%0A//         image.src = 'data:image/png;base64,' + data;%0A// 
     
@@ -647,27 +647,23 @@
 ess(
-image);%0A// 
+data);%0A
     %7D);%0A
 // %7D
@@ -658,19 +658,16 @@
     %7D);%0A
-// 
 %7D%0A%0Avar b
@@ -940,24 +940,189 @@
 unction(
-JSON
 ) %7B%0A
+    query =  $('#title').val();%0A    console.log(query);%0A    getSimilarBooks(query, function(data) %7B%0A        console.log(data);%0A        JSON_data = JSON.parse(data);%0A    
     book
@@ -1138,16 +1138,21 @@
 k%22, JSON
+_data
 .book); 
@@ -1170,16 +1170,20 @@
        %0A
+    
     for(
@@ -1195,24 +1195,29 @@
 ndex in JSON
+_data
 .recommended
@@ -1219,16 +1219,20 @@
 ended)%7B%0A
+    
         
@@ -1274,24 +1274,28 @@
 ex;%0A        
+    
 var bookJSON
@@ -1301,16 +1301,21 @@
 N = JSON
+_data
 .recomme
@@ -1327,16 +1327,20 @@
 index%5D;%0A
+    
         
@@ -1374,17 +1374,29 @@
 N);%0A    
+   
-%7D
+ %7D%0A    %7D);
 %0A%7D%0A%0A$(do
@@ -1466,317 +1466,8 @@
 ()%7B%0A
-    var JSON = %7B%22book%22: %7B%22title%22:%22Gs%22, %22author%22:%22Bash Gs%22, %22url%22:%22https://chitanka.info/text/1%22%7D,%0A            %22recommended%22:%5B%7B%22title%22:%22Gs1%22, %22author%22:%22Bash Gs1%22, %22url%22:%22https://chitanka.info/text/2%22%7D,%0A                           %7B%22title%22:%22Gs2%22, %22author%22:%22Bash Gs2%22, %22url%22:%22https://chitanka.info/text/17472%22%7D%5D%7D%0A
     
@@ -1480,21 +1480,18 @@
 oksInfo(
-JSON
 )
+;
 %0A    %7D);

Make request to get the similar books