| <!DOCTYPE html> |
| <html lang="ru"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Автоотправка запросов</title> |
| <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> |
| <style> |
| body { |
| font-family: Arial, sans-serif; |
| text-align: center; |
| padding: 20px; |
| } |
| input, button { |
| margin: 10px; |
| padding: 10px; |
| font-size: 16px; |
| } |
| #counter { |
| font-size: 20px; |
| font-weight: bold; |
| color: green; |
| } |
| </style> |
| </head> |
| <body> |
|
|
| <h2>Отправка запросов</h2> |
|
|
| <label>URL запроса:</label> |
| <input type="text" id="requestUrl" placeholder="Введите URL"> |
| <br> |
|
|
| <label>Задержка (мс):</label> |
| <input type="number" id="delayTime" value="500" min="100"> |
| <br> |
|
|
| <button id="startBtn">Старт</button> |
| <button id="stopBtn">Стоп</button> |
| <br> |
|
|
| <p>Отправлено запросов: <span id="counter">0</span></p> |
|
|
| <script> |
| let intervalId = null; |
| let count = 0; |
| |
| document.getElementById("startBtn").addEventListener("click", function () { |
| const url = document.getElementById("requestUrl").value.trim(); |
| let delay = parseInt(document.getElementById("delayTime").value, 10); |
| |
| if (!url) { |
| Swal.fire("Ошибка", "Введите URL для отправки запросов!", "error"); |
| return; |
| } |
| |
| if (isNaN(delay) || delay < 100) { |
| Swal.fire("Ошибка", "Минимальная задержка 100 мс!", "error"); |
| return; |
| } |
| |
| count = 0; |
| document.getElementById("counter").textContent = count; |
| |
| Swal.fire({ |
| title: "Запросы запущены!", |
| text: `Будут отправляться каждые ${delay} мс.`, |
| icon: "success", |
| timer: 2000, |
| showConfirmButton: false |
| }); |
| |
| |
| intervalId = setInterval(() => { |
| fetch(url, { method: "GET" }) |
| .then(response => { |
| if (!response.ok) throw new Error("Ошибка запроса"); |
| return response.text(); |
| }) |
| .then(data => { |
| console.log("Ответ сервера:", data); |
| count++; |
| document.getElementById("counter").textContent = count; |
| }) |
| .catch(error => { |
| console.error("Ошибка:", error); |
| Swal.fire("Ошибка", "Не удалось отправить запрос!", "error"); |
| }); |
| }, delay); |
| }); |
| |
| document.getElementById("stopBtn").addEventListener("click", function () { |
| if (intervalId) { |
| clearInterval(intervalId); |
| intervalId = null; |
| Swal.fire("Остановлено", "Запросы больше не отправляются", "info"); |
| } |
| }); |
| </script> |
|
|
| </body> |
| </html> |
|
|