-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
28 lines (26 loc) · 1013 Bytes
/
app.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
document.getElementById('scrapeForm').addEventListener('submit', function(e) {
e.preventDefault();
const url = document.getElementById('url').value;
window.open(`/scrape?url=${encodeURIComponent(url)}`, '_blank');
fetch(`/scrape?url=${encodeURIComponent(url)}`)
.then(response => response.json())
.then(data => {
const results = document.getElementById('results');
results.innerHTML = '';
data.forEach(item => {
const li = document.createElement('li');
if (item.text) {
li.textContent = item.text;
} else if (item.url) {
const a = document.createElement('a');
a.href = item.url;
a.textContent = item.url;
li.appendChild(a);
}
results.appendChild(li);
});
})
.catch(error => {
console.error('Error:', error);
});
});