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 整理发布!!

猜你喜欢

转载自blog.csdn.net/m0_55125030/article/details/116990243