WaitUntil

等待满足某种条件后执行,目前不支持嵌套调用

As of 2023-04-01. See the latest version.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/412875/1169576/WaitUntil.js

Author
wish king
Version
0.1.1
Created
2020-10-11
Updated
2023-04-01
License
N/A

等待满足某种条件后执行,这是什么库?
当你在写脚本时,有没有遇到过想等待某个元素加载完执行,或者等待jQuery加载完执行,或者满足多个条件后执行的情况?
如果有,那么这个脚本就是解决这个问题的
它有两个重要的参数,第一个是满足条件的函数,第二个是条件满足后执行的回调函数
注意:目前它不支持嵌套调用


//使用示例

WaitUntil(function(){return typeof jQuery !=="undefined" && $(".test").length>0}, function(){
    alert($(".test").html());
});

//其他参数
//condfunc 满足条件的函数
//callback 条件满足后执行的回调函数
//interval 监听满足条件的时间间隔,单位毫秒,默认100
//trys 尝试次数,超过这个数值就停止监听,默认为300(因默认间隔是100毫秒,所以默认停止监控时间为300*100毫秒,即30秒)
//times 执行次数,默认执行1次