-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
63 lines (55 loc) · 1.93 KB
/
main.html
File metadata and controls
63 lines (55 loc) · 1.93 KB
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function sendForm() {
var myNode = document.getElementById("results");
while (myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
var info = google.script.run.withSuccessHandler(onSuccess).callNLP();
function onSuccess(data) {
for (j = 0; j < data.length; j++) {
// Create html tags
var link = document.createElement("a");
var header = document.createElement("h5");
var para = document.createElement("p");
var lineBreak = document.createElement("hr");
// Insert text into tags and strip html tags
var hnode = document.createTextNode(strip(data[j]["title"]));
// Trim the description to 140 characters and cut at last whole word
var trimmedString = data[j]["description"].substring(0, 140);
trimmedString = trimmedString.substring(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" ")))
// Before adding text strip any html tags in description
var pnode = document.createTextNode(strip(trimmedString) + "...");
// Create link for the related article that will open in new tab
link.setAttribute('href', data[j]["url"]);
link.setAttribute('target', '_blank');
// Add children to parents
header.appendChild(hnode);
link.appendChild(header);
para.appendChild(pnode);
// Append all html tags results div
element = document.getElementById('results');
element.appendChild(link);
element.appendChild(para);
element.appendChild(lineBreak);
}
}
// Strip away any html tags present in a string
function strip(html) {
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
}
</script>
<div id="all">
<button onclick="sendForm();">Refresh</button>
</div>
<div id="results">
</div>
</body>
</html>