-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path看广告.js
148 lines (126 loc) · 3.81 KB
/
看广告.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var profile1920 = {
goldenPoint: { x: 1500, y: 1000 },
left: { x: 840, y: 735 },
right: { x: 1340, y: 735 }
}
var profile2160 = {
goldenPoint: { x: 1700, y: 1000 },
left: { x: 961, y: 730 },
right: { x: 1170, y: 730 }
}
var profile;
const height = device.height;
const width = device.width;
if (height === 1920 && width == 1080) {
profile = profile1920;
} else if ((height === 2160 || height === 2220) && width == 1080) {
profile = profile2160;
} else {
toast("Unstackable resolution.");
exit();
}
mainEntrence();
// 程序主入口
function mainEntrence() {
sleep(2000);
toast("3s to start.");
sleep(3000);
deviceInfo();
eventListener();
click(profile.goldenPoint.x, profile.goldenPoint.y);
click(profile.goldenPoint.x, profile.goldenPoint.y);
ad();
}
function deviceInfo() {
auto();
if (!requestScreenCapture()) {
toast('No captureScreen permission.');
exit();
}
console.log("height:" + height);
console.log("width:" + width);
// 调整屏幕亮度
// device.setBrightness(0);
// 调整媒体声音
device.setMusicVolume(0);
}
function eventListener() {
threads.start(function () {
// 启用按键监听
events.observeKey();
// 监听音量上键按下
events.onKeyDown("volume_down", function (event) {
toastLog("Mannualy Exit");
device.setBrightness(40);
threads.shutDownAll();
exit();
});
});
}
function ad() {
toastLog("开始为车辆补充燃油");
while (true) {
// confirm the UI
var img = captureScreen();
var left = images.pixel(img, profile.left.x, profile.left.y);
var right = images.pixel(img, profile.right.x, profile.right.y);
// toastLog("left is " + colors.toString(left));
// toastLog("right is " + colors.toString(right));
if (colors.equals(left, "#c3fb12") && colors.equals(right, "#ffffff")) {
click(profile.right.x, profile.right.y);
toastLog("开始看这个广告");
break;
}
else {
sleep(1000);
}
}
// wait for playing ad
sleep(30000);
var jump_back = 0;
while (true) {
if (!jump_back) {
toastLog("尝试返回")
back();
// sleep(1000);
// back();
sleep(5000);
}
var img = captureScreen();
var left = images.pixel(img, profile.left.x, profile.left.y);
var right = images.pixel(img, profile.right.x, profile.right.y);
var next = images.pixel(img, profile.goldenPoint.x, profile.goldenPoint.y);
// toastLog("left is " + colors.toString(left));
// toastLog("right is " + colors.toString(right));
// toastLog("next is " + colors.toString(next));
// grey blue
if (colors.equals(left, "#bababa") && colors.isSimilar(right, "#2580d8")) {
toastLog("继续广告");
click(profile.right.x, profile.right.y);
// click(profile.right.x, profile.right.y);
sleep(8000);
}
// green white
else if (colors.equals(left, "#c3fb12") && colors.equals(right, "#ffffff")) {
toastLog("看下一个广告")
ad();
}
// next is green
else if (colors.equals(next, "#c3fb12")) {
toastLog("车辆燃油已恢复");
exit();
}
// next is white
else if (colors.equals(next, "#ffffff")) {
toastLog("偶然多点一次返回,看下一个广告")
click(profile.goldenPoint.x, profile.goldenPoint.y);
ad();
}
// In progress
else {
toastLog("请稍等");
sleep(3000);
jump_back = 1;
}
}
}