1. function archiveUrls(urlList) {
  2. if (!Array.isArray(urlList)) {
  3. console.error("Input must be an array of URLs.");
  4. return;
  5. }
  6. for (const url of urlList) {
  7. if (typeof url !== 'string' || url.trim() === '') {
  8. console.warn("Invalid URL found in list. Skipping.");
  9. continue;
  10. }
  11. fetch(url) // Fetch content from the URL
  12. .then(response => {
  13. if (!response.ok) {
  14. console.error(`Error fetching ${url}: ${response.status}`);
  15. return;
  16. }
  17. return response.text(); // Get the content as text
  18. })
  19. .then(data => {
  20. // Simulate archiving (e.g., storing in localStorage or a simple array)
  21. console.log(`Archived content from ${url}:`, data.substring(0, 100) + "..."); // Show first 100 chars
  22. // In a real application, store 'data' somewhere.
  23. })
  24. .catch(error => {
  25. console.error(`Error archiving ${url}:`, error);
  26. });
  27. }
  28. }

Add your comment