autojs05autojspro常用的代碼和公共函數如何用Autojs來寫腳本


如何用Autojs來寫腳本,一部手機除了睡覺的時間之外,都可以給你來賺錢,手機不是用來看的,手機是用來賺錢的。我勸你把手機仍在一個角落里面,讓它乖乖地給你去賺錢,而你呢,你應該去做你自己想做的事情,比如對於我來說,我喜歡寫程序,看書,喝茶,做家務,陪兒子玩。那么這個時間你就不要去玩手機了,極簡主義者連手機這種東西都是不碰的,所以我今天要給大家倡導一個理念:讓手機給你賺零花錢。

植入了理念,后面就談怎么去做,如果你要讓手機給你賺錢,賺的是什么錢,我們這里不做違法的事情,不做黃色的,不做賭博的,那么我們做什么,簡單來說就是薅羊毛,就是通過自動閱讀新聞,觀看視頻,獲取平台的收益,本來這個事情是需要你的手指去瘋狂點擊的,現在呢,就不需要了,要讓計算機腳本語言幫助你去實現。

今天我介紹的一款軟件是Autojs,這個是一個寫手機運行腳本的工具,這個是國人開發的,自豪!!!

這個大家可以在模擬器上面去安裝,具體的操作步驟我就不講了,我主要來講解一下我們怎么去做這個薅羊毛的事情,

模擬器上面裝好以后,就是看到這個界面

我們現在以刷寶為例子,來講解,首先先下載“刷寶短視頻”, 百度搜索一下就可以了,安裝后注冊你的賬號,通常是以微信號來登陸,綁定一下,這樣才能夠提現。

然后我們要下載一個JS code的軟件,這個軟件是方便你在電腦上去寫腳本,原理上你從手機上去寫也是可以的,完全可以,小編就是在去公司的班車上,在手機上來寫薅金腳本的!但是在手機上寫,你會很累,所以你在JS code上下載一個插件,就可以來寫了。這邊我以手機端舉例子,我們來講解一個最簡單的例子,循序漸進地講,其實要很快學會一門計算機編程語言,最快的方法,就是你想要去實現一個東西,然后你帶着這個目標去學怎么寫,這樣是最快的。

今天我們就寫一句代碼,如何自動打開像趣頭條,今日頭條之類的平台,

launchApp("刷寶短視頻");
1
lanchApp("刷寶短視頻“) 解析

好的,我們來講解一下這個代碼的意思,launchApp的意思就是英文“加載App的意思”,這是一個函數,函數是用括號括起來的,大家學過初中數學的話知道函數是 y=f(x), 這個x是自變量,y是應變量,就是說y和x存在一個對應的關系,輸入一個x,通過一定的規則法則,就出來一個y, 這個就是一個規則,比如說:y=2x, 就是你放大了2倍, y=1/2*x,就是縮小了一倍。這個是數學的概念,其實函數的思想可以用來闡述各種事物,計算機編程語言中的函數其實也是這個意思,launchApp就是一個規則,x是什么呢,就是“刷寶短視頻“,那么y是什么呢,這里沒有給定,那就是一個空的返回值,可以不返回任何值,”刷寶短視頻“就是你下載的應用App的名字,同樣,你可以寫“趣頭條”,“今日頭條”等等。

給大家看看,效果,執行這個腳本以后,程序自動開啟“刷寶短視頻”了,怎么樣,好玩嗎
——————————

 

autojspro常用的代碼和公共函數搜集整理,史上最全最完整

 
復制代碼
   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:&nbsp;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}<\/span>([\s\S]*?)<\/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("\n")
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,還沒有廣告
  • 相關教程
  • Auto.js Pro安卓全分辨率免ROOT引流腳本開發教程

 
標簽:  Auto.js
 
 
 
 

——————

autojs   全套

https://github.com/search?o=desc&p=2&q=%E9%92%89%E9%92%89&s=updated&type=Repositories

https://github.com/search?o=desc&q=%E9%92%89%E9%92%89&s=updated&type=Repositories

https://github.com/Serverless-Book-Anycodes/Github-Issue-Robot

 

https://github.com/georgehuan1994/DingDing-Automatic-Clock-in

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM