-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsets-lit.html
89 lines (79 loc) · 4.06 KB
/
sets-lit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<head>
<link type="text/css" rel="stylesheet" href="jquery.qtip.min.css" />
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,500,600,700,800' rel='stylesheet'>
<link href='styles.css' rel='stylesheet'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
<script src="stupidtable.js"></script>
<base target="_parent">
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: 'https://www.librarything.com/api_getdata.php?userid=unsoluble&key=2337767339&resultsets=books,bookreviews,booktags&reviewmax=800&tagList=NovelSet&max=200&showReviews=1&showTags=1',
dataType: 'jsonp',
success: function(result){
var text = '<table id="bookTable">';
text += '<thead><tr>';
text += '<th></th>';
text += '<th id="title-column" data-sort-onload="yes" data-sort="string">title</th>';
text += '<th id="author-column" data-sort="string" data-sort-multicolumn="title-column">author</th>';
text += '<th>summary</th>';
text += '<th id="grade-column" data-sort="string" data-sort-multicolumn="author-column">grade</th>';
text += '<th id="copies-column" data-sort="int" data-sort-multicolumn="author-column">copies</th>';
text += '</tr></thead>';
text += '<tbody>';
// Remap the result into a clean array.
var arr = $.map(result.books, function(el) { return el });
for (i=0; i < arr.length; i++) {
// Skip the book if it has more than 24 copies.
if (arr[i].copies > 24) {
continue;
}
// Book covers will link to a Destiny search for the title.
var searchTerms = encodeURI(arr[i].title);
var searchQuery = "https://search.follettsoftware.com/metasearch/ui/27293/search/all?q=" + searchTerms + "&resultsSortBy=MOSTRECENT";
let gradeLevel = "Any";
for (let tag of arr[i].tags) {
if (tag.startsWith("Grade")) {
gradeLevel = parseInt(tag.replace("Grade", ""));
break;
}
}
// Fix sorting for leading articles.
var sortTitle = '';
if (arr[i].title.substr(0, 2) == 'A ') {
sortTitle = arr[i].title.substr(2);
}
else if (arr[i].title.substr(0, 4) == 'The ') {
sortTitle = arr[i].title.substr(4);
}
else {
sortTitle = arr[i].title;
}
// Cover art from LibraryThing (and not Amazon) doesn't load correctly, so use a generic image.
var coverArt = arr[i].cover;
if (arr[i].cover.indexOf("librarything") >=0 ) {
coverArt = 'Generic_Cover.jpg';
}
text += '<tr>';
text += '<td class="cover_td"><div class="book"><a href="' + searchQuery + '"><img class="cover" src="' + coverArt + '" /></a></div></td>';
text += '<td class="title_td" data-sort-value="' + sortTitle + '">' + arr[i].title + '</td>';
text += '<td class="author_td" data-sort-value="' + arr[i].author_code + '">' + arr[i].author_fl + '</td>';
text += '<td class="summary_td">' + arr[i].bookreview + '</td>';
text += '<td class="grade_td">' + gradeLevel + '</td>';
text += '<td class="copies_td">' + arr[i].copies + '</td>';
text += '</tr>';
}
text += '</tbody></table>';
$('#books').html(text); // insert the generated HTML
$("#bookTable").stupidtable(); // sort the table
}
});
});
</script>
<div id="books"></div>
</body>
</html>