auto.waitFor(); const deviceID = device.getAndroidId() log(`设备号 ${deviceID}`); let e = null; let canAutoRun = false; let CheckVersion = function () { log("检查更新") let version = "0.0.0" if (files.isFile("version.txt")) { version = files.read("version.txt"); version = version.trim() } let store = storages.create("_##_@_DY_Proxy"); let host = store.get("__host", "") if (host.length == 0) { host = "https://f.jdwan.com" } let url = "{host}/api/version" url = url.replace("{host}", host) log("url =", url) let headers = { headers: { "Authorization": "Basic cm9nZWVjbjp4aXhpQDAyMDI=" } } try { let resp = http.get(url, headers) if (resp.statusCode != 200) { log("更新请求失败, statusCode: ", resp.statusCode) canAutoRun = true return false } let body = resp.body.json() if (body == null) { log("没有新的数据") canAutoRun = true return false } if (body.version == version) { canAutoRun = true return false } log(`有新版本 ${body.version} 当前版本: ${version}, 开始更新`) if (e && !e.getEngine().isDestroyed()) { canAutoRun = false e.getEngine().forceStop() } body.files.forEach((file, index) => { log("下载文件: ( " + (index + 1) + " / " + body.files.length + ")" + file) let url = "{host}/api/version/file/{file}" url = url.replace("{host}", host).replace("{file}", file) let resp = http.get(url, headers) if (resp.statusCode != 200) { log(`下载文件(${file})失败, statusCode: ${resp.statusCode}`) return } let path = files.path(file) files.createWithDirs(path) files.writeBytes(path, resp.body.bytes()) }) } catch (e) { log("更新请求失败, ", e) canAutoRun = true return false } canAutoRun = true log("更新完成") return true } events.on("exit", function () { log("结束运行"); if (e && !e.getEngine().isDestroyed()) { canAutoRun = false e.getEngine().forceStop() } }); CheckVersion() setInterval(CheckVersion, 60 * 1000) setInterval(() => { let activity = currentActivity() if ("com.ss.android.ugc.aweme.update.dialog.ui.UpdateNotifyDialog" == activity) { let btn = text("以后再说").findOne(500) if (btn) { btn.click() } } if ("com.ss.android.ugc.aweme.account.business.logout.LogoutDialogActivity" == activity) { // todo: 退出登录 let btn = text("我知道了").findOne(500) if (btn) { btn.click() } } if ("com.bytedance.dux.dialog.alert.DuxAlertDialog" == activity) { let btn = text("拒绝").findOne(500) if (btn) { btn.click() } } }, 1000) setInterval(() => { if (!canAutoRun) { return } if (e && !e.getEngine().isDestroyed()) { return } let path = files.path("runner.js"); log("runner", path); log("开始执行脚本"); e = engines.execScriptFile(path, { loopTimes: 1, path: files.path("./"), }); }, 2000)