...

Ping synagy

تست سرعت اینترنت

تست سرعت

دانلود
0
Mbps
آپلود
0
Mbps
Loading…

در حال انجام تست…

تست پینگ

زمان پاسخ
0
میلی‌ثانیه
Loading…

در حال انجام تست…

نتایج قبلی

تاریخ دانلود (Mbps) آپلود (Mbps) پینگ (ms)
document.addEventListener(‘DOMContentLoaded’, function() { // بارگذاری نتایج قبلی از localStorage loadPreviousResults(); // رویداد کلیک برای تست سرعت document.getElementById(‘speed-test-btn’).addEventListener(‘click’, function() { runSpeedTest(); }); // رویداد کلیک برای تست پینگ document.getElementById(‘ping-test-btn’).addEventListener(‘click’, function() { runPingTest(); }); }); function runSpeedTest() { const speedBtn = document.getElementById(‘speed-test-btn’); const speedLoading = document.getElementById(‘speed-loading’); speedBtn.disabled = true; speedLoading.style.display = ‘block’; // ریست کردن مقادیر document.getElementById(‘download-speed’).textContent = ‘0’; document.getElementById(‘upload-speed’).textContent = ‘0’; document.getElementById(‘download-progress’).style.width = ‘0%’; document.getElementById(‘upload-progress’).style.width = ‘0%’; // استفاده از speedtest-net برای تست سرعت const test = speedtest({ maxTime: 15000, serverId: null, // انتخاب خودکار بهترین سرور onupdate: function(data) { if (data.testState === 1) { // دانلود const downloadSpeed = (data.download * 8 / 1000000).toFixed(2); document.getElementById(‘download-speed’).textContent = downloadSpeed; const progress = Math.min(100, downloadSpeed / 100 * 100); document.getElementById(‘download-progress’).style.width = `${progress}%`; } else if (data.testState === 2) { // آپلود const uploadSpeed = (data.upload * 8 / 1000000).toFixed(2); document.getElementById(‘upload-speed’).textContent = uploadSpeed; const progress = Math.min(100, uploadSpeed / 50 * 100); document.getElementById(‘upload-progress’).style.width = `${progress}%`; } }, onend: function(data) { const downloadSpeed = (data.download * 8 / 1000000).toFixed(2); const uploadSpeed = (data.upload * 8 / 1000000).toFixed(2); const ping = data.ping.toFixed(2); // ذخیره نتایج saveTestResult(downloadSpeed, uploadSpeed, ping); speedBtn.disabled = false; speedLoading.style.display = ‘none’; } }); } function runPingTest() { const pingBtn = document.getElementById(‘ping-test-btn’); const pingLoading = document.getElementById(‘ping-loading’); pingBtn.disabled = true; pingLoading.style.display = ‘block’; // شبیه‌سازی تست پینگ (در عمل باید از API مناسب استفاده شود) setTimeout(function() { // این مقدار تصادفی فقط برای نمایش است // در یک پیاده‌سازی واقعی باید از WebSocket یا API دیگر استفاده کنید const pingTime = (Math.random() * 100).toFixed(2); document.getElementById(‘ping-time’).textContent = pingTime; pingBtn.disabled = false; pingLoading.style.display = ‘none’; // ذخیره نتیجه (پینگ به تنهایی ذخیره نمی‌شود مگر با تست سرعت) }, 2000); } function saveTestResult(download, upload, ping) { const tests = JSON.parse(localStorage.getItem(‘speedTests’) || ‘[]’); const now = new Date(); tests.unshift({ date: now.toLocaleString(‘fa-IR’), download: download, upload: upload, ping: ping }); // فقط 10 نتیجه آخر را نگه دارید if (tests.length > 10) { tests.pop(); } localStorage.setItem(‘speedTests’, JSON.stringify(tests)); loadPreviousResults(); } function loadPreviousResults() { const tests = JSON.parse(localStorage.getItem(‘speedTests’) || ‘[]’); const tableBody = document.getElementById(‘results-table’); tableBody.innerHTML = ”; tests.forEach(test => { const row = document.createElement(‘tr’); row.innerHTML = ` ${test.date} ${test.download} ${test.upload} ${test.ping} `; tableBody.appendChild(row); }); }