<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>实时网速监测</title>

    <style>

        #speed {

            font-size: 24px;

            margin-top: 20px;

        }

    </style>

</head>

<body>

    <h1>实时网速监测</h1>

    <p>当前网速:<span id="speed">0</span> Mbps</p>


    <script>

        function getNetworkSpeed() {

            var image = new Image();

            var startTime, endTime;


            image.onload = function() {

                endTime = performance.now();

                var duration = (endTime - startTime) / 1000; // 毫秒转换成秒

                var speed = Math.round(1 / duration); // 计算网速并四舍五入为整数

                document.getElementById("speed").textContent = speed;

            };


            startTime = performance.now();

            image.src = "https://www.2leo.top/wp-content/uploads/2023/11/%E5%94%AF%E7%BE%8E%E5%B0%91%E5%A5%B3-%E9%92%9F%E8%A1%A8-%E5%8A%A8%E6%BC%AB%E5%A3%81%E7%BA%B8_%E5%BD%BC%E5%B2%B8%E5%A3%81%E7%BA%B8.jpg"; // 替换为一个大文件的URL

        }


        setInterval(getNetworkSpeed, 5000); // 每5秒更新一次网速

    </script>

</body>

</html>