gpt4 book ai didi

javascript - 设置等待时间,延迟时间,执行脚本

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:41 25 4
gpt4 key购买 nike

greasemonkey 的这个脚本对我有用,当加载某个网站时单击按钮。

但是如何设置等待时间呢?示例:网站已加载,脚本等待 1 秒直到执行。

我的第二个问题是:如何在每次加载页面时只运行一次?脚本一遍又一遍地开始。

    // ==UserScript==
// @name _YOUR_NAME
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/

function clickSubmitBtnWhenItAppears (jNode) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
jNode[0].dispatchEvent (clickEvent);
}

//-- Value match is case-sensitive
waitForKeyElements (
//"#btn_submit input[type='submit'][value*='Click Me Now']",
"input[type='submit'][value*='Click Me Now']",
clickSubmitBtnWhenItAppears
);

脚本来源:How do I get Greasemonkey to click on a button that only appears after a delay?

最佳答案

这可能是您正在寻找的:

$(document).ready(function() { //When document has loaded

setTimeout(function() {

//Code to run After timeout elapses

}, 2000); //Two seconds will elapse and Code will execute.

});

关于javascript - 设置等待时间,延迟时间,执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32537330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com