forked from maxwellyue/autojs_script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
123 lines (111 loc) · 3.27 KB
/
main.js
File metadata and controls
123 lines (111 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* 必备软件
* 1、虚拟定位:大牛助手
* 2、虚拟步数:大牛助手
* 2、虚拟IP:
*/
/**
* 执行规则
* 1、顺序执行
* 2、0-7点不执行
* 3、每次阅读10篇文章
* 4、阅读时候,需要有一定的停顿
*/
init();
function init(){
storages.remove("version");
//每次阅读的时间
var normalRumTime = 0.5*60*60;
while(true){
var config = getConfig();
//新闻类的列表
var newsList = config.newsAppList;
//视频类的列表
var videoList = config.videoAppList;
/**
* 0-7点阅读视频
* 其他时间阅读新闻
*/
if(new Date().getHours() >= 7){
var appNum = newsList.length;
for(var i = 0;i< appNum;i++){
exec(newsList[i].name,normalRumTime);
}
}else{
//TODO
sleep(1000*60*30);//睡眠半个小时
}
}
}
//获取主配置
function getConfig(){
toast("开始获取配置");
var url = "https://raw.githubusercontent.com/maxwellyue/autojs_script/master/config.json";
var str = http.get(url)
str = JSON.parse(str.body.string());
toast("配置获取完成");
return str;
}
//执行脚本
function exec(scriptName,seconds){
//自动获取脚本更新
updateScript(scriptName);
//开始执行
var startDate = new Date();//开始时间
var exectuion = engines.execScriptFile("/sdcard/脚本/"+scriptName+".js");
//计时器,检测时间
var isIExec = true;
while(isIExec){
//计时
var runSeconds = ((new Date().getTime()) - startDate.getTime())/1000;
toast(scriptName+"已执行"+runSeconds +"秒");
if(runSeconds > seconds){
isIExec = false;
}
sleep(60*1000);//每一分钟检测一次
//检测当前执行的任务是否已经完成
//如果发现只有一个进程,则跳转到下一个
if(engines.all().length < 2){
isIExec = false;
stopCurrent(exectuion);
}
}
//停止脚本
stopCurrent(exectuion);
}
//停止当前脚本
function stopCurrent(exectuion){
toast("执行停止");
exectuion.getEngine().forceStop();
sleep(2000);
back();
sleep(1000);
back();
sleep(1000);
home();
sleep(5000);
}
//更新脚本
function updateScript(scriptName){
toast("检测脚本更新");
var storage = storages.create("version");
var scriptVersion = storage.get(scriptName);
var config = getConfig();
var newsAppList = config.newsAppList;
for(var i = 0; i< newsAppList.length;i++){
var thisScript = newsAppList[i];
var name = thisScript.name;
var version = thisScript.version;
if(scriptName == name && version != scriptVersion){
toast("检测开始更新");
var path = "/sdcard/脚本/"+scriptName+".js";
var scriptContent = http.get("https://raw.githubusercontent.com/maxwellyue/autojs_script/master/"+scriptName+".js").body.string();
files.write(path,scriptContent);
storage.put(scriptName,version);
toast("检测更新完成");
return true;
}
toast("检测无需更新");
return false;
}
}