Autojs多个js脚本依次执行的代码分享

// 此代码由autojs开发交流群整理提供,如有侵权,请联系我删除!

 很多时候我们会有这样一个场景:一个合集脚本,下面会依次执行多个子js脚本。那么这个代码要如何写呢?大家可以参考下面的写法:

// 在此处给脚本排队即可
let filePathList = ["1.js", "2.js", "3.js"];

filePathList = filePathList.map(function (filePath) {
  return files.path(filePath);
});

events.on("exit", function () {
  log("exit");
});

setInterval(function () {}, 1000);

let limitTime = 3000;

while (1) {
  if (filePathList.length > 0) {
    let e = engines.execScriptFile(filePathList[0]);
    while (!e.getEngine()); //等待脚本运行
    let currentScriptEngine = e.getEngine();
    let lastTime = new Date().getTime();
    while (1) {
      let currentTime = new Date().getTime();
      if (currentTime - lastTime > limitTime) {
        log("脚本运行超时, 开始 执行销毁命令");
        currentScriptEngine.forceStop();
        log("脚本运行超时, 结束 执行销毁命令");
        break;
      }
      if (currentScriptEngine.isDestroyed()) {
        break;
      } else {
        sleep(100);
      }
    }
  } else {
    engines.myEngine().forceStop();
  }
  filePathList.shift();
}
//脚本源码,由资源库:zwk123.com 整理发布!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiaowei19970701

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值