-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnscript.js
52 lines (39 loc) · 1.3 KB
/
snscript.js
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
var childElement, appendChildElement, parentElement;
parentElement = document.getElementById('para');
function setup(){
let bgpage = chrome.extension.getBackgroundPage();
let array = bgpage.notesArray;
console.log(array);
let count =0;
for(let sentence of array){
childElement = document.createElement('p');
appendChildElement = parentElement.appendChild(childElement);
appendChildElement.innerHTML ="Note "+ (++count) +": \r"+ sentence;
}
};
var showbtn = document.querySelector('#display');
showbtn.addEventListener('click',clicklistener);
function clicklistener(){
console.log('loading..');
fetch('http://localhost:3000/api').then(function(response) {
return response.json();
}).then(displayText)
.catch(function(err) {
console.log(err);
});
}
function displayText(data){
console.log(data);
var defMsg = 'Oh O! Seems like there are no saved notes to display at the moment.';
var paragraph =document.getElementById('para');
if(data.body.length == 0){
paragraph.innerText = defMsg;
}
else{
var texttodisplay = "";
for(let i =0; i<data.body.length;i++){
texttodisplay += '\n\rNote#'+data.body[i].id+'\n'+data.body[i].savednotes;
}
paragraph.innerText = texttodisplay;
}
}