-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
38 lines (34 loc) · 1.19 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
31
32
33
34
35
36
37
38
chrome.tabs.query({ 'active': true, 'lastFocusedWindow': true }, function (tabs) {
var url = tabs[0].url;
// Send the URL to the backend
fetch('http://localhost:5000/scrape', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ url: url })
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
const extElement = document.getElementById('ext');
if (extElement) {
extElement.innerHTML = '';
data.forEach(item => {
const itemDiv = document.createElement('div');
itemDiv.classList.add('item');
const linkElement = document.createElement('a');
linkElement.href = item.link;
linkElement.textContent = item.title;
linkElement.target = '_blank';
itemDiv.appendChild(linkElement);
extElement.appendChild(itemDiv);
});
}
})
.catch(error => console.error('Error:', error));
});