Greasy Fork

Greasy Fork is available in English.

Speedtest.net Auto Runner

Automatically runs speedtest and repeats

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Speedtest.net Auto Runner
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically runs speedtest and repeats
// @author       Henry Guo
// @match        https://www.speedtest.net/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const config = {
        initialDelay: 2000,    // 页面加载后等待时间(毫秒)
        resultDelay: 5000,     // 测试完成后等待时间(毫秒)
    };

    // 检查当前是否在结果页面
    function isResultPage() {
        return window.location.pathname.startsWith('/result/');
    }

    // 开始测速
    function startTest() {
        const startButton = document.querySelector('.js-start-test');
        if (startButton) {
            startButton.click();
            console.log('Speed test started');
            // 开始监控URL变化
            checkTestComplete();
        }
    }

    // 检查测试是否完成
    function checkTestComplete() {
        if (isResultPage()) {
            console.log('Test completed, waiting before next test...');
            setTimeout(() => {
                // 重新加载主页以开始新的测试
                window.location.href = '/';
            }, config.resultDelay);
        } else {
            // 如果测试还未完成,继续检查
            setTimeout(checkTestComplete, 1000);
        }
    }

    // 初始化函数
    function initialize() {
        // 如果当前在结果页面,等待后返回主页
        if (isResultPage()) {
            setTimeout(() => {
                window.location.href = '/';
            }, config.resultDelay);
            return;
        }

        // 等待页面加载完成后开始测试
        setTimeout(() => {
            startTest();
        }, config.initialDelay);
    }

    // 启动脚本
    initialize();
})();