最近看到一個開源專案:螞蟻森林能量自動識訓腳本,有沒有問題呀?開源專案地址:https://github.com/SuperMonster003/Ant-Forest
-----------------------------------------------------------------------
/**
* @description alipay ant forest intelligent collection script
*
* @since Nov 16, 2020
* @version 1.9.25
* @author SuperMonster003 {@link https://github.com/SuperMonster003}
*
* @see {@link https://github.com/SuperMonster003/Ant_Forest}
*/
'use strict';
let $$init = {
check() {
checkAlipayPackage();
checkModulesMap();
checkSdkAndAJVer();
checkProviderSettings();
checkRootAccess();
checkAccessibility();
return this;
// tool function(s) //
function checkAlipayPackage() {
let _pkg = "com.eg.android.AlipayGphone";
let _pkg_mgr = context.getPackageManager();
let _app_name, _app_info;
try {
_app_info = _pkg_mgr.getApplicationInfo(_pkg, 0);
_app_name = _pkg_mgr.getApplicationLabel(_app_info);
} catch (e) {
showSplitLineRaw();
console.warn(e.message);
console.warn(e.stack);
}
if (!_app_name) {
let _msg = '此設備可能未安裝"支付寶"應用';
toast(_msg);
showSplitLineRaw();
console.error("腳本無法繼續");
console.error(_msg);
showSplitLineRaw();
exit();
}
global._$_pkg_name = _pkg;
}
function checkModulesMap() {
void [
"MODULE_MONSTER_FUNC", "MODULE_STORAGE",
"MODULE_DEFAULT_CONFIG", "MODULE_PWMAP",
"MODULE_TREASURY_VAULT", "MODULE_UNLOCK",
"EXT_DIALOGS", "EXT_TIMERS", "EXT_DEVICE",
"EXT_APP", "EXT_IMAGES", "EXT_ENGINES"
].filter((mod) => (
!files.exists("./Modules/" + mod + ".js")
)).some((mod, idx, arr) => {
let _str = "";
_str += "腳本無法繼續|以下模塊缺失或路徑錯誤:|";
_str += "- - - - - - - - - - - - - - - - -|";
arr.forEach(n => _str += '-> "' + n + '"|');
_str += "- - - - - - - - - - - - - - - - -|";
_str += "請檢查或重新放置模塊";
showSplitLineRaw();
_str.split("|").forEach(s => messageActionRaw(s, 4));
showSplitLineRaw();
toast("模塊缺失或路徑錯誤", "Long");
exit();
});
}
function checkSdkAndAJVer() {
// do not `require()` before `checkModulesMap()`
global.$_app = require("./Modules/MODULE_MONSTER_FUNC").checkSdkAndAJVer();
}
function checkProviderSettings() {
// checker for legacy bug (before v1.9.24 Beta)
// which may cause a tiny value for `System.SCREEN_OFF_TIMEOUT`
let System = android.provider.Settings.System;
let _scr_off_tt = System.SCREEN_OFF_TIMEOUT;
let _ctx_reso = context.getContentResolver();
let _scr_off_tt_val = System.getInt(_ctx_reso, _scr_off_tt, 0);
let _min_normal_val = 15 * 1e3; // 15 seconds
let _normal_val = 2 * 60e3; // 2 minutes
let _normal_mm = Number((_normal_val / 60e3).toFixed(2));
if (_scr_off_tt_val < _min_normal_val) {
showSplitLineRaw();
messageActionRaw("修正例外的設備螢屏超時引數");
messageActionRaw("修正值: " + _normal_val + " (" + _normal_mm + "分鐘)");
System.putInt(_ctx_reso, _scr_off_tt, _normal_val);
}
}
function checkRootAccess() {
global._$_autojs_has_root = require("./Modules/EXT_APP").hasRoot();
global._$_autojs_has_secure = require("./Modules/EXT_APP").hasSecure();
}
function checkAccessibility() {
let _line = showSplitLineRaw;
let _getDash = () => "- ".repeat(17).trim();
let _msg = messageActionRaw;
_checkSvc();
_checkFunc();
// tool function(s) //
function _checkSvc() {
// do not `require()` before `checkModulesMap()`
let _a11y = require("./Modules/EXT_DEVICE").a11y;
if (_a11y.state()) {
return;
}
let _perm = "android.permission.WRITE_SECURE_SETTINGS";
let _pkg_n_perm = context.packageName + " " + _perm;
let _mod_mon = require("./Modules/MODULE_MONSTER_FUNC");
let _mod_sto = require("./Modules/MODULE_STORAGE");
let $_cfg = _mod_sto.create("af_cfg").get("config", {});
if ($_cfg.auto_enable_a11y_svc === "ON") {
_tryEnableAndRestart();
if (global._$_autojs_has_root) {
shell("pm grant " + _pkg_n_perm, true);
_tryEnableAndRestart();
}
_failedHint();
}
if (typeof auto.waitFor !== "function") {
try {
auto();
} catch (e) {
// consume errors msg caused by auto()
}
exit();
}
let _thd = threads.start(function () {
// script will continue running rather than stop
// when accessibility service enabled by user
auto.waitFor();
});
_thd.join(60e3);
if (_thd.isAlive()) {
_line();
_msg("等待用戶開啟無障礙服務超時", 4, 1);
_line();
exit();
}
// tool function(s) {
function _failedHint() {
let _shell_sc = "adb shell pm grant " + _pkg_n_perm;
_line();
_msg("自動開啟無障礙服務失敗", 4);
if (!global._$_autojs_has_secure) {
_line();
_msg("Auto.js缺少以下權限:", 4);
_msg("WRITE_SECURE_SETTINGS", 4);
_line();
_msg("可嘗試使用ADB工具連接手機", 3);
_msg("并執行以下Shell指令(無換行):\n" +
"\n" + _shell_sc + "\n", 3);
_msg("Shell指令已復制到剪切板", 3);
_msg("重啟設備后授權不會失效", 3);
setClip(_shell_sc);
}
}
function _tryEnableAndRestart() {
if (_a11y.enable(true)) {
_line();
_msg("已自動開啟無障礙服務");
_msg("嘗試一次專案重啟操作");
_line();
_mod_mon.restartThisEngine({
debug_info_flag: "forcible",
instant_run_flag: false,
max_restart_engine_times: 1,
});
sleep(5e3);
exit();
}
}
}
function _checkFunc() {
let _max = 24;
while (!press(1e8, 0, 1) && _max--) {
sleep(50);
}
if (_max < 0) {
_line();
void ("腳本無法繼續|無障礙服務狀態例外|或基于服務的方法無法使用|"
+ _getDash() + "|可嘗試以下解決方案:|" + _getDash()
+ '|a. 卸載并重新安裝"Auto.js"|b. 安裝后重啟設備'
+ '|c. 運行"Auto.js"并拉出側邊欄|d. 開啟無障礙服務'
+ "|e. 再次嘗試運行本專案").split("|").forEach(s => _msg(s, 4));
_line();
toast("無障礙服務方法無法使用", "Long");
exit();
}
}
}
// raw function(s) //
function messageActionRaw(msg, lv, if_toast) {
let _msg = msg || " ";
if (lv && lv.toString().match(/^t(itle)?$/)) {
return messageActionRaw("[ " + msg + " ]", 1, if_toast);
}
if_toast && toast(_msg);
let _lv = typeof lv === "undefined" ? 1 : lv;
if (_lv >= 4) {
console.error(_msg);
_lv >= 8 && exit();
return false;
}
if (_lv >= 3) {
console.warn(_msg);
return false;
}
if (_lv === 0) {
console.verbose(_msg);
} else if (_lv === 1) {
console.log(_msg);
} else if (_lv === 2) {
console.info(_msg);
}
return true;
}
function showSplitLineRaw(extra, style) {
console.log((
style === "dash" ? "- ".repeat(18).trim() : "-".repeat(33)
) + (extra || ""));
}
},
global() {
setGlobalFunctions();
setGlobalExtensions();
setGlobalObjects();
setGlobalFlags();
setGlobalLog();
debugInfo("開發者測驗日志已啟用", "Up_both_dash");
debugInfo("設備型號: " + device.brand + " " + device.product);
appSetter().setEngine().setTask().setParams().setBlist().setPages().init();
accSetter().setParams().setMain();
debugInfo("Auto.js版本: " + $$app.autojs_ver);
debugInfo("專案版本: " + $$app.project_ver);
debugInfo("安卓SDK版本: " + $$app.sdk_ver);
debugInfo("安卓系統版本號: " + device.release);
debugInfo("Root權限: " + ($$app.has_root ? "有效" : "無效"));
return this;
// tool function(s) //
function setGlobalFunctions() {
require("./Modules/MODULE_MONSTER_FUNC").load([
"clickAction", "swipeAndShow", "setIntervalBySetTimeout", "keycode",
"getSelector", "equa
uj5u.com熱心網友回復:
太長了,沒細看。。。轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/249269.html
標籤:JavaScript
上一篇:tomcat埠少了一個
下一篇:vue3怎么兄弟傳參
