Greasy Fork镜像 支持简体中文。

WaitFor

一直等待并执行回调函数

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/464516/1179152/WaitFor.js

  1. // ==UserScript==
  2. // @name WaitFor
  3. // @namespace http://bbs.91wc.net/?wait-for
  4. // @version 0.1
  5. // @description 一直等待并执行回调函数
  6. // @author Wilson
  7. // ==/UserScript==
  8.  
  9. function WaitFor(cond, callback, delay) {
  10. delay = delay || 100;
  11. var timer = setTimeout(function(){
  12. if(timer) clearTimeout(timer);
  13. if(cond && cond()) callback();
  14. WaitFor(cond, callback, delay);
  15. }, delay);
  16. }
  17.  
  18. //使用:
  19. //WaitFor(()=>{return true}, ()=>{console.log(1)});
  20. //cond 条件回调函数,当cond()为真则执行callback
  21. //callback 回调函数
  22. //delay 多久检查一次条件,单位ms,默认100

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址