抢购助手是一款自动化任务助手,模拟人工,快捷、方便、安全、高效率!
"ui";
var ColoredButton = (function() {
//继承ui.Widget
util.extend(ColoredButton, ui.Widget);
function ColoredButton() {
//调用父类构造函数
ui.Widget.call(this);
//自定义属性color,定义按钮颜色
this.defineAttr("color", (view, name, defaultGetter) => {
return this._color;
}, (view, name, value, defaultSetter) => {
this._color = value;
view.attr("backgroundTint", value);
});
}
ColoredButton.prototype.render = function() {
return (
);
}
ui.registerWidget("colored-button", ColoredButton);
return ColoredButton;
})();
var color = "#009688";
ui.statusBarColor("#ff5050")
ui.layout(
//淘宝界面
//start
//定义按钮的大小颜色和文本
//end
//京东界面
//start
//定义按钮的大小颜色和文本
//end
//苏宁界面
//start
//定义按钮的大小颜色和文本
//end
);
//=================================================================================
var 连续提交 = "无"
ui.lianxutijiao.on("check", (checked)=>{
if(checked){
连续提交= "有"
toast("已开启连续提交功能,此功能必须填写坐标!");
}
else
{
连续提交 = "无"
}
});
ui.zuobiao.click(function () {
if(ui.zuobiao.getText()=="点击获取坐标") {
ui.zuobiao.setText("取消获取坐标");
threads.start(获取坐标);
device.keepScreenOn()//保持屏幕常亮
}else{
ui.zuobiao.setText("点击获取坐标");
console.clear();
console.hide();
threads.shutDownAll();
device.cancelKeepingAwake();
}
})
ui.taobao.on("click",function(){
app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk")
})
ui.jingdong.on("click",function(){
app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk")
})
var 开启刷新 = "无"
var 提前刷新 = "无"
ui.shuaxin.on("check", (checked)=>{
if(checked){
开启刷新= "有"
提前刷新 = "有"
toast("已开启购物车自动刷新功能!");
}
else
{
开启刷新 = "无"
提前刷新 = "无"
}
});
var 自动付款 = "无"
ui.pay1.on("check", (checked)=>{
if(checked){
自动付款= "有"
toast("已开启自动付款");
}
else
{
自动付款 = "无"
}
});
var 自动勾选 = "无"
var 手动勾选 = "有"
ui.jiance.on("check", (checked)=>{
if(checked){
自动勾选= "有"
toast("已开启自动勾选商品,并检测价格进行结算!");
手动勾选 = "无"
}
else
{
自动勾选 = "无"
}
});
//淘宝密码隐藏
ui.bt1.on("check", (checked)=>{
if (ui.bt1.getText() == "隐藏密码") {
ui.bt1.setText("显示密码");
ui.h.visibility = 8;
toast("密码已隐藏!");
} else {
ui.bt1.setText("隐藏密码");
ui.h.visibility = 0;
toast("密码已显示!");
}
});
var 平台类别2="苏宁页面"
ui.model_one.on("check", (checked)=>{
if(checked){
平台类别2="苏宁页面"
toast("已切换到苏宁页面抢购模式")
}
});
ui.model_two.on("check", (checked)=>{
if(checked){
平台类别2="苏宁购物车"
toast("已切换到苏宁购物车抢购模式")
}
});
var 平台类别="京东页面"
ui.model_tree.on("check", (checked)=>{
if(checked){
平台类别="京东页面"
toast("已切换到京东页面抢购模式")
}
});
ui.model_four.on("check", (checked)=>{
if(checked){
平台类别="京东购物车"
toast("已切换到京东购物车抢购模式")
}
});
ui.model_five.on("check", (checked)=>{
if(checked){
平台类别="京东BP链接"
toast("已切换到京东BP链接抢购模式")
}
});
var 测试 = "无"
ui.ceshi.on("check", (checked)=>{
if(checked){
测试 = "有"
}
else
{
测试 = "无"
}
});
//创建选项菜单(右上角)
ui.emitter.on("create_options_menu", menu=>{
menu.add("日志");
});
//监听选项菜单点击
ui.emitter.on("options_item_selected", (e, item)=>{
switch(item.getTitle()){
case "日志":
app.startActivity("console");
break;
}
e.consumed = true;
});
activity.setSupportActionBar(ui.toolbar);
//设置滑动页面的标题
ui.viewpager.setTitles(["淘宝","京东","苏宁","其他"]);
//让滑动页面和标签栏联动
ui.tabs.setupWithViewPager(ui.viewpager);
//让工具栏左上角可以打开侧拉菜单
ui.toolbar.setupWithDrawer(ui.drawer);
ui.menu.setDataSource([
{
title: "使用教程",
icon: "@drawable/ic_description_black_48dp"
},
]);
ui.menu.on("item_click", item =>{
switch(item.title){
case"使用教程":
app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk");
}
});
//这里是无障碍触发方式
ui.autoService.on("check", function(checked) {
// 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
if(checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS" }); }
if(!checked && auto.service != null){
auto.service.disableSelf(); } });
// 当用户回到本界面时,resume事件会被触发
ui.emitter.on("resume", function() {
// 此时根据无障碍服务的开启情况,同步开关的状态
ui.autoService.checked = auto.service != null; });
//开启悬浮窗权限
ui.overlayService.on("check", function (checked) {
// 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
if (checked) {
int = app.startActivity({
packageName: "com.android.settings",
className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
data: "package:" + auto.service.getPackageName().toString()
});
toast("请打开悬浮窗开关");
}
if (!checked && auto.service != null) {
auto.service.disableSelf();
toast("已关闭悬浮窗权限");
}
});
ui.ok_bp.on("click", () => {
// engines.execScriptFile("tb_bp.js");
"ui";
var color = "#009688";
ui.statusBarColor("#ff4040")
ui.layout(
//这是聚划算百亿补贴界面
//start
{/* */}
//定义按钮的大小颜色和文本
//end
);
ui.lianjie.on("click",function(){
app.openUrl("https://docs.qq.com/doc/DU0pSZ3BTWXl4U1pk")
})
//BP跳转
ui.fastTbUrlOpen.on("click", () => {
if(ui.id1.text() ==""){
toast("请输入聚划算商品的BP链接!")
}
else {
var url = ui.id1.text();
app.startActivity({
action: "android.intent.action.VIEW",
data: "taobao://" + url,
packageName: "com.taobao.taobao",
});
}
});
var 不提交订单 = "无"
var 提交订单 = "有"
ui.tijiao.on("check", (checked)=>{
if(checked){
不提交订单 = "有"
提交订单 = "无"
toast("检测商品提交价格,大于预定价格不提交!");
}
else
{
不提交订单 = "无"
提交订单 = "有"
}
});
//密码隐藏
ui.bt1.on("check", (checked)=>{
if (ui.bt1.getText() == "隐藏密码") {
ui.bt1.setText("显示密码");
ui.h.visibility = 8;
toast("密码已隐藏!");
} else {
ui.bt1.setText("隐藏密码");
ui.h.visibility = 0;
toast("密码已显示!");
}
});
//自动付款
var 自动付款 = "无"
ui.pay1.on("check", (checked)=>{
if(checked){
自动付款= "有"
toast("已开启自动付款");
}
else
{
自动付款 = "无"
}
});
//这里是无障碍触发方式
ui.autoService.on("check", function(checked) {
// 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
if(checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS" }); }
if(!checked && auto.service != null){
auto.service.disableSelf(); } });
// 当用户回到本界面时,resume事件会被触发
ui.emitter.on("resume", function() {
// 此时根据无障碍服务的开启情况,同步开关的状态
ui.autoService.checked = auto.service != null; });
// //开启悬浮窗权限
// ui.overlayService.on("check", function (checked) {
// // 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
// if (checked) {
// int = app.startActivity({
// packageName: "com.android.settings",
// className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
// data: "package:" + auto.service.getPackageName().toString()
// });
// toast("请打开悬浮窗开关");
// }
// if (!checked && auto.service != null) {
// auto.service.disableSelf();
// toast("已关闭悬浮窗权限");
// }
// });
// 获取时分秒用于记录日志
function logWithTime(msg) {
console.info(formatDate(getNow()) + " " + msg);
}
// 检测淘宝网络延迟和时间偏差
var NTP = {
requiredResponses: 3,
serverTimes: [],//服务器时间
serverDelay: [],//服务器延迟
serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
resyncTime: 0, // minutes
sync: function () {
var offset = storage.get("NTPClockOffset");//获取时钟偏移
if (offset) {
try {
var t = offset.split("|")[1];
var d = NTP.fixTime() - parseInt(t, 10);
if (d < (1000 * 60 * NTP.resyncTime)) {
return false;
}
} catch (e) {
}
}
NTP.getServerTime();
},
getNow: function () {
var date = new Date();
return date.getTime();
},
//分析服务器响应
parseServerResponse: function (data) {
var NtpStartTime = storage.get("NtpStartTime");
var NtpStopTime = NTP.getNow();
var origtime = parseInt(data.data.t);//起始时间
var delay = ((NtpStopTime - NtpStartTime) / 2);//延迟
var offset = NtpStopTime - origtime - delay;//抵消
NTP.serverTimes.push(offset);
NTP.serverDelay.push(delay);
// 因为网络问题,需要多次获取偏移值,获取平均值
if (NTP.serverTimes.length >= NTP.requiredResponses) {
var sumOffset = 0;
var sumDelay = 0;
var i = 0;
for (i = 0; i < NTP.serverTimes.length; i++) {
sumOffset += NTP.serverTimes[i];
sumDelay += NTP.serverDelay[i];
}
var averageOffset = Math.round(sumOffset / i);
var averageDelay = Math.round(sumDelay / i);
storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
} else {
NTP.getServerTime();
}
},
//获取服务器时间并判断是否获取成功
getServerTime: function () {
var NtpStartTime = NTP.getNow();
storage.put("NtpStartTime", NtpStartTime);
var res = http.get(NTP.serverUrl);
if (res.statusCode !== 200) {
toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
return false;
} else {
NTP.parseServerResponse(res.body.json());
}
},
//固定时间
fixTime: function (timeStamp) {
if (!timeStamp) {
timeStamp = NTP.getNow();
}
var offset = storage.get("NTPClockOffset");
try {
if (!offset) {
offset = 0;
} else {
offset = offset.split("|")[0];
}
if (isNaN(parseInt(offset, 10))) {
return timeStamp;
}
return timeStamp + parseInt(offset, 10);
} catch (e) {
return timeStamp;
}
}
};
// 获取默认开始时间
function getTime() {
var fmt = "YYYY-MM-dd hh:mm:ss";
var d = new Date();
var hh = d.getHours();
var mm = d.getMinutes();
var ss = d.getSeconds();
if (mm < 30) {
mm = 30
ss = 00
}
else{
hh+=1
mm = 00
ss = 00
}
var o = {
"Y+": d.getYear() + 1900,
"M+": d.getMonth() + 1,
"d+": d.getDate(),
"h+": hh,
// "m+": d.getMinutes(),
// "s+": d.getSeconds()
"m+": mm,
"s+": ss
};
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
fmt = fmt.replace(/-/g, '/');
return fmt;
};
//定义初始化界面数据
var storage = storages.create("tmalltaobaohelper.byfly");
threads.start(NTP.sync);
//初始化淘宝界面
setTimeout(initConfig_two, 500);
function initConfig_two() {
NTPClockOffset = storage.get("NTPClockOffset", "0");
NTPClockDelay = storage.get("NTPClockDelay", "0");
if (!NTPClockOffset) {
NTPClockOffset = 0;
} else {
NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
}
if (NTPClockOffset < 0) {
var offset_str = "慢了" + -NTPClockOffset + 'ms,'
} else {
offset_str = "快了" + NTPClockOffset + 'ms,'
}
if (NTPClockDelay < 50) {
var good_str = "网速评估:"+"您的网络延迟低于50ms,非常优秀!"
}
else if (NTPClockDelay < 100) {
var good_str = "网速评估:"+"您的网络延迟低于100ms,优秀!"
}
else if (NTPClockDelay>100 && NTPClockDelay<200) {
var good_str = "网速评估:"+"您的网络延迟高于100ms,抢购可能会有影响!"
}
else {
good_str = "网速评估:"+"您的网络质量不佳,建议切换网络!"
}
ui.networkTesttwo.on("click",function(){
ui.networkTesttwo.setText("时间校准:"+"本地时间比淘宝" + offset_str +"已经为您校准了淘宝时间!"+'\n'+ "网络延迟:" + NTPClockDelay+'\n'+good_str );
});
ui.startTime_two.setText(getTime());
ui.interval.setText(storage.get("interval", "100").toString());
ui.lastTime_two.setText(storage.get("lastTime_two", "10").toString());
ui.delaytime_two.setText(storage.get("delaytime_two", "700").toString());
}
// 时间戳转时间字符串
function add0(m) {
return m < 10 ? '0' + m : m
}
function getNow() {
var now = new Date().getTime();
return now - NTPClockOffset;
}
function formatDate(needTime) {
//needTime是整数,否则要parseInt转换
var time = new Date(parseInt(needTime));
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
var S = time.getMilliseconds();
return add0(h) + ':' + add0(mm) + ':' + add0(s)+":"+add0(S);
}