function archiveUrls(urlList) {
if (!Array.isArray(urlList)) {
console.error("Input must be an array of URLs.");
return;
}
for (const url of urlList) {
if (typeof url !== 'string' || url.trim() === '') {
console.warn("Invalid URL found in list. Skipping.");
continue;
}
fetch(url) // Fetch content from the URL
.then(response => {
if (!response.ok) {
console.error(`Error fetching ${url}: ${response.status}`);
return;
}
return response.text(); // Get the content as text
})
.then(data => {
// Simulate archiving (e.g., storing in localStorage or a simple array)
console.log(`Archived content from ${url}:`, data.substring(0, 100) + "..."); // Show first 100 chars
// In a real application, store 'data' somewhere.
})
.catch(error => {
console.error(`Error archiving ${url}:`, error);
});
}
}
Add your comment