<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>sitemap.xml</title>
  <meta name="robots" content="noindex, nofollow">
</head>
<body>
  <pre id="xml"></pre>
  <script>
    const origin = location.origin;
    const searches = JSON.parse(localStorage.getItem('indexedSearches') || '[]');
    const videos = JSON.parse(localStorage.getItem('indexedVideos') || '[]');

    const urls = [];

    searches.forEach(q => {
      urls.push(`<url><loc>${origin}/search?q=${encodeURIComponent(q)}</loc></url>`);
    });

    videos.forEach(v => {
      urls.push(`<url><loc>${origin}/watch?v=${v}</loc></url>`);
    });

    const sitemap =
      `<?xml version="1.0" encoding="UTF-8"?>\n` +
      `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n` +
      urls.join('\n') +
      `\n</urlset>`;

    document.getElementById('xml').textContent = sitemap;
  </script>
</body>
</html>