-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
30 lines (25 loc) · 1.04 KB
/
popup.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
displayJsonData(localStorage.getItem("jsonData"));
window.addEventListener('click',function(e){
if(e.target.href!==undefined){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.runtime.sendMessage({message: "openSite", href:e.target.href});
});
}
});
function displayJsonData(jsonData) {
// json.parse(response): to object, and then parse obj to array
var arr = JSON.parse(JSON.parse(jsonData));
var body = document.body;
body.setAttribute("style","min-width: 300px");
var divElem = document.getElementById('jsonLoad');
var temAelem;
for(var i = 0; i < arr.length; i++) {
var href = 'https://www.' + arr[i].domain;
temAelem = document.createElement('a');
temAelem.setAttribute("href",href);
temAelem.setAttribute("class","list-group-item list-group-item-action");
temAelem.setAttribute("style"," text-align:center");
temAelem.innerText = arr[i].name;
divElem.appendChild(temAelem);
}
}