-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetchFeedly.js
More file actions
35 lines (33 loc) · 1.46 KB
/
fetchFeedly.js
File metadata and controls
35 lines (33 loc) · 1.46 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
var list = document.createElement("ul");
var container = document.getElementById("container");
list.classList.add("list-group");
list.style.marginTop = "30px";
function sendForm() {
var keyword = document.getElementById("keyword").value; // crate a variable that holds the search query
fetch("https://hook.integromat.com/8vy1c5ujg5nlhpbusmin2t7wbnau38ic", {
// use JS's fetch method to send a request with the keyword to the webhook
method: "POST", // define the http request
body: `${JSON.stringify(keyword)}` //attach the keyword to the webhook so we can process it in integromat
})
.then(res => res.json()) // wait for response. then, turn the response into json
.then(result => resultsToHTMLList(result)); //then, run resultsToHTMLList() and insert the new json response as parameter
}
function resultsToHTMLList(results) {
// create an html
for (result of results) {
console.log(result);
var listItem = document.createElement("li");
var item = document.createElement("p");
var title = document.createTextNode(result.Title);
var secondItem = document.createElement("a");
secondItem.setAttribute("href", result.ArticleURL);
var link = document.createTextNode(result.ArticleURL);
item.appendChild(title);
secondItem.appendChild(link);
listItem.appendChild(item);
listItem.appendChild(secondItem);
listItem.classList.add("list-group-item");
list.appendChild(listItem);
}
container.appendChild(list);
}