Files
2024-09-30 10:59:36 +08:00

654 lines
18 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
let db = require("./core.sqlite.js")
let consts = require("./consts.js")
let _global_duration = 1000;
let userList = [];
text("发私信").find().forEach((item, idx) => {
let obj =
userList.push({
obj: item,
name: item.parent().parent().child(1).child(0).child(0).text(),
})
})
let global = {
setDuration: function (duration) {
_global_duration = duration
},
}
let store = storages.create("_##_@_DY_Proxy");
const project = "autojs"
let pwdFile = function (path) {
let pwd = engines.myEngine().cwd()
if (!path) {
return pwd
}
if (path) {
path = path.replace(/^\//, "")
}
return `${pwd}/${project}/${path}`.replace(/\/\//g, "/").replace(/\/$/, "")
}
let pageUser = {
activity: "com.ss.android.ugc.aweme.profile.ui.UserProfileActivity",
wait: function () {
waitForActivity(this.activity)
},
open: function () {
home()
sleep(500)
let activity = "snssdk1128://user/profile"
app.startActivity({
packageName: consts.Package.DouYin,
action: "android.intent.action.VIEW",
data: activity,
});
let appId = id(consts.AppID()).findOne(1000)
if (appId) {
appId.click()
}
waitForActivity("com.ss.android.ugc.aweme.main.MainActivity")
this.clickTabMe()
},
openUser: function (uid) {
let activity = "snssdk1128://user/profile/{uid}".replace("{uid}", uid)
app.startActivity({
packageName: consts.Package.DouYin,
action: "android.intent.action.VIEW",
data: activity,
});
let appId = id(consts.AppID()).findOne(1000)
if (appId) {
appId.click()
}
for (let i = 0; i <= 10; i++) {
sleep(1000)
if (currentActivity() != "com.ss.android.ugc.aweme.profile.ui.UserProfileActivity") {
if (i == 10) {
return false
}
continue
}
break
}
return true
},
gotoFriend: function () {
className("com.bytedance.highperformanceview.layout.MeasureOnceRelativeLayout2").find()[2].click()
waitForActivity("com.ss.android.ugc.aweme.following.ui.FollowRelationTabActivity")
sleep(2000)
return true
},
getStatistics: function () {
let statistics = {
like: 0,
friend: 0,
focus: 0,
fans: 0,
}
className("com.bytedance.highperformanceview.layout.MeasureOnceRelativeLayout2").find().forEach((item, index) => {
let tv = item.findOne(className("android.widget.TextView"))
if (tv) {
let text = tv.text()
switch (index) {
case 0:
statistics.like = parseInt(text)
case 1:
statistics.focus = parseInt(text)
case 2:
statistics.fans = parseInt(text)
case 3:
statistics.friend = parseInt(text)
}
}
})
store.put("__statistics", statistics)
return statistics
},
hasNewFriend: function () {
let statistics = store.get("__statistics", {
like: 0,
friend: 0,
focus: 0,
fans: 0,
})
let currentStatistics = this.getStatistics()
if (currentStatistics.friend > statistics.friend) {
return true
}
return false
},
hasPublishItems: function () {
let txt = "还没有作品"
let id = "com.ss.android.ugc.aweme:id/title"
let elem = text(txt).findOne(2 * 1000)
if (!elem) {
return true
}
return !(elem.id() == id)
},
getBtnGuanZhu: function () {
let txt = "关注"
let _class = "android.widget.TextView"
let elems = text(txt).find()
if (elems.empty()) {
return false
}
let elem = elems.find(className(_class)).findOne(clickable())
if (!elem) {
return false
}
return elem
},
getBtnBianJiZiLiao: function () {
let _desc = "编辑资料"
let _class = "android.view.ViewGroup"
let elem = className(_class).find().findOne(descStartsWith(_desc))
if (!elem) {
log("找不到编辑资料")
return false
}
return elem
},
getBtnSiXin: function () {
let txt = "私信"
let desc = "私信"
let elem = text(txt).findOne(2 * _global_duration)
if (!elem) {
log("找不到私信按钮")
return false
}
if (elem.desc() != desc) {
log("私信按钮 desc 不匹配")
return false
}
return elem
},
hasProduce: function () {
let _text = "还没有作品"
let elem = text(_text).findOne(1000)
if (!elem) {
return true
}
return false
},
getIPLocation: function () {
let txt = "IP"
let elem = textStartsWith(txt).findOne(1000)
if (!elem) {
log("找不到 IP 标签 id")
return false
}
return elem.text().replace(txt, "").trim()
},
clickBtnSiXin: function () {
let elem = this.getBtnSiXin()
if (!elem) {
return false
}
elem.click()
sleep(2 * _global_duration)
return true
},
clickBtnGuanZhu: function () {
let elem = this.getBtnGuanZhu()
if (!elem) {
return false
}
elem.click()
sleep(2 * _global_duration)
return true
},
clickTabMe: function () {
let pt = className("android.widget.TextView").find().findOne(text("我")).bounds()
click(pt.centerX(), pt.centerY())
sleep(1000)
},
}
let pageChat = {
getBtnVoice: function () {
let _desc = "语音"
let _class = "android.widget.Button"
let elem = className(_class).find().findOne(desc(_desc))
if (!elem) {
return false
}
return elem
},
getBtnMyLoveSend: function () {
let _txt = "发送"
let _id = "com.ss.android.ugc.aweme:id/send"
let elem = id(_id).findOne(2 * _global_duration)
if (!elem) {
log("找不到发送按钮")
return false
}
return elem
},
getMyLoveFirstProduct: function () {
let _class = "com.bytedance.ies.dmt.ui.widget.DmtTextView";
let loves = className(_class).find()
if (loves.empty()) {
log("找不到我的喜欢")
return false
}
return loves.shift()
},
getMyLoveButton: function () {
let _txt = "我的喜欢"
let elem = null;
let times = 0
while (times++ < 10) {
elem = className("android.widget.Button").find().findOne(desc(_txt))
if (elem) {
return elem
}
elem = className("android.widget.TextView").find().findOne(text(_txt))
if (!elem) {
sleep(1000)
continue
}
elem = elem.parent()
break
}
if (times > 10) {
log("找不到 我的喜欢 按钮")
return false
}
return elem
},
getPanelMore: function () {
let _class = "androidx.viewpager.widget.ViewPager"
let elem = className(_class).findOne(2 * _global_duration)
if (!elem) {
log("找不到 更多面板")
return false
}
return elem
},
getBtnCloseMore: function () {
let _desc = "关闭面板"
let _class = "android.widget.Button"
let elem = className(_class).find().findOne(desc(_desc))
if (!elem) {
log("找不到关闭面板按钮")
return false
}
return elem
},
getBtnMore: function () {
let _desc = "更多面板"
let _class = "android.widget.Button"
let elem = className(_class).find().findOne(desc(_desc))
if (!elem) {
log("找不到更多面板按钮")
return false
}
// log(elem.id())
return elem
},
clickBtnCloseMore: function () {
let elem = this.getBtnCloseMore()
if (!elem) {
return false
}
log("点击更多按钮")
elem.click()
sleep(_global_duration)
return true
},
clickBtnMore: function () {
if (desc("关闭面板").findOne(2 * _global_duration)) {
return true
}
let elem = this.getBtnMore()
if (!elem) {
return false
}
elem.click()
sleep(2 * _global_duration)
return true
},
swipeMorePanelRight: function () {
let elem = this.getPanelMore()
if (!elem) {
return false
}
// elem.scrollLeft()
let x = elem.bounds().centerX() + elem.bounds().width() / 4
let y = elem.bounds().centerY()
let x1 = elem.bounds().left
let y1 = elem.bounds().centerY()
log(x, y, x1, y1)
swipe(x, y, x1, y1, 200)
sleep(_global_duration)
return true
},
swipeMorePanelLeft: function () {
let elem = this.getPanelMore()
if (!elem) {
return false
}
let x = elem.bounds().centerX() - elem.bounds().width() / 4
let y = elem.bounds().centerY()
let x1 = elem.bounds().right
let y1 = elem.bounds().centerY()
log(x, y, x1, y1)
swipe(x, y, x1, y1, 200)
sleep(_global_duration)
return true
},
clickBtnMyLove: function () {
let elem = this.getMyLoveButton()
if (!elem) {
return false
}
elem.click()
// click(elem.bounds().centerX(), elem.bounds().centerY())
sleep(_global_duration)
return true
},
clickBtnMyLoveFirstProduct: function () {
let elem = this.getMyLoveFirstProduct()
if (!elem) {
return false
}
log(elem.className())
click(elem.bounds().centerX(), elem.bounds().centerY())
sleep(_global_duration)
return true
},
clickBtnMyLoveSend: function () {
let elem = this.getBtnMyLoveSend()
if (!elem) {
return false
}
elem.click()
sleep(_global_duration)
return true
},
pressBtnVoice: function (duration) {
let elem = this.getBtnVoice()
if (!elem) {
return false
}
press(elem.bounds().centerX(), elem.bounds().centerY(), duration)
sleep(_global_duration)
return true
},
sendAudioVoice: function (voice) {
let elem = this.getBtnVoice()
if (!elem) {
log("找不到 语音 按钮")
return false
}
var musicDuration = threads.disposable();
threads.start(function () {
sleep(500)
//播放音乐
media.playMusic(files.path(`audio/${voice}.m4a`));
media.pauseMusic()
//让音乐播放完
let duration = media.getMusicDuration()
musicDuration.setAndNotify(duration)
sleep(500)
media.resumeMusic()
sleep(duration);
});
let duration = musicDuration.blockedGet()
press(elem.bounds().centerX(), elem.bounds().centerY(), 1000 + duration)
sleep(_global_duration)
return true
},
isSendVoiceMode: function () {
let _txt = "按住 说话"
return text(_txt).findOne(2 * _global_duration)
},
getBtnVoiceToTxt: function () {
return desc("文本").findOne(2 * _global_duration)
},
getInputSendTxt: function () {
return text("发送消息").findOne(2 * _global_duration)
},
clickInputSendTxt: function () {
let elem = this.getInputSendTxt()
if (!elem) {
log("找不到发送消息输入框")
return false
}
elem.click()
sleep(_global_duration)
return true
},
getBtnSendTxt: function () {
return desc('发送').findOne(2 * _global_duration)
},
sendText: function (txt) {
if (this.isSendVoiceMode()) {
let elem = this.getBtnVoiceToTxt()
if (!elem) {
return false
}
elem.click()
sleep(_global_duration)
}
elem = this.getInputSendTxt()
if (!elem) {
log("找不到发送消息输入框")
return false
}
elem.setText(txt)
sleep(_global_duration)
if (!this.getBtnSendTxt().click()) {
log("找不到发送按钮")
return false
}
return true
}
}
let pageFriend = {
activity: "com.ss.android.ugc.aweme.following.ui.FollowRelationTabActivity",
wait: function () {
lib.waitForActivity(_activity)
},
open: function () {
// app.startActivity(this.activity)
},
getFriends: function () {
let userList = [];
text("发私信").find().forEach((item, idx) => {
let name = item.parent().parent().child(1).child(0).child(0).text()
// log("check name exists", name)
if (db.existsUser(name)) {
return
}
userList.push({ button: item, name: name })
})
return userList
}
}
let st = {
times: function (times) {
if (times != undefined) {
return store.put('__times', times)
}
return store.get('__times', 0)
},
addTimes: function () {
return store.put('__times', this.times() + 1)
},
voice: function (voice) {
if (voice != undefined) {
return store.put('__voice', voice)
}
return store.get('__voice', "default")
},
produce: function (produce) {
if (produce != undefined) {
return store.put('__produce', produce)
}
return store.get('__produce', false)
},
name_keyword: function (keyword) {
if (keyword != undefined) {
return store.put('__name_keyword', keyword)
}
return store.get('__name_keyword', [])
},
default_avatar: function (avatar) {
if (avatar != undefined) {
return store.put('__default_avatar', avatar)
}
return store.get('__default_avatar', false)
},
default_name: function (name) {
if (name != undefined) {
return store.put('__default_name', name)
}
return store.get('__default_name', false)
},
region: function (region) {
if (region != undefined) {
return store.put('__region', region)
}
return store.get('__region', [])
},
wechat: function (wechat) {
if (wechat != undefined) {
return store.put('__wechat', wechat)
}
return store.get('__wechat', "")
},
hello: function (hello) {
if (hello != undefined) {
return store.put('__hello', hello)
}
return store.get('__hello', "你好")
},
host: function (h) {
if (h) {
store.put("__host", h)
return h
}
let host = store.get("__host", "")
if (host.length == 0) {
host = "https://f.jdwan.com"
store.put("__host", host)
}
return host
},
lastID: function (id) {
if (id) {
return store.put('__lastID', id)
}
return store.get('__lastID', 0)
},
config_version: function (version) {
if (version) {
return store.put('__configVersion', version)
}
return store.get('__configVersion', 0)
},
}
module.exports = {
duration: 1000,
global: global,
page: {
user: pageUser,
chat: pageChat,
friend: pageFriend,
},
store: st,
kill: function () {
let name = consts.Package.DouYin
app.openAppSetting(name);//通过包名打开应用的详情页(设置页)
text(app.getAppName(name)).waitFor();//通过包名获取已安装的应用名称判断是否已经跳转至该app的应用设置界面
sleep(500);//稍微休息一下,不然看不到运行过程,自己用时可以删除这行
let is_sure = textMatches(/(.*强.*|.*停.*|.*结.*)/).findOne();//在app的应用设置界面找寻包含“强”“停”“结”“行”的控件
//特别注意应用设置界面可能存在并非关闭该app的控件但是包含上述字样的控件如果某个控件包含名称“行”字
//textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/)改为textMatches(/(.*强.*|.*停.*|.*结.*)/)
//或者结束应用的控件名为“结束运行”直接将textMatches(/(.*强.*|.*停.*|.*结.*|.*行.*)/)改为text("结束运行")
if (is_sure.enabled()) {//判断控件是否已启用想要关闭的app是否运行
is_sure.parent().click();//结束应用的控件如果无法点击,需要在布局中找寻它的父控件,如果还无法点击,再上一级控件,本案例就是控件无法点击
textMatches(/(.*确.*|.*定.*)/).findOne().click();//需找包含“确”,“定”的控件
log(app.getAppName(name) + "应用已被关闭");
sleep(1000);
back();
} else {
log(app.getAppName(name) + "应用不能被正常关闭或不在后台运行");
back();
}
},
}