forked from intermezzi/777
-
Notifications
You must be signed in to change notification settings - Fork 0
/
floating.js
120 lines (107 loc) · 3.53 KB
/
floating.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
//toastLog(" 请在无障碍中选择本 APP");
auto.waitFor();
let window = floaty.window(
<vertical>
<button id="move" text=" 移动 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="switchXX" text=" 切到 强国 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="startBrowse" text=" 开始浏览 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="startCSC" text=" 收藏分享评论 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="startChallengeAnswer" text=" 挑战答题 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="startDailyAnswer" text=" 每日答题等 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="stop" text=" 停止 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
<button id="exit" text=" 退出悬浮窗 " w="90" h="35" bg="#77ffffff" textSize="10sp" />
</vertical>
);
let deviceWidth = device.width;
let deviceHeight = device.height;
window.setPosition(deviceWidth * 0.7, deviceHeight*0.4);
setInterval(() => {
}, 1000);
let wx, wy, downTime, windowX, windowY;
// 这个函数是对应悬浮窗的移动
window.move.setOnTouchListener(function (view, event) {
switch (event.getAction()) {
case event.ACTION_DOWN:
wx = event.getRawX();
wy = event.getRawY();
windowX = window.getX();
windowY = window.getY();
downTime = new Date().getTime();
return true;
case event.ACTION_MOVE:
// 如果按下的时间超过 xx 秒判断为长按,调整悬浮窗位置
if (new Date().getTime() - downTime > 300) {
window.setPosition(windowX + (event.getRawX() - wx), windowY + (event.getRawY() - wy));
}
return true;
case event.ACTION_UP:
// 手指弹起时如果偏移很小则判断为点击
if (Math.abs(event.getRawY() - wy) < 30 && Math.abs(event.getRawX() - wx) < 30) {
toastLog(" 长按调整位置 ")
}
return true;
}
return true;
});
window.switchXX.click(() => {
toastLog(" 切换到学习强国APP...");
launch("cn.xuexi.android");
});
// 这个函数是对应悬浮窗的退出
window.exit.click(() => {
toastLog(" 退出!");
exit();
});
let th = null;
//浏览
window.startBrowse.click(() => {
let ss = "./xxqg_v3.1.0(无UI).js";
startTh(ss);
});
//收藏评论分享
window.startCSC.click(() => {
let ss = "./collectShareComment.js";
startTh(ss);
});
//挑战答题
window.startChallengeAnswer.click(() => {
let ss = "./challengeAnswer.js";
startTh(ss);
});
//每日答题
window.startDailyAnswer.click(() => {
let ss = "./dailyAnswer.js";
startTh(ss);
});
//停止
window.stop.click(() => {
if (th == null) {
toastLog(" 没有进行中的脚本 ");
} else {
if (th.isAlive()) {
threads.shutDownAll();
toastLog(" 停止!");
} else {
toastLog(" 没有进行中的脚本 ");
}
}
});
function startTh(fileStr){
let ss=fileStr;
if (th == null) {
th = threads.start(function () {
toastLog(" 开启线程");
let begin = require(ss);
begin();
});
} else {
if (th.isAlive()) {
toastLog(" 脚本都在运行了你还点!?");
} else {
th = threads.start(function () {
let begin = require(ss);
begin();
});
}
}
}