-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (35 loc) · 1.19 KB
/
Copy pathscript.js
File metadata and controls
39 lines (35 loc) · 1.19 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
36
37
38
39
document.getElementById('startScan').addEventListener('click', () => {
const fileInput = document.getElementById('bookmarkFile');
const file = fileInput.files[0];
if (!file) {
alert('Please select a bookmark HTML.');
return;
}
const reader = new FileReader();
reader.onload = async function (e) {
const htmlContent = e.target.result;
const parser = new DOMParser();
const doc = parser.parseFromString(htmlContent, "text/html");
const links = Array.from(doc.querySelectorAll('a')).map(a => a.href);
await scanLinks(links);
};
reader.readAsText(file);
});
async function scanLinks(links) {
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '';
for (const url of links) {
const status = await checkLink(url);
const result = document.createElement('div');
result.textContent = `${url} - ${status}`;
resultsDiv.appendChild(result);
}
}
async function checkLink(url) {
try {
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
return 'Possibly Alive (No Cors)';
} catch (error) {
return 'Dead';
}
}