You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求Tampermonkey自动点击无ID按钮的延时脚本

Tampermonkey延时自动点击脚本

直接使用以下脚本即可实现需求,核心逻辑是设置延时后定位目标按钮并触发点击:

// ==UserScript==
// @name         延时自动点击按钮
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  延时自动点击指定按钮
// @author       Your Name
// @match        替换为目标页面的URL
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 设置延时时间(单位:毫秒,示例为3秒)
    const delayTime = 3000;

    setTimeout(() => {
        // 使用你提供的选择器定位按钮
        const targetBtn = document.querySelector("#al_login > div.col-sm-8.container.paddingInBoxExtra.roundCornerExtra > div:nth-child(2) > input.row.btn.primary-btn.pull-right.marginBottomNone");
        
        // 确认按钮存在后再点击,避免报错
        if (targetBtn) {
            targetBtn.click();
            console.log("已自动点击目标按钮");
        } else {
            console.log("未找到目标按钮");
        }
    }, delayTime);
})();

注意事项

  • 替换@match后的内容为目标按钮所在页面的完整URL,比如https://example.com/login
  • 可根据需求调整delayTime的数值,修改延时时长
  • 如果页面加载较慢导致按钮未及时出现,可改用循环检测版本的脚本,确保找到按钮后再点击:
// ==UserScript==
// @name         延时自动点击按钮(循环检测版)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  延时后循环检测并点击指定按钮
// @author       Your Name
// @match        替换为目标页面的URL
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 设置初始延时时间(单位:毫秒)
    const initialDelay = 1000;
    // 循环检测间隔(单位:毫秒)
    const checkInterval = 500;

    setTimeout(() => {
        const checkBtnInterval = setInterval(() => {
            const targetBtn = document.querySelector("#al_login > div.col-sm-8.container.paddingInBoxExtra.roundCornerExtra > div:nth-child(2) > input.row.btn.primary-btn.pull-right.marginBottomNone");
            
            if (targetBtn) {
                targetBtn.click();
                console.log("已自动点击目标按钮");
                clearInterval(checkBtnInterval); // 停止检测
            } else {
                console.log("未找到目标按钮,继续检测...");
            }
        }, checkInterval);
    }, initialDelay);
})();

内容的提问来源于stack exchange,提问作者Younes BEC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 03:45:36