-
Notifications
You must be signed in to change notification settings - Fork 0
/
isomorph_animorph.html
75 lines (56 loc) · 2.43 KB
/
isomorph_animorph.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
<html>
<head>
<title>Automatic Quotation Checker</title>
<script src="https://apis.google.com/js/client.js?"></script>
</head>
<body onload = "login();">
<div id="input">
<h1>Automatic Quotation Checker</h1>
<p>This tool takes a passage of text and searches for matching phrases using the Google Books API. Paste your text below and specify the length (in words) of phrases to search for. Results will appear below the text box, in the form of a list of links, after a few seconds.</p>
<p><b>Phrase length (in words):</b> <input type="text" id="length" cols="5"> <button id="submit" onclick="search();">Search</button></input></p>
<p><textarea id="source" rows="25" cols="75"></textarea></p>
</div>
<div id="output">
</div>
</body>
<script>
function login() {
gapi.client.setApiKey("AIzaSyDITTqKVQCJg1-oYlGrzAg0y49GJl_GGew");
gapi.client.load("books", "v1");
}
function search() {
var chunkSizeRaw = document.getElementById("length").value;
var chunkSize = parseInt(chunkSizeRaw);
var counter = 0;
var source = document.getElementById("source").value.replace(/(\r\n|\n|\r)/gm," ").replace(/ +/g," ").replace(/-/g," ").replace(/[\.,\/#!$%\^&\*;:{}=_`~()\?']/g,"").split(" ");
console.log(source);
var batch = gapi.client.newHttpBatch();
while (counter + chunkSize <= source.length) {
var chunk = source.slice(counter,counter+chunkSize);
var searchTerm = "\"" + chunk.join("+") + "\"";
//var searchTerm = encodeURIComponent(searchTermRaw);
console.log(searchTerm);
var request = gapi.client.request( {
"path": "/books/v1/volumes",
"params": {"q": searchTerm}
});
batch.add(request, {"id": "search" + counter});
counter++;
}
batch.execute(function(response) {
console.log(response);
counter = 0;
for (var i in response) {
if (parseInt(response[i].result.totalItems) < 100 && parseInt(response[i].result.totalItems) > 2) {
document.getElementById("output").innerHTML += "<b>" + source.slice(counter,counter+chunkSize).join(" ") + "</b>" + "<br>";
for (var key in response[i].result.items) {
document.getElementById("output").innerHTML += "<a href=\"" + response[i].result.items[key].volumeInfo.infoLink + "\">" + response[i].result.items[key].volumeInfo.title + "</a>" + "<br><br>";
//document.getElementById("output").innerHTML += "<a href=\"" + "test" + "\">" + "test" + "</a>" + "<br><br>";
}
}
counter++;
}
});
}
</script>
</html>