1 /** 2 * 整理者: 家 3 * 日期: 20190224 4 * 妈呀: 整理了一宿,现在是早上6:34 5 * 功能: 把某些常用的函数集中起来,方便调用 6 * 函数来源: 都是群里的大佬写的,稻草人,+攀登,Ai,破晓的星辰,灶猫,家,浩然,白酒煮饭,生僻字大佬,内个谁,Xero,无名小姐,壞蛋┭,锦瑟安年Ω,专业滥竽充数,膜拜以上几位大神,不管你们同意不同意,我都把你们的代码搬到一块了,O(∩_∩)O哈哈~ 7 * git: https://github.com/snailuncle/autojsCommonFunctions/blob/master/autojsCommonFunctions.js 8 */ 9 10 //此代码由飞云脚本圈整理提供(www.feiyunjs.com) 11 12 // //导入模块 13 // function 导入常用函数模块(){ 14 // var url='https://raw.githubusercontent.com/snailuncle/autojsCommonFunctions/master/autojsCommonFunctions.js' 15 // var r = http.get(url) 16 // log("code = " + r.statusCode); 17 // var html=r.body.bytes() 18 // files.writeBytes('./autojsCommonFunctions.js',html) 19 // var common=require('./autojsCommonFunctions.js') 20 // return common 21 // } 22 // var common=导入常用函数模块() 23 // log(common) 24 // for(let i=0;i<33;i++){ 25 // common.闪光弹('fire in the hole') 26 // } 27 28 29 30 31 [ 32 '点击控件', 33 '铃声', 34 '启动app', 35 '停止app', 36 '卸载app', 37 '卸载app没root', 38 '清除app数据', 39 '启动最新安装的app', 40 '停止最新安装的app', 41 '卸载最新安装的app', 42 '清除最新安装的app数据', 43 '静默安装app', 44 '获取app图标', 45 '控制app联网', 46 '获取手机上所有的app名字', 47 '点击输入框弹出输入法', 48 '使所有输入框点击时都能弹出输入法', 49 '失去焦点', 50 '是否root', 51 '获取指定应用的版本号', 52 '打开qq群名片', 53 '打开qq名片', 54 'qq强制聊天', 55 '字节变为gbk中文', 56 '最新安装的app', 57 '文件修改时间', 58 '文件大小', 59 '字符串变字节', 60 '日期加N天', 61 'md5', 62 '是横屏还是竖屏', 63 '截图', 64 '随机字符', 65 '获取时间', 66 '调整手机音量', 67 '微信扫一扫', 68 '公共字符串', 69 '网络', 70 '安卓intent源码', 71 '获取手机ip地理位置', 72 '替换系统文件', 73 '编辑距离', 74 '数组交集', 75 '提取包含关键字的app', 76 '获取页面所有文字', 77 '悬浮控制', 78 '闪光弹', 79 '打开开发者选项', 80 '气泡', 81 '随机字符串', 82 'wifi状态', 83 '开关飞行模式', 84 '上滑', 85 '获取deflate网页内容', 86 '获取gzip网页内容' 87 ] 88 89 90 91 92 93 var common = {} 94 Array.prototype.intersect = function () { 95 var result = new Array(); 96 var obj = {}; 97 for (var i = 0; i < arguments.length; i++) { 98 for (var j = 0; j < arguments[i].length; j++) { 99 var str = arguments[i][j]; 100 if (!obj[str]) { 101 obj[str] = 1; 102 } else { 103 obj[str]++; 104 if (obj[str] == arguments.length) { 105 result.push(str); 106 } 107 } //end else 108 } //end for j 109 } //end for i 110 return result; 111 } 112 //集合去掉重复 113 Array.prototype.uniquelize = function () { 114 var tmp = {}, 115 ret = []; 116 for (var i = 0, j = this.length; i < j; i++) { 117 if (!tmp[this[i]]) { 118 tmp[this[i]] = 1; 119 ret.push(this[i]); 120 } 121 } 122 return ret; 123 } 124 //并集 125 Array.prototype.union = function () { 126 var arr = new Array(); 127 var obj = {}; 128 for (var i = 0; i < arguments.length; i++) { 129 for (var j = 0; j < arguments[i].length; j++) { 130 var str = arguments[i][j]; 131 if (!obj[str]) { 132 obj[str] = 1; 133 arr.push(str); 134 } 135 } //end for j 136 } //end for i 137 return arr; 138 } 139 //2个集合的差集 在arr不存在 140 Array.prototype.minus = function (arr) { 141 var result = new Array(); 142 var obj = {}; 143 for (var i = 0; i < arr.length; i++) { 144 obj[arr[i]] = 1; 145 } 146 for (var j = 0; j < this.length; j++) { 147 if (!obj[this[j]]) { 148 obj[this[j]] = 1; 149 result.push(this[j]); 150 } 151 } 152 return result; 153 }; 154 // console.log(Array.intersect(["1", "2", "3"], ["2", "3", "4", "5", "6"])); //[2,3] 155 // console.log([1, 2, 3, 2, 3, 4, 5, 6].uniquelize()); //[1,2,3,4,5,6] 156 // console.log(Array.union(["1", "2", "3"], ["2", "3", "4", "5", "6"], ["5", "6", "7", "8", "9"])) 157 // console.log(["2", "3", "4", "5", "6"].minus(["1", "2", "3"])); 158 159 common.点击控件 = function (view) { 160 log(arguments.callee.name + '开始') 161 log(view) 162 if (view) { 163 var x = view.bounds().centerX() 164 var y = view.bounds().centerY() 165 log('将要点击的坐标 %s,%s', x, y) 166 press(x, y, 1) 167 } else { 168 throw '传入点击控件中的view异常' 169 } 170 log(arguments.callee.name + '结束') 171 } 172 common.铃声 = function (铃声类型, 是否循环播放, 播放时长) { 173 var 铃声类型 = 铃声类型 || 0 174 var 播放时长 = 播放时长 || 6000 175 var 是否循环播放 = 是否循环播放 || false 176 if (是否循环播放) { 177 播放时长 = 666 * 1000 178 } 179 var 铃声选择结果 = android.media.RingtoneManager.TYPE_NOTIFICATION 180 switch (铃声类型) { 181 case 0: 182 铃声选择结果 = android.media.RingtoneManager.TYPE_RINGTONE 183 break; 184 case 1: 185 铃声选择结果 = android.media.RingtoneManager.TYPE_ALARM 186 break; 187 case 2: 188 铃声选择结果 = android.media.RingtoneManager.TYPE_ALL 189 break; 190 default: 191 break; 192 } 193 var mp = new android.media.MediaPlayer(); 194 mp.setDataSource(context, android.media.RingtoneManager.getDefaultUri(铃声选择结果)); 195 if (是否循环播放) mp.setLooping(true); 196 mp.prepare(); 197 mp.start(); 198 threads.start(function () { 199 sleep(播放时长) 200 if (mp.isPlaying()) { 201 mp.stop() 202 } 203 }); 204 return mp; 205 } 206 207 common.启动app = function (appName) { 208 launchApp(appName) 209 } 210 211 common.停止app = function (appName) { 212 var packageName=getPackageName(appName); 213 shell('am force-stop ' + packageName,true); 214 215 } 216 common.卸载app = function (appName) { 217 var packageName=getPackageName(appName); 218 shell("pm uninstall "+packageName,true) 219 } 220 221 common.清除app数据 = function (appName) { 222 var packageName=getPackageName(appName); 223 shell('pm clear ' + packageName,true); 224 } 225 226 227 common.卸载最新安装的app=function (){ 228 var pm = context.getPackageManager() 229 var appList=pm.getInstalledApplications(0) 230 var appInfoList=[] 231 for(let i=0;i<appList.size();i++){ 232 var app=appList.get(i) 233 var appInfo={ 234 appName:app.loadLabel(pm), 235 packageName:app.packageName, 236 isSystemApp:app.isSystemApp(), 237 firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime 238 } 239 appInfoList.push(appInfo) 240 241 } 242 appInfoList.sort((a,b)=>{ 243 return b.firstInstallTime-a.firstInstallTime 244 }) 245 log('最新安装的app是=%j',appInfoList[0]) 246 247 var packageName=appInfoList[0].packageName 248 shell("pm uninstall "+packageName,true) 249 return appInfoList[0].appName 250 } 251 common.清除最新安装的app数据=function (){ 252 var pm = context.getPackageManager() 253 var appList=pm.getInstalledApplications(0) 254 var appInfoList=[] 255 for(let i=0;i<appList.size();i++){ 256 var app=appList.get(i) 257 var appInfo={ 258 appName:app.loadLabel(pm), 259 packageName:app.packageName, 260 isSystemApp:app.isSystemApp(), 261 firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime 262 } 263 appInfoList.push(appInfo) 264 265 } 266 appInfoList.sort((a,b)=>{ 267 return b.firstInstallTime-a.firstInstallTime 268 }) 269 log('最新安装的app是=%j',appInfoList[0]) 270 271 var packageName=appInfoList[0].packageName 272 shell('pm clear ' + packageName,true); 273 return appInfoList[0].appName 274 } 275 common.停止最新安装的app=function (){ 276 var pm = context.getPackageManager() 277 var appList=pm.getInstalledApplications(0) 278 var appInfoList=[] 279 for(let i=0;i<appList.size();i++){ 280 var app=appList.get(i) 281 var appInfo={ 282 appName:app.loadLabel(pm), 283 packageName:app.packageName, 284 isSystemApp:app.isSystemApp(), 285 firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime 286 } 287 appInfoList.push(appInfo) 288 289 } 290 appInfoList.sort((a,b)=>{ 291 return b.firstInstallTime-a.firstInstallTime 292 }) 293 log('最新安装的app是=%j',appInfoList[0]) 294 295 296 297 298 var packageName=appInfoList[0].packageName 299 shell('am force-stop ' + packageName,true); 300 return appInfoList[0].appName 301 } 302 303 common.启动最新安装的app=function (){ 304 var pm = context.getPackageManager() 305 var appList=pm.getInstalledApplications(0) 306 var appInfoList=[] 307 for(let i=0;i<appList.size();i++){ 308 var app=appList.get(i) 309 var appInfo={ 310 appName:app.loadLabel(pm), 311 packageName:app.packageName, 312 isSystemApp:app.isSystemApp(), 313 firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime 314 } 315 appInfoList.push(appInfo) 316 317 } 318 appInfoList.sort((a,b)=>{ 319 return b.firstInstallTime-a.firstInstallTime 320 }) 321 log('最新安装的app是=%j',appInfoList[0]) 322 323 324 325 326 var packageName=appInfoList[0].packageName 327 launch(packageName) 328 return appInfoList[0].appName 329 } 330 331 common.点击输入框弹出输入法=function (window,view){ 332 view.on( 333 "touch_down", function () { 334 window.requestFocus(); 335 view.requestFocus(); 336 } 337 ) 338 view.on( 339 "key", function (keyCode,event) { 340 if(event.getAction()==event.ACTION_DOWN && keyCode == keys.back){ 341 window.disableFocus() 342 event.consumed=true 343 } 344 window.requestFocus(); 345 view.requestFocus(); 346 } 347 ) 348 349 } 350 351 352 common.使所有输入框点击时都能弹出输入法=function (window,inputBoxViewArr){ 353 for(let i=0;i<inputBoxViewArr.length;i++){ 354 var view=inputBoxViewArr[i] 355 common.点击输入框弹出输入法(window,view) 356 } 357 } 358 359 360 361 common.失去焦点=function (window){ 362 window.disableFocus() 363 } 364 365 366 367 368 369 common.是否root=function(){ 370 var r=shell("ls /system/bin",true).result.toString() 371 if(r.length>50){ 372 return true 373 }else{ 374 return false 375 } 376 } 377 common.获取指定应用的版本号 = function (appName) { 378 /** 379 * 获取指定应用的版本号 380 * @param {string} packageName 应用包名 381 */ 382 function getPackageVersion(packageName) { 383 importPackage(android.content); 384 var pckMan = context.getPackageManager(); 385 var packageInfo = pckMan.getPackageInfo(packageName, 0); 386 return packageInfo.versionName; 387 } 388 var packageName = getPackageName(appName); 389 return getPackageVersion(packageName) 390 } 391 392 393 common.打开qq群名片=function (qq群号){ 394 app.startActivity({ 395 action: "android.intent.action.VIEW", 396 data:"mqqapi://card/show_pslcard?card_type=group&uin="+qq群号, 397 packageName: "com.tencent.mobileqq", 398 });//打开qq群名片 399 400 401 } 402 403 404 405 common.打开qq名片=function (qq号){ 406 app.startActivity({ 407 action: "android.intent.action.VIEW", 408 data:"mqqapi://card/show_pslcard?uin="+qq号, 409 packageName: "com.tencent.mobileqq", 410 });//打开qq名片 411 412 413 } 414 415 common.qq强制聊天=function (qq号){ 416 app.startActivity({ 417 action: "android.intent.action.VIEW", 418 data:"mqq://im/chat?chat_type=wpa&version=1&src_type=web&uin="+qq号, 419 packageName: "com.tencent.mobileqq", 420 });//qq强制聊天 421 422 } 423 424 common.字节变为gbk中文 = function (bytesContent) { 425 var str = new java.lang.String(bytesContent, "gbk") 426 return str 427 } 428 common.最新安装的app = function () { 429 430 var pm = context.getPackageManager() 431 var appList=pm.getInstalledApplications(0) 432 var appInfoList=[] 433 for(let i=0;i<appList.size();i++){ 434 var app=appList.get(i) 435 var appInfo={ 436 appName:app.loadLabel(pm), 437 packageName:app.packageName, 438 isSystemApp:app.isSystemApp(), 439 firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime 440 } 441 appInfoList.push(appInfo) 442 } 443 appInfoList.sort((a,b)=>{ 444 return b.firstInstallTime-a.firstInstallTime 445 }) 446 log('最新安装的app是=%j',appInfoList[0]) 447 return appInfoList[0] 448 449 450 } 451 common.文件修改时间 = function (path) { 452 var time=new java.io.File(files.path(path)).lastModified(); 453 return time 454 } 455 common.文件大小 = function (path) { 456 var size = new java.io.File(path).length() 457 return size 458 } 459 common.字符串变字节 = function (string) { 460 return new java.lang.String(string).getBytes(); 461 } 462 common.日期加N天 = function (n) { 463 var now = new Date(); 464 now.setDate(now.getDate()+n); 465 return (now); 466 } 467 common.md5 = function (string) { 468 return java.math.BigInteger(1,java.security.MessageDigest.getInstance("MD5") 469 .digest(java.lang.String(string).getBytes())).toString(16); 470 } 471 common.是横屏还是竖屏 = function () { 472 var a = (context.resources.configuration.orientation); 473 if (a === 1) { 474 toastLog("这是竖屏!!"); 475 return '竖屏' 476 } 477 478 else { 479 toastLog("这是横屏!!");} 480 return '横屏' 481 482 } 483 common.截图 = function (path) { 484 var path=path || '/sdcard/1temp.png' 485 486 var dd = shell("screencap -p "+path,true) 487 var img 488 if(dd.code ==0){ 489 img = images.read(path) 490 }else{ 491 log("错误信息:") 492 log(dd.error) 493 } 494 return img 495 496 497 } 498 common.随机字符=function (n){ 499 var n= n || 8 500 var str=""; 501 for(var i=0;i<n;i++){ 502 str+=String.fromCharCode(random(0,65535)); 503 } 504 return str; 505 } 506 507 common.获取时间=function (time) { 508 if (time) { 509 return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time)); 510 } else { 511 return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); 512 } 513 } 514 515 common.调整手机音量=function (){ 516 517 var am = context.getSystemService(context.AUDIO_SERVICE) 518 // STREAM_MUSIC这个自己试试,是调整那种音量,范围0-6 自己试试,我也不知道 519 var STREAM_MUSIC = 1 520 // 1 增大音量 -1 降低音量 0 不变 521 var ADJUST_RAISE = -1 522 // 1 显示调整音量界面 0 不显示界面 523 var FLAG_SHOW_UI = 1 524 am.adjustStreamVolume(STREAM_MUSIC, ADJUST_RAISE, FLAG_SHOW_UI) 525 526 527 //获取最大音量 528 var max = am.getStreamMaxVolume(STREAM_MUSIC); 529 log(max) 530 //获取当前音量 531 toastLog('最大音量'+max) 532 sleep(2000) 533 var current = am.getStreamVolume(STREAM_MUSIC); 534 log(current) 535 toastLog('当前音量'+current) 536 537 } 538 539 common.微信扫一扫=function (){ 540 context.startActivity(app.intent({ 541 action: "VIEW", 542 className:"com.tencent.mm.ui.LauncherUI", 543 packageName:"com.tencent.mm", 544 extras: { 545 "LauncherUI.From.Scaner.Shortcut": true 546 } 547 }).setFlags(335544320)); 548 } 549 common.公共字符串=function (str1,str2){ 550 // var str1 = "aaabbba" 551 // var str2 = " bbbcaaa" 552 553 function find(str1, str2) { 554 //创建存放重复内容的数组 555 var all = new Array(); 556 //字符串转字符数组 557 var str_1 = str1.split(""); 558 var str_2 = str2.split(""); 559 for (var i = 0; i < str_1.length; i++) { 560 for (var l = 0; l < str_2.length; l++) { 561 //判断是否重复 562 var lo = all.length; 563 all[lo] = ""; 564 //判断之后的字符串是否相同 565 for (var k = 0; str_1[i + k] == str_2[l + k]; k++) { 566 all[lo] = all[lo] + str_1[i + k]; 567 //防止数组越界,提前停止循环 568 if (i + k == str_1.length-1||i+k==str_2.length-1) { 569 break; 570 } 571 } 572 } 573 } 574 575 var most = 0; 576 var fu = new Array(); 577 for (var j = 0; j < all.length; j++) { 578 //去除空的内容 579 if (all[j] != "") { 580 //按照大小排序(删除部分小的) 581 if (all[j].split("").length >= most) { 582 most = all[j].split("").length; 583 fu[fu.length] = all[j]; 584 } 585 } 586 } 587 588 //将不重复内容写到新数组 589 var wu=new Array(); 590 for(var i=0;i<fu.length;i++){ 591 var c=false; 592 for(var l=0;l<wu.length;l++){ 593 if(fu[i]==wu[l]){ 594 c=true; 595 } 596 } 597 if(!c){ 598 wu[wu.length]=fu[i]; 599 } 600 } 601 602 //将最长的内容写到新数组 603 var ml=new Array(); 604 //获得最后一个字符串的长度(最长) 605 var longest=wu[wu.length-1].split("").length; 606 //长度等于最长的内容放到新数组 607 for(var i=wu.length-1;i>=0;i--){ 608 if(wu[i].split("").length==longest){ 609 ml[ml.length]=wu[i]; 610 }else{ 611 //提前结束循环 612 break; 613 } 614 } 615 616 return ml 617 } 618 var result=find(str1, str2) 619 log(result) 620 return result 621 } 622 623 common.网络=function (){ 624 var intent = new Intent(); 625 importClass(android.content.BroadcastReceiver); 626 importClass(android.content.ContextWrapper); 627 importClass(android.content.IntentFilter); 628 importClass(android.net.ConnectivityManager); 629 var filter = new IntentFilter(); 630 filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); 631 new ContextWrapper(context).registerReceiver(a = new BroadcastReceiver({ 632 onReceive: function(context, intent) { 633 var action = intent.getAction(); 634 if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { 635 var mConnectivityManager = context.getSystemService(context.CONNECTIVITY_SERVICE); 636 netInfo = mConnectivityManager.getActiveNetworkInfo(); 637 if (netInfo != null && netInfo.isAvailable()) { 638 639 /////////////网络连接 640 var name = netInfo.getTypeName(); 641 642 if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { 643 /////WiFi网络 644 toastLog("WiFi网络"); 645 return "WiFi网络" 646 } else if (netInfo.getType() == ConnectivityManager.TYPE_ETHERNET) { 647 /////有线网络 648 toastLog("有线网络"); 649 return "有线网络" 650 651 } else if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) { 652 /////////3g网络 653 toastLog("3g网络"); 654 return "3g网络" 655 656 } 657 } else { 658 ////////网络断开 659 toastLog("网络断开"); 660 return "网络断开" 661 662 } 663 } 664 665 } 666 }), filter); 667 668 } 669 670 common.安卓intent源码=function (){ 671 var intent = new Intent(); 672 intent.setAction("android.settings.ACCESSIBILITY_SETTINGS"); 673 //辅助功能 674 //intent.setAction("android.settings.ADD_ACCOUNT_SETTINGS"); 675 //添加账户 676 //intent.setAction("android.settings.AIRPLANE_MODE_SETTINGS"); 677 //系统设置首页 678 //intent.setAction("android.settings.APN_SETTINGS"); 679 //APN设置 680 //intent.setAction("android.settings.APPLICATION_SETTINGS"); 681 //应用管理 682 //intent.setAction("android.settings.BATTERY_SAVER_SETTINGS"); 683 //节电助手 684 //intent.setAction("android.settings.BLUETOOTH_SETTINGS"); 685 //蓝牙 686 //intent.setAction("android.settings.CAPTIONING_SETTINGS"); 687 //字幕 688 //intent.setAction("android.settings.CAST_SETTINGS"); 689 //无线显示 690 //intent.setAction("android.settings.DATA_ROAMING_SETTINGS"); 691 //移动网络 692 //intent.setAction("android.settings.DATE_SETTINGS"); 693 //日期和时间设置 694 //intent.setAction("android.settings.DEVICE_INFO_SETTINGS"); 695 //关于手机 696 //intent.setAction("android.settings.DISPLAY_SETTINGS"); 697 //显示设置 698 //intent.setAction("android.settings.DREAM_SETTINGS"); 699 //互动屏保设置 700 //intent.setAction("android.settings.HARD_KEYBOARD_SETTINGS"); 701 //实体键盘 702 //intent.setAction("android.settings.HOME_SETTINGS"); 703 //应用权限,默认应用设置,特殊权限 704 //intent.setAction("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"); 705 //忽略电池优化设置 706 //intent.setAction("android.settings.INPUT_METHOD_SETTINGS"); 707 //可用虚拟键盘设置 708 //intent.setAction("android.settings.INPUT_METHOD_SUBTYPE_SETTINGS"); 709 //安卓键盘语言设置(AOSP) 710 //intent.setAction("android.settings.INTERNAL_STORAGE_SETTINGS"); 711 //内存和存储 712 //intent.setAction("android.settings.LOCALE_SETTINGS"); 713 //语言偏好设置 714 //intent.setAction("android.settings.LOCATION_SOURCE_SETTINGS"); 715 //定位服务设置 716 //intent.setAction("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS"); 717 //所有应用 718 //intent.setAction("android.settings.MANAGE_APPLICATIONS_SETTINGS"); 719 //应用管理 720 //intent.setAction("android.settings.MANAGE_DEFAULT_APPS_SETTINGS"); 721 //与ACTION_HOME_SETTINGS相同 722 //intent.setAction("android.settings.action.MANAGE_OVERLAY_PERMISSION"); 723 //在其他应用上层显示,悬浮窗 724 //intent.setAction("android.settings.MANAGE_UNKNOWN_APP_SOURCES"); 725 //安装未知应用 安卓8.0 726 //intent.setAction("android.settings.action.MANAGE_WRITE_SETTINGS"); 727 //可修改系统设置 权限 728 //intent.setAction("android.settings.MEMORY_CARD_SETTINGS"); 729 //内存与存储 730 //intent.setAction("android.settings.NETWORK_OPERATOR_SETTINGS"); 731 //可用网络选择 732 //intent.setAction("android.settings.NFCSHARING_SETTINGS"); 733 //NFC设置 734 //intent.setAction("android.settings.NFC_SETTINGS"); 735 //网络中的 更多设置 736 //intent.setAction("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); 737 //通知权限设置 738 //intent.setAction("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS"); 739 //勿扰权限设置 740 //intent.setAction("android.settings.ACTION_PRINT_SETTINGS"); 741 //打印服务设置 742 //intent.setAction("android.settings.PRIVACY_SETTINGS"); 743 //备份和重置 744 //intent.setAction("android.settings.SECURITY_SETTINGS"); 745 //安全设置 746 //intent.setAction("android.settings.SHOW_REGULATORY_INFO"); 747 //监管信息 748 //intent.setAction("android.settings.SOUND_SETTINGS"); 749 //声音设置 750 //intent.setAction("android.settings.SYNC_SETTINGS"); 751 //添加账户设置 752 //intent.setAction("android.settings.USAGE_ACCESS_SETTINGS"); 753 //有权查看使用情况的应用 754 //intent.setAction("android.settings.USER_DICTIONARY_SETTINGS"); 755 //个人词典 756 //intent.setAction("android.settings.VOICE_INPUT_SETTINGS"); 757 //辅助应用和语音输入 758 //intent.setAction("android.settings.VPN_SETTINGS"); 759 //VPN设置 760 //intent.setAction("android.settings.VR_LISTENER_SETTINGS"); 761 //VR助手 762 //intent.setAction("android.settings.WEBVIEW_SETTINGS"); 763 //选择webview 764 //intent.setAction("android.settings.WIFI_IP_SETTINGS"); 765 //高级WLAN设置 766 //intent.setAction("android.settings.WIFI_SETTINGS"); 767 //选择WIFI,连接WIFI 768 app.startActivity(intent); 769 770 } 771 772 common.获取手机ip地理位置=function (){ 773 var ip地理位置 = false 774 var ip地理位置正则 = /本机IP: d{1,3}.d{1,3}.d{1,3}.d{1,3}</span>([sS]*?)</td/ 775 var ipUrl = "http://www.baidu.com/s?ie=UTF-8&wd=ip%E5%BD%92%E5%B1%9E%E5%9C%B0%E6%9F%A5%E8%AF%A2" 776 var r = http.get(ipUrl); 777 log("code = " + r.statusCode); 778 var htmlResult = r.body.string() 779 ip地理位置 = ip地理位置正则.exec(htmlResult) 780 if (ip地理位置) { 781 ip地理位置 = ip地理位置正则.exec(ip地理位置) 782 ip地理位置 = ip地理位置[1] 783 toastLog(ip地理位置) 784 return ip地理位置 785 } else { 786 log('没有查询到Ip地理位置,脚本停止') 787 return false 788 } 789 790 } 791 792 common.获取app图标=function (appName){ 793 importClass(java.io.File); 794 importClass(java.io.FileOutputStream); 795 importClass(android.graphics.Bitmap); 796 var pm = context.getPackageManager(); 797 importClass(android.util.DisplayMetrics) 798 var name = appName 799 var packageName = app.getPackageName(name); 800 var appInfo = pm.getApplicationInfo(packageName, 0); 801 var bmp = appInfo.loadIcon(pm).getBitmap(); 802 files.create("/sdcard/"+name+".jpg"); 803 var f = new File("/sdcard/"+name+"qq.jpg"); 804 var fOut = new FileOutputStream(f); 805 bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut); 806 fOut.flush(); 807 fOut.close(); 808 809 var img=images.read("sdcard/"+name+".jpg") 810 return img 811 // app.viewFile("sdcard/"+name+".jpg") 812 } 813 814 common.替换系统文件 = function (syspath,sdpath) { 815 // // var path = "/data/data/com.aaa.bbb" 816 // // var pathSD = "/sdcard/com.aaa.bbb" 817 // //删除原来的文件 818 // shell('chown root:root ' + path, true) 819 // shell('rm ' + path + " -rf", true); 820 // shell('rm ' + pathSD + " -rf", true); 821 // sleep(2000) 822 823 // // 解压备份的文件 824 // var inkeSdacrdPath = "/sdcard/com.aaa.bbb.zip" 825 // var 文件路径 = inkeSdacrdPath 826 // var 文件夹路径 = "/sdcard" 827 // com.stardust.io.Zip.unzip(new java.io.File(文件路径), new java.io.File(文件夹路径)) 828 // sleep(2000) 829 830 // //移动解压后的文件 831 // shell("mv -f /sdcard/com.aaa.bbb /data/data/com.aaa.bbb", true); 832 833 // //修改权限 834 // shell("chmod -R 777 /data/data/com.aaa.bbb", true); 835 836 //------------------------------------------------ 837 //------------------------------------------------ 838 //------------------------------------------------ 839 // var path = "/data/data/com.aaa.bbb" 840 // var pathSD = "/sdcard/com.aaa.bbb" 841 //删除原来的文件 842 shell('chown root:root ' + syspath, true) 843 shell('rm ' + path + " -rf", true); 844 sleep(2000) 845 846 //移动解压后的文件 847 shell("mv -f "+sdpath+" "+syspath, true); 848 849 //修改权限 850 shell("chmod -R 777 "+syspath, true); 851 852 853 854 } 855 856 common.编辑距离 = function (sm,sn){ 857 var m=sm.length+1 858 var n=sn.length+1 859 var matrix = new Array(); 860 for ( var i = 0; i < m; i++) { 861 matrix[i] = new Array(); 862 for ( var j = 0; j < n; j++) { 863 matrix[i][j] = 0; 864 } 865 } 866 matrix[0][0]=0 867 for(let i=1;i<m;i++){ 868 matrix[i][0] = matrix[i-1][0] + 1 869 } 870 for(let j=1;j<n;j++){ 871 matrix[0][j] = matrix[0][j-1]+1 872 } 873 cost = 0 874 for(let i=1;i<m;i++){ 875 for(let j=1;j<n;j++){ 876 if(sm[i-1]==sn[j-1]){ 877 cost = 0 878 } 879 else{ 880 cost = 1 881 } 882 matrix[i][j]=Math.min(matrix[i-1][j]+1,matrix[i][j-1]+1,matrix[i-1][j-1]+cost) 883 } 884 } 885 return matrix[m-1][n-1] 886 // var mindist=minEditDist("126","456") 887 // print(mindist) 888 } 889 common.静默安装app = function (apk路径) { 890 shell("pm install -r " + apk路径 , true) 891 } 892 893 894 895 common.获取手机上所有的app名字 = function () { 896 var 所有的app名字=[] 897 var pm=context.getPackageManager() 898 let list=pm.getInstalledApplications(0) 899 for(let i=0;i<list.size();i++){ 900 let p=list.get(i) 901 var app={ 902 appName:p.loadLabel(pm), 903 packageName:p.packageName 904 } 905 所有的app名字.push(app.appName) 906 } 907 return 所有的app名字 908 } 909 common.数组交集=function(){ 910 911 var 交集 = Array.intersect(arr1, arr2) 912 log(交集) 913 return 交集 914 } 915 common.控制app联网 = function (appName, 是否允许联网联网) { 916 var 是否允许联网联网 = 是否允许联网联网 || true 917 //作者: 家 QQ203118908 918 919 920 //本来打算用iptables-restore用文件形式更新防火墙规则, 921 //可是iptables-restore出现了bug,2013年就有人提过这个bug 922 //https://linux.debian.bugs.dist.narkive.com/J0hbJiR6/bug-710379-xtables-addons-common-quota2-module-iptables-save-creates-invalid-record 923 //又得改,坑爹 924 925 //马丹,iptables -D INPUT -lineNumber也有BUG, 926 //提示 index of deletion too big 927 //日了够了 928 //又得改,坑爹 929 // sudo iptables -D OUTPUT 1 -t nat 930 // 931 // uid=`cat /data/system/packages.list | grep com.sohu.inputmethod.sogou | busybox awk '{print $2}'` 932 // iptables -t filter -A OUTPUT -m owner --uid-owner=$uid -j DROP 933 934 // 以上是android iptables 屏蔽某个app网络访问的内容, 935 936 function 联网控制(appName) { 937 // -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT 938 // -A OUTPUT -m owner --uid-owner 10105 -j DROP 939 this.等待shell执行完毕的时间 = 0 940 this.防火墙规则路径 = '/sdcard/iptables.txt' 941 this.uid路径 = '/sdcard/' + appName + 'uidOwner.txt' 942 this.appName = appName 943 this.packageName = getPackageName(this.appName) 944 this.执行shell = (cmd) => { 945 var result = shell(cmd, true); 946 console.show(); 947 log(result); 948 if (result.code == 0) { 949 toastLog("执行成功"); 950 } else { 951 toastLog("执行失败!请到控制台查看错误信息"); 952 } 953 sleep(this.等待shell执行完毕的时间) 954 } 955 this.uid = () => { 956 var cmd = 'cat /data/system/packages.list | grep ' + this.packageName + ' > ' + this.uid路径 957 log('cmd=', cmd) 958 this.执行shell(cmd) 959 // cat /data/system/packages.list | grep com.tencent.mobileqq > /sdcard/QQuidOwner.txt 960 var 包含uid的文本 = files.read('/sdcard/' + appName + 'uidOwner.txt') 961 log('包含uid的文本=', 包含uid的文本) 962 var uidReg = new RegExp(this.packageName + '\s*(\d+)') 963 log('uidReg=', uidReg) 964 var uid = 包含uid的文本.match(uidReg)[1] 965 log(uid) 966 return uid 967 } 968 this.允许联网规则 = 'iptables -t filter -A OUTPUT -m owner --uid-owner ' + this.uid() + ' -j ACCEPT' 969 this.禁止联网规则 = 'iptables -t filter -A OUTPUT -m owner --uid-owner ' + this.uid() + ' -j DROP' 970 this.允许 = () => { 971 this.清空该app的防火墙规则() 972 this.将防火墙规则写入系统(this.允许联网规则) 973 } 974 this.禁止 = () => { 975 this.清空该app的防火墙规则() 976 this.将防火墙规则写入系统(this.禁止联网规则) 977 } 978 979 this.将防火墙规则写入系统 = (防火墙规则) => { 980 var cmd = 防火墙规则 981 this.执行shell(cmd) 982 } 983 this.导出防火墙规则 = () => { 984 var cmd = 'iptables-save > ' + this.防火墙规则路径 985 this.执行shell(cmd) 986 } 987 this.防火墙规则 = () => { 988 this.导出防火墙规则() 989 var 防火墙规则 = files.read(this.防火墙规则路径) 990 log('防火墙规则=', 防火墙规则) 991 return 防火墙规则 992 } 993 this.清空该app的防火墙规则 = () => { 994 var 防火墙规则 = this.防火墙规则() 995 // stringObject.replace(regexp/substr,replacement) 996 // -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT 997 // -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT 998 // -A OUTPUT -m owner --uid-owner 10105 -j DROP 999 // -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT 1000 // -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT 1001 // 删除之前添加的规则(iptables -A INPUT -s 192.168.1.5 -j DROP): 1002 // [root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP 1003 // iptables -t filter -A OUTPUT -m owner --uid-owner=$uid -j DROP 1004 var 要删除的规则reg = new RegExp('-A (OUT|IN)PUT -m owner --uid-owner ' + this.uid() + ' -j (ACCEPT|DROP)', 'g') 1005 // 要删除的规则reg= /-A OUTPUT -m owner --uid-owner 10105 -j (ACCEPT|DROP)/ 1006 // -A OUTPUT -m owner --uid-owner 10105 -j (ACCEPT|DROP) 1007 // iptables -D OUTPUT -m owner --uid-owner 10105 -j ACCEPT 1008 log('要删除的规则reg=', 要删除的规则reg) 1009 var new防火墙规则 = 防火墙规则.match(要删除的规则reg, '') 1010 log('new防火墙规则=', new防火墙规则) 1011 // new防火墙规则= [ 1012 // '-A OUTPUT -m owner --uid-owner 10105 -j ACCEPT', 1013 // '-A OUTPUT -m owner --uid-owner 10105 -j DROP' 1014 // ] 1015 if (new防火墙规则) { 1016 for (let i = 0; i < new防火墙规则.length; i++) { 1017 var 规则 = new防火墙规则[i] 1018 规则 = 规则.replace('-A', '-D') 1019 var cmd = 'iptables ' + 规则 1020 this.执行shell(cmd) 1021 } 1022 } 1023 log('清空了指定app的防火墙规则') 1024 } 1025 } 1026 // var appName = 'QQ' 1027 // var appName = '哔哩哔哩' 1028 var appName = '微信' 1029 var app联网控制 = new 联网控制(appName) 1030 if (是否允许联网联网) { 1031 app联网控制.允许() 1032 } else { 1033 app联网控制.禁止() 1034 } 1035 1036 1037 } 1038 common.提取包含关键字的app = function (app关键字) { 1039 importClass(android.content.pm.PackageManager) 1040 var uc应用 = [] 1041 var ucapp = {} 1042 pm = context.getPackageManager(); 1043 var 有的 = pm.getInstalledPackages(PackageManager.GET_SHARED_LIBRARY_FILES) 1044 有的 = pm.getInstalledPackages(PackageManager.GET_META_DATA) 1045 有的 = 有的 + "" 1046 有的 = 有的.replace(/PackageInfo[^ ]+ /g, "") 1047 有的 = 有的.replace(/[}|[|]| ]/g, "") 1048 有的 = 有的.split(",") 1049 for (let i of 有的) { 1050 var packageInfo = pm.getPackageInfo(i, 0); 1051 var appName = packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString() 1052 //appName = app.getAppName(i) 1053 if (appName.match(app关键字)) { 1054 // log(appName) 1055 // log("包名:" + i) 1056 ucapp = { 1057 "包名": i, 1058 "名称": appName 1059 } 1060 uc应用.push(ucapp) 1061 } 1062 } 1063 return uc应用 1064 } 1065 common.卸载app没root = function (appName) { 1066 var packageName=getPackageName(appName); 1067 app.uninstall(packageName); 1068 1069 1070 } 1071 1072 common.获取页面所有文字 = function (setting) { 1073 var setting = setting || {} 1074 var defaultSetting = { 1075 getText: true, 1076 getDesc: true, 1077 getId: false, 1078 removeRepetitiveElements: true 1079 } 1080 Object.assign(defaultSetting, setting); 1081 log(defaultSetting) 1082 var allStr = [] 1083 var getDescAndTextAndIdOfNode = function (node) { 1084 if (node) { 1085 if (defaultSetting.getText) { 1086 var text = node.text() 1087 if (!!text) { 1088 allStr.push(text) 1089 } 1090 } 1091 if (defaultSetting.getDesc) { 1092 var desc = node.desc() 1093 if (!!desc) { 1094 allStr.push(desc) 1095 } 1096 } 1097 if (defaultSetting.getId) { 1098 var id = node.id() 1099 if (!!id) { 1100 allStr.push(id) 1101 } 1102 } 1103 } 1104 for (let i = 0; i < node.childCount(); i++) { 1105 getDescAndTextAndIdOfNode(node.child(i)); 1106 } 1107 } 1108 var getFrameLayoutNode = function () { 1109 return className('FrameLayout').findOne(2000) 1110 } 1111 getDescAndTextAndIdOfNode(getFrameLayoutNode()) 1112 1113 function removeRepetitiveElements(arr) { 1114 var obj = {} 1115 for (let i = 0; i < arr.length; i++) { 1116 if (obj.hasOwnProperty(arr[i])) {} else { 1117 obj[arr[i]] = true 1118 } 1119 } 1120 return Object.keys(obj) 1121 } 1122 if (defaultSetting.removeRepetitiveElements) { 1123 allStr = removeRepetitiveElements(allStr) 1124 } 1125 return allStr 1126 } 1127 1128 common.悬浮控制 = function (window, windowid, ar) { 1129 this.Orientation = context.resources.configuration.orientation; 1130 this.Width = this.Orientation == 1 ? device.width : device.height; 1131 this.Height = this.Orientation == 2 ? device.width : device.height; 1132 this.Click = function () {}; 1133 this.Move = function () {}; 1134 this.LongClick = function () {}; 1135 this.setClick = (fun) => { 1136 fun = fun || function () {}; 1137 this.Click = fun; 1138 }; 1139 this.setMove = (fun) => { 1140 fun = fun || function () {}; 1141 this.Move = fun; 1142 }; 1143 this.setLongClick = (fun, ji) => { 1144 fun = fun || function () {}; 1145 this.LongClick = fun; 1146 if (parseInt(ji)) { 1147 this.Tjitime = parseInt(ji) / 50; 1148 }; 1149 }; 1150 setInterval(() => { 1151 if (context.resources.configuration.orientation != this.Orientation) { 1152 this.Orientation = context.resources.configuration.orientation; 1153 this.Width = this.Orientation == 1 ? device.width : device.height; 1154 this.Height = this.Orientation == 2 ? device.width : device.height; 1155 var xy = this.windowGXY(window.getX(), window.getY(), this.G(window)); 1156 this.windowyidong([ 1157 [window.getX(), window.getY()], 1158 [xy.x, xy.y] 1159 ]); 1160 }; 1161 }, 100); 1162 this.TX = 0; 1163 this.TY = 0; 1164 this.Tx = 0; 1165 this.Ty = 0; 1166 this.Tyidong = false; 1167 this.Tkeep = false; 1168 this.Tjitime = 12; 1169 this.Ttime = 0; 1170 setInterval(() => { 1171 if (this.Tkeep) { 1172 this.Ttime++; 1173 if (!this.Tyidong && this.Ttime > this.Tjitime) { 1174 //非移动且按下时长超过1秒判断为长按 1175 this.Tkeep = false; 1176 this.Ttime = 0; 1177 this.LongClick(); 1178 }; 1179 }; 1180 }, 50); 1181 if (windowid) { 1182 windowid.setOnTouchListener(new android.view.View.OnTouchListener((view, event) => { 1183 this.Move(view, event); 1184 switch (event.getAction()) { 1185 case event.ACTION_DOWN: 1186 this.Tx = event.getRawX(); 1187 this.Ty = event.getRawY(); 1188 this.TX = window.getX(); 1189 this.TY = window.getY(); 1190 this.Tkeep = true; //按下,开启计时 1191 break; 1192 case event.ACTION_MOVE: 1193 var sx = event.getRawX() - this.Tx; 1194 var sy = event.getRawY() - this.Ty; 1195 if (!this.Tyidong && this.Tkeep && this.weiyi(sx, sy) >= 10) { 1196 this.Tyidong = true; 1197 }; 1198 if (this.Tyidong && this.Tkeep) { 1199 window.setPosition(this.TX + sx, this.TY + sy); 1200 }; 1201 break; 1202 case event.ACTION_UP: 1203 if (!this.Tyidong && this.Tkeep && this.Ttime < 7) { 1204 this.Click(); 1205 }; 1206 this.Tkeep = false; 1207 this.Ttime = 0; 1208 if (this.Tyidong) { 1209 var A = this.windowGXY(window.getX(), window.getY(), this.G(window)); 1210 threads.start(new java.lang.Runnable(() => { 1211 this.windowyidong([ 1212 [window.getX(), window.getY()], 1213 [A.x, A.y] 1214 ]); 1215 })); 1216 this.Tyidong = false; 1217 }; 1218 break; 1219 }; 1220 return true; 1221 })); 1222 }; 1223 this.G = (win) => { 1224 var K = 35, //悬浮窗的隐形边矩 1225 H = 66; //手机通知栏的高度 1226 if (!ar) { 1227 return [ 1228 [-K, -K], 1229 [this.Width - win.getWidth() + K, this.Height - win.getHeight() - H + K] 1230 ]; 1231 } else { 1232 return [ 1233 [0, H], 1234 [this.Width - win.getWidth(), this.Height - win.getHeight()] 1235 ]; 1236 }; 1237 }; 1238 this.weiyi = function () { //平方和开方 1239 var num = 0; 1240 for (var i = 0; i < arguments.length; i++) { 1241 num += arguments[i] * arguments[i]; 1242 }; 1243 return Math.round(Math.sqrt(num) * 1000) / 1000 1244 }; 1245 this.windowGXY = function (x, y, k) { 1246 x = (k[0][0] < x && x < k[1][0]) ? x : (k[0][0] < x ? k[1][0] : k[0][0]); 1247 y = (k[0][1] < y && y < k[1][1]) ? y : (k[0][1] < y ? k[1][1] : k[0][1]); 1248 return { 1249 x: x, 1250 y: y 1251 }; 1252 }; 1253 this.windowyidong = (A, s, w) => { 1254 w = w || window; 1255 s = s || 10; 1256 var sx = A[1][0] - A[0][0], 1257 sy = A[1][1] - A[0][1]; 1258 var sd = this.weiyi(sx, sy) / s; 1259 var X = sx / sd, 1260 Y = sy / sd; 1261 var x = 0, 1262 y = 0; 1263 for (var i = 0; i < sd; i++) { 1264 x += X; 1265 y += Y; 1266 sleep(1); 1267 w.setPosition(A[0][0] + x, A[0][1] + y); 1268 }; 1269 w.setPosition(A[1][0], A[1][1]); 1270 }; 1271 this.OutScreen = () => { 1272 var F = this.G(window); 1273 var x = window.getX(), 1274 y = window.getY(); 1275 var sx = window.getX() + window.getWidth() / 2, 1276 sy = window.getY() + window.getHeight() / 2 + 66; 1277 var cx = Math.abs(sx < (this.Width - sx) ? sx : (this.Width - sx)) < Math.abs(sy < (this.Height - sy) ? sy : (this.Height - sy)) ? (sx < this.Width / 2 ? (F[0][0] - window.getWidth()) : (F[1][0] + window.getWidth())) : x, 1278 cy = Math.abs(sx < (this.Width - sx) ? sx : (this.Width - sx)) < Math.abs(sy < (this.Height - sy) ? sy : (this.Height - sy)) ? y : (sy < this.Height / 2 ? (F[0][1] - window.getHeight()) : (F[1][1] + window.getHeight())); 1279 return [ 1280 [x, y], 1281 [cx, cy] 1282 ]; 1283 }; 1284 this.toScreenEdge = (d) => { 1285 d = d || 0; 1286 var F = this.G(window); 1287 var x = window.getX(), 1288 y = window.getY(); 1289 var sw = window.getWidth() * d; 1290 var sx = window.getX() + window.getWidth() / 2, 1291 sy = window.getY() + window.getHeight() / 2 + 66; 1292 var cx = sx < (this.Width - sx) ? -sw : (this.Width + sw - window.getWidth()); 1293 return [ 1294 [x, y], 1295 [cx, y] 1296 ]; 1297 }; 1298 this.centerXY = (F) => { 1299 var w = window.getWidth(); 1300 var h = window.getHeight(); 1301 return [ 1302 [F[0] + w / 2, F[1] + h / 2], 1303 [F[0] - w / 2, F[1] - h / 2] 1304 ]; 1305 }; 1306 this.autoIntScreen = () => { 1307 var A = this.windowGXY(window.getX(), window.getY(), this.G(window)); 1308 threads.start(new java.lang.Runnable(() => { 1309 this.windowyidong([ 1310 [window.getX(), window.getY()], 1311 [A.x, A.y] 1312 ]); 1313 })); 1314 }; 1315 this.autoIntScreen(); 1316 }; 1317 1318 1319 common.闪光弹 = function (content, x, y, color, t) { 1320 1321 1322 1323 1324 var single = (function () { 1325 var unique; 1326 1327 function getInstance() { 1328 if (unique === undefined) { 1329 unique = new Flash(); 1330 } 1331 return unique; 1332 } 1333 return { 1334 getInstance: getInstance 1335 } 1336 })(); 1337 1338 function Flash() {} 1339 Flash.prototype.update = function (content, x, y, color, t) { 1340 this.content = content || '未传入参数' 1341 this.x = x || random(100, 300) 1342 this.y = y || random(100, 900) 1343 this.color = color || -2278181 1344 this.t = t || 2000 1345 } 1346 Flash.prototype.show = function () { 1347 var window = floaty.rawWindow( <card cardBackgroundColor = "#aa00FF00" 1348 cardCornerRadius = "18dp" > 1349 <text id = "text" 1350 size = "30dp" 1351 layout_width = "wrap_content" 1352 layout_height = "wrap_content" 1353 layout_gravity = "center" 1354 gravity = "center" 1355 paddingLeft = "10" 1356 paddingRight = "10" 1357 paddingTop = "10" 1358 paddingBottom = "10" > 123 </text> </card> 1359 ); 1360 window.text.setText(this.content); 1361 window.text.setBackgroundColor(this.color); 1362 window.setPosition(this.x, this.y); 1363 setTimeout(() => { 1364 window.close(); 1365 }, this.t); 1366 } 1367 1368 function flash(content, x, y, color, t) { 1369 var content = content.toString() 1370 var f = single.getInstance() 1371 f.update(content, x, y, color, t) 1372 f.show() 1373 } 1374 var color = color || colors.rgb(random(0, 255), random(0, 255), random(0, 255)) 1375 flash(content, x, y, color, t); 1376 // flash('hello world') 1377 // flash('Are you ok?') 1378 // flash('我很好') 1379 // flash('you are beautiful') 1380 1381 1382 1383 1384 } 1385 common.打开开发者选项 = function () { 1386 app.startActivity({ 1387 action: "android.intent.action.VIEW", //此处可为其他值 1388 packageName: "com.android.settings", 1389 className: "com.android.settings.Settings$DevelopmentSettingsActivity" 1390 //此处可以加入其他内容,如data、extras 1391 }); 1392 } 1393 1394 1395 common.气泡 = function (msg, x, y) { 1396 function toastAt0(msg, x, y) { 1397 importClass(android.widget.Toast); 1398 importClass(android.view.Gravity); 1399 var toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); 1400 toast.setGravity(Gravity.TOP | Gravity.LEFT, x, y); 1401 toast.show(); 1402 } 1403 var x = x || device.width / 3 1404 var y = y || device.height / 5 * 4 1405 var msg = msg.toString() 1406 ui.run(() => toastAt0(msg, x, y)); 1407 sleep(2000) 1408 1409 // toastAt('sdfsfdsdfs',300,300) 1410 1411 1412 1413 1414 } 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 common.随机字符串 = function (PassLength) { 1428 var PassLength = PassLength || 8 1429 var str = 'abcdefghijklmnopqrstuvwxyz'; 1430 var STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 1431 var num = '0123456789'; 1432 var sym = '+=-@#~,.[]()!%^*$'; 1433 var text = str.split('').concat(STR.split('')) 1434 var pw = ''; 1435 for (i = 0; i < PassLength; i++) { 1436 var strpos = random(0, text.length - 1); 1437 pw += text[strpos].charAt(random(0, text[strpos].length - 1)); 1438 } 1439 return pw; 1440 } 1441 1442 common.wifi状态 = function () { 1443 1444 importPackage(android.content); 1445 let wifiManager = context.getSystemService(Context.WIFI_SERVICE); 1446 if (wifiManager.isWifiEnabled()) { 1447 log('wifi is opend') 1448 return 'open' 1449 } else { 1450 log('wifi is closed') 1451 return 'close' 1452 } 1453 1454 1455 } 1456 1457 1458 common.开关飞行模式 = function (开关) { 1459 // 0 关闭 1开启 默认开启飞行模式 1460 var 开关 = 开关 || 1 1461 1462 function 打开飞行模式() { 1463 // 打开飞行模式 1464 new Shell().exec("su -c 'settings put global airplane_mode_on 1; am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true'") 1465 } 1466 1467 function 关闭飞行模式() { 1468 //关闭飞行模式 1469 new Shell().exec("su -c 'settings put global airplane_mode_on 0; am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false'") 1470 } 1471 if (开关 == 1) { 1472 打开飞行模式() 1473 } else { 1474 关闭飞行模式() 1475 } 1476 1477 } 1478 1479 common.上滑 = function () { 1480 var randomP = random(500, 600); 1481 var points = [randomP]; 1482 var interval = 0.1; 1483 var x0 = random(780, 900); 1484 var y0 = random(1500, 1600); 1485 var a = 240; 1486 for (var t = 0; t < Math.PI / 2; t += interval) { 1487 var x = x0 - a * (1.8 * Math.cos(t * 0.9) - Math.cos(2 * t * 0.9)); 1488 var y = y0 - a * (5 * Math.sin(t * 0.9) - Math.sin(2 * t * 0.9)); 1489 points.push([parseInt(x), parseInt(y)]); 1490 } 1491 gesture.apply(null, points); 1492 sleep(1500); 1493 } 1494 1495 common.获取deflate网页内容 = function (url) { 1496 importClass('java.io.BufferedReader'); 1497 importClass('java.io.InputStreamReader'); 1498 importClass("java.util.zip.InflaterInputStream") 1499 importClass('java.io.ByteArrayInputStream'); 1500 importClass("java.util.zip.Inflater") 1501 1502 var res = http.get(url) 1503 log("statusCode = " + res.statusCode); 1504 var deflateFileContent = res.body.bytes() 1505 var 网页内容 = null; 1506 if (deflateFileContent) { 1507 var br = new BufferedReader(new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(deflateFileContent), new Inflater(true)))); 1508 var lns = [], 1509 cl; 1510 while (cl = br.readLine()) lns.push(cl); 1511 网页内容 = lns.join(" ") 1512 // log('网页内容') 1513 // log(网页内容) 1514 return 网页内容 1515 } else { 1516 console.error('下载失败') 1517 exit() 1518 } 1519 return false 1520 } 1521 1522 common.获取gzip网页内容 = function (url) { 1523 function 保存zip文件(zipFile) { 1524 var path = files.join(files.cwd(), "1下载bilibili弹幕专用/webPage.gzip.js") 1525 files.createWithDirs(path) 1526 log("path=", path) 1527 // path= /storage/emulated/0/脚本/zip文件专用/test.zip 1528 files.writeBytes(path, zipFile) 1529 var r = 解压zip文件(path) 1530 log(r) 1531 return r 1532 } 1533 1534 function 解压zip文件(文件路径) { 1535 //同一目录下的同一文件名 1536 // unzipGzipFile(sourceGzipFilePath, targetPath) 1537 var fileName = files.getName(文件路径) 1538 var 解压后的文件路径 = 文件路径.replace(fileName, 'webPage.js') 1539 log('解压的解压后的文件路径=', 解压后的文件路径) 1540 files.createWithDirs(解压后的文件路径) 1541 // com.stardust.io.Zip.unzip(new java.io.File(文件路径), new java.io.File(解压后的文件路径)) 1542 var sourceGzipFilePath = 文件路径 1543 var targetPath = 解压后的文件路径 1544 unzipGzipFile(sourceGzipFilePath, targetPath) 1545 return targetPath 1546 } 1547 1548 function unzipGzipFile(sourceGzipFilePath, targetPath) { 1549 importClass(java.io.FileInputStream); 1550 importClass(java.util.zip.GZIPInputStream); 1551 importClass('java.io.FileOutputStream'); 1552 1553 var sourceGzipFilePath = sourceGzipFilePath || '/sdcard/tempSourceGzipFilePath.js' 1554 var targetPath = targetPath || '/sdcard/tempTargetPath.js' 1555 log('sourceGzipFilePath') 1556 log(sourceGzipFilePath) 1557 log('targetPath') 1558 log(targetPath) 1559 var sChunk = 8192; 1560 var gzipFileInputStream = new FileInputStream(sourceGzipFilePath); 1561 var zipin = new GZIPInputStream(gzipFileInputStream); 1562 var buffer = util.java.array('byte', sChunk) 1563 var out = new FileOutputStream(targetPath); 1564 var length; 1565 while ((length = zipin.read(buffer, 0, sChunk)) != -1) 1566 out.write(buffer, 0, length); 1567 out.close(); 1568 zipin.close(); 1569 } 1570 var res = http.get(url) 1571 log("statusCode = " + res.statusCode); 1572 var gzipFileContent = res.body.bytes() 1573 var 网页内容 = null; 1574 if (gzipFileContent) { 1575 var 网页保存路径 = 保存zip文件(gzipFileContent) 1576 网页内容 = files.read(网页保存路径) 1577 // log('网页内容') 1578 // log(网页内容) 1579 return 网页内容 1580 } else { 1581 console.error('下载失败') 1582 exit() 1583 } 1584 return false 1585 } 1586 1587 1588 // var r=common 1589 // log(r) 1590 // var arr=[] 1591 // for(var k in common){ 1592 // arr.push(k) 1593 // } 1594 // log(arr) 1595 1596 1597 module.exports = common
说明
本文转自https://blog.csdn.net/feiyunjs/article/details/94722766
本文提供的代码仅供参考。
可能有些地方在最新版本的Auto.js上面需要做修改,才能运行。
Auto.js简介
Auto.js是利用安卓系统的“辅助功能”实现类似于按键精灵一样,可以通过代码模拟一系列界面动作的辅助工作。
与“按键精灵”不同的是,它的模拟动作并不是简单的使用在界面定坐标点来实现,而是类似与win一般,找窗口句柄来实现的。
Auto.js使用JavaScript作为脚本语言,目前使用Rhino 1.7.7.2作为脚本引擎,支持ES5与部分ES6特性。
开发文档
Auto.js Pro开发文档优化版
文档尚在完善中,可能有文档描述和代码实际行为有出入的情况。
模板、样式、generator来自Node.js。
吸引我使用Auto.js Pro的原因有很多。最主要的几个原因是:
- Auto.js Pro能开发免ROOT的安卓脚本
- Auto.js Pro基于节点操作,能开发全分辨率的脚本,自动适配各种安卓机型
- Auto.js Pro丰富的UI组件,能自定义各种样式的安卓界面
- Auto.js Pro使用的javascript的语法比较优雅,代码可读性强
- Auto.js Pro的命令库非常的丰富,接口比较多
- Auto.js Pro脚本文件体积比较小。1000行的代码,打包后的apk文件只有3-5M,还没有广告
- 相关教程