3 Star 13 Fork 39

带翼而飞/auto.js 停止更新前 备份下来的脚本仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
autojsCommonFunctions.js 89.99 KB
一键复制 编辑 原始数据 按行查看 历史
小凡 提交于 2019-04-29 14:01 . daily-4-29
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071
/**
* 整理者: 家
* QQ: 203118908 有问题请加QQ反馈
* 日期: 20190224
* 妈呀: 整理了一宿,现在是早上6:34
* 功能: 把某些常用的函数集中起来,方便调用
* 函数来源: 都是群里的大佬写的,稻草人,+攀登,Ai,破晓的星辰,灶猫,家,浩然,白酒煮饭,生僻字大佬,内个谁,Xero,无名小姐,壞蛋┭,锦瑟安年Ω,专业滥竽充数,膜拜以上几位大神,不管你们同意不同意,我都把你们的代码搬到一块了,O(∩_∩)O哈哈~
* git: https://raw.githubusercontent.com/snailuncle/autojsDemo/master/autojsCommonFunctions.js
*/
// //导入模块
// function 导入常用函数模块(){
// var url='https://raw.githubusercontent.com/snailuncle/autojsDemo/master/autojsCommonFunctions.js'
// var r = http.get(url)
// log("code = " + r.statusCode);
// var html=r.body.bytes()
// files.write('./autojsCommonFunctions.js','')
// files.writeBytes('./autojsCommonFunctions.js',html)
// var common=require('./autojsCommonFunctions.js')
// return common
// }
// var common=导入常用函数模块()
// log(common)
// for(let i=0;i<33;i++){
// common.闪光弹('fire in the hole')
// }
[
'点击控件',
'铃声',
'启动app',
'停止app',
'卸载app',
'卸载app没root',
'清除app数据',
'启动最新安装的app',
'停止最新安装的app',
'卸载最新安装的app',
'清除最新安装的app数据',
'静默安装app',
'获取app图标',
'控制app联网',
'获取手机上所有的app名字',
'点击输入框弹出输入法',
'使所有输入框点击时都能弹出输入法',
'失去焦点',
'是否root',
'获取指定应用的版本号',
'打开qq群名片',
'打开qq名片',
'qq强制聊天',
'字节变为gbk中文',
'最新安装的app',
'文件修改时间',
'文件大小',
'字符串变字节',
'日期加N天',
'日期变时间戳',
'md5',
'是横屏还是竖屏',
'截图',
'随机字符',
'获取时间',
'调整手机音量',
'微信扫一扫',
'公共字符串',
'网络',
'安卓intent源码',
'获取手机ip地理位置',
'替换系统文件',
'编辑距离',
'数组交集',
'提取包含关键字的app',
'获取页面所有文字',
'悬浮控制',
'闪光弹',
'打开开发者选项',
'气泡',
'随机字符串',
'wifi状态',
'开关飞行模式',
'上滑',
'获取deflate网页内容',
'获取gzip网页内容',
'发送通知',
'去除通知',
'clickAttr',
'pressAttr',
'获取拼音',
'画出控件区域',
'获取多开分身右侧字母区域控件',
'画矩形',
'画点',
'strip', // 去除头尾空格
'大数组包含小数组',
'getObjType',
'deepCopy', // 深拷贝
'反色',
'bmob上传文件',
'bmob下载文件',
'过微信QQ滑块',
'确保有jar文件',
'获取QQ收藏内容',
'获取多开分身右侧字母区域指定字母的位置',
'模拟真人滑动',
'画手势',
'指定特征的控件是否存在',
]
var common = {}
Array.prototype.intersect = function () {
var result = new Array();
var obj = {};
for (var i = 0; i < arguments.length; i++) {
for (var j = 0; j < arguments[i].length; j++) {
var str = arguments[i][j];
if (!obj[str]) {
obj[str] = 1;
} else {
obj[str]++;
if (obj[str] == arguments.length) {
result.push(str);
}
} //end else
} //end for j
} //end for i
return result;
}
//集合去掉重复
Array.prototype.uniquelize = function () {
var tmp = {},
ret = [];
for (var i = 0, j = this.length; i < j; i++) {
if (!tmp[this[i]]) {
tmp[this[i]] = 1;
ret.push(this[i]);
}
}
return ret;
}
//并集
Array.prototype.union = function () {
var arr = new Array();
var obj = {};
for (var i = 0; i < arguments.length; i++) {
for (var j = 0; j < arguments[i].length; j++) {
var str = arguments[i][j];
if (!obj[str]) {
obj[str] = 1;
arr.push(str);
}
} //end for j
} //end for i
return arr;
}
//2个集合的差集 在arr不存在
Array.prototype.minus = function (arr) {
var result = new Array();
var obj = {};
for (var i = 0; i < arr.length; i++) {
obj[arr[i]] = 1;
}
for (var j = 0; j < this.length; j++) {
if (!obj[this[j]]) {
obj[this[j]] = 1;
result.push(this[j]);
}
}
return result;
};
// console.log(Array.intersect(["1", "2", "3"], ["2", "3", "4", "5", "6"])); //[2,3]
// console.log([1, 2, 3, 2, 3, 4, 5, 6].uniquelize()); //[1,2,3,4,5,6]
// console.log(Array.union(["1", "2", "3"], ["2", "3", "4", "5", "6"], ["5", "6", "7", "8", "9"]))
// console.log(["2", "3", "4", "5", "6"].minus(["1", "2", "3"]));
common.点击控件 = function (view) {
log(arguments.callee.name + '开始')
log(view)
if (view) {
var x = view.bounds().centerX()
var y = view.bounds().centerY()
log('将要点击的坐标 %s,%s', x, y)
press(x, y, 1)
} else {
throw '传入点击控件中的view异常'
}
log(arguments.callee.name + '结束')
}
common.铃声 = function (铃声类型, 是否循环播放, 播放时长) {
var 铃声类型 = 铃声类型 || 0
var 播放时长 = 播放时长 || 6000
var 是否循环播放 = 是否循环播放 || false
if (是否循环播放) {
播放时长 = 666 * 1000
}
var 铃声选择结果 = android.media.RingtoneManager.TYPE_NOTIFICATION
switch (铃声类型) {
case 0:
铃声选择结果 = android.media.RingtoneManager.TYPE_RINGTONE
break;
case 1:
铃声选择结果 = android.media.RingtoneManager.TYPE_ALARM
break;
case 2:
铃声选择结果 = android.media.RingtoneManager.TYPE_ALL
break;
default:
break;
}
var mp = new android.media.MediaPlayer();
mp.setDataSource(context, android.media.RingtoneManager.getDefaultUri(铃声选择结果));
if (是否循环播放) mp.setLooping(true);
mp.prepare();
mp.start();
threads.start(function () {
sleep(播放时长)
if (mp.isPlaying()) {
mp.stop()
}
});
return mp;
}
common.启动app = function (appName) {
launchApp(appName)
}
common.停止app = function (appName) {
var packageName=getPackageName(appName);
shell('am force-stop ' + packageName,true);
}
common.卸载app = function (appName) {
var packageName=getPackageName(appName);
shell("pm uninstall "+packageName,true)
}
common.清除app数据 = function (appName) {
var packageName=getPackageName(appName);
shell('pm clear ' + packageName,true);
}
common.卸载最新安装的app=function (){
var pm = context.getPackageManager()
var appList=pm.getInstalledApplications(0)
var appInfoList=[]
for(let i=0;i<appList.size();i++){
var app=appList.get(i)
var appInfo={
appName:app.loadLabel(pm),
packageName:app.packageName,
isSystemApp:app.isSystemApp(),
firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime
}
appInfoList.push(appInfo)
}
appInfoList.sort((a,b)=>{
return b.firstInstallTime-a.firstInstallTime
})
log('最新安装的app是=%j',appInfoList[0])
var packageName=appInfoList[0].packageName
shell("pm uninstall "+packageName,true)
return appInfoList[0].appName
}
common.清除最新安装的app数据=function (){
var pm = context.getPackageManager()
var appList=pm.getInstalledApplications(0)
var appInfoList=[]
for(let i=0;i<appList.size();i++){
var app=appList.get(i)
var appInfo={
appName:app.loadLabel(pm),
packageName:app.packageName,
isSystemApp:app.isSystemApp(),
firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime
}
appInfoList.push(appInfo)
}
appInfoList.sort((a,b)=>{
return b.firstInstallTime-a.firstInstallTime
})
log('最新安装的app是=%j',appInfoList[0])
var packageName=appInfoList[0].packageName
shell('pm clear ' + packageName,true);
return appInfoList[0].appName
}
common.停止最新安装的app=function (){
var pm = context.getPackageManager()
var appList=pm.getInstalledApplications(0)
var appInfoList=[]
for(let i=0;i<appList.size();i++){
var app=appList.get(i)
var appInfo={
appName:app.loadLabel(pm),
packageName:app.packageName,
isSystemApp:app.isSystemApp(),
firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime
}
appInfoList.push(appInfo)
}
appInfoList.sort((a,b)=>{
return b.firstInstallTime-a.firstInstallTime
})
log('最新安装的app是=%j',appInfoList[0])
var packageName=appInfoList[0].packageName
shell('am force-stop ' + packageName,true);
return appInfoList[0].appName
}
common.启动最新安装的app=function (){
var pm = context.getPackageManager()
var appList=pm.getInstalledApplications(0)
var appInfoList=[]
for(let i=0;i<appList.size();i++){
var app=appList.get(i)
var appInfo={
appName:app.loadLabel(pm),
packageName:app.packageName,
isSystemApp:app.isSystemApp(),
firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime
}
appInfoList.push(appInfo)
}
appInfoList.sort((a,b)=>{
return b.firstInstallTime-a.firstInstallTime
})
log('最新安装的app是=%j',appInfoList[0])
var packageName=appInfoList[0].packageName
launch(packageName)
return appInfoList[0].appName
}
common.点击输入框弹出输入法=function (window,view){
view.on(
"touch_down", function () {
window.requestFocus();
view.requestFocus();
}
)
view.on(
"key", function (keyCode,event) {
if(event.getAction()==event.ACTION_DOWN && keyCode == keys.back){
window.disableFocus()
event.consumed=true
}
window.requestFocus();
view.requestFocus();
}
)
}
common.使所有输入框点击时都能弹出输入法=function (window,inputBoxViewArr){
for(let i=0;i<inputBoxViewArr.length;i++){
var view=inputBoxViewArr[i]
common.点击输入框弹出输入法(window,view)
}
}
common.失去焦点=function (window){
window.disableFocus()
}
common.是否root=function(){
var r=shell("ls /system/bin",true).result.toString()
if(r.length>50){
return true
}else{
return false
}
}
common.获取指定应用的版本号 = function (appName) {
/**
* 获取指定应用的版本号
* @param {string} packageName 应用包名
*/
function getPackageVersion(packageName) {
importPackage(android.content);
var pckMan = context.getPackageManager();
var packageInfo = pckMan.getPackageInfo(packageName, 0);
return packageInfo.versionName;
}
var packageName = getPackageName(appName);
return getPackageVersion(packageName)
}
common.打开qq群名片=function (qq群号){
app.startActivity({
action: "android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?card_type=group&uin="+qq群号,
packageName: "com.tencent.mobileqq",
});//打开qq群名片
}
common.打开qq名片=function (qq号){
app.startActivity({
action: "android.intent.action.VIEW",
data:"mqqapi://card/show_pslcard?uin="+qq号,
packageName: "com.tencent.mobileqq",
});//打开qq名片
}
common.qq强制聊天=function (qq号){
app.startActivity({
action: "android.intent.action.VIEW",
data:"mqq://im/chat?chat_type=wpa&version=1&src_type=web&uin="+qq号,
packageName: "com.tencent.mobileqq",
});//qq强制聊天
}
common.字节变为gbk中文 = function (bytesContent) {
var str = new java.lang.String(bytesContent, "gbk")
return str
}
common.最新安装的app = function () {
var pm = context.getPackageManager()
var appList=pm.getInstalledApplications(0)
var appInfoList=[]
for(let i=0;i<appList.size();i++){
var app=appList.get(i)
var appInfo={
appName:app.loadLabel(pm),
packageName:app.packageName,
isSystemApp:app.isSystemApp(),
firstInstallTime:pm.getPackageInfo(app.packageName,0).firstInstallTime
}
appInfoList.push(appInfo)
}
appInfoList.sort((a,b)=>{
return b.firstInstallTime-a.firstInstallTime
})
log('最新安装的app是=%j',appInfoList[0])
return appInfoList[0]
}
common.文件修改时间 = function (path) {
var time=new java.io.File(files.path(path)).lastModified();
return time
}
common.文件大小 = function (path) {
var size = new java.io.File(path).length()
return size
}
common.字符串变字节 = function (string) {
return new java.lang.String(string).getBytes();
}
common.日期加N天 = function (n) {
var now = new Date();
now.setDate(now.getDate()+n);
return (now);
}
common.md5 = function (string) {
return java.math.BigInteger(1,java.security.MessageDigest.getInstance("MD5")
.digest(java.lang.String(string).getBytes())).toString(16);
}
common.是横屏还是竖屏 = function () {
var a = (context.resources.configuration.orientation);
if (a === 1) {
toastLog("这是竖屏!!");
return '竖屏'
}
else {
toastLog("这是横屏!!");}
return '横屏'
}
common.截图 = function (path) {
var path=path || '/sdcard/1temp.png'
var dd = shell("screencap -p "+path,true)
var img
if(dd.code ==0){
img = images.read(path)
}else{
log("错误信息:")
log(dd.error)
}
return img
}
common.随机字符=function (n){
var n= n || 8
var str="";
for(var i=0;i<n;i++){
str+=String.fromCharCode(random(0,65535));
}
return str;
}
common.获取时间=function (time) {
if (time) {
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(time));
} else {
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
}
}
common.调整手机音量=function (){
var am = context.getSystemService(context.AUDIO_SERVICE)
// STREAM_MUSIC这个自己试试,是调整那种音量,范围0-6 自己试试,我也不知道
var STREAM_MUSIC = 1
// 1 增大音量 -1 降低音量 0 不变
var ADJUST_RAISE = -1
// 1 显示调整音量界面 0 不显示界面
var FLAG_SHOW_UI = 1
am.adjustStreamVolume(STREAM_MUSIC, ADJUST_RAISE, FLAG_SHOW_UI)
//获取最大音量
var max = am.getStreamMaxVolume(STREAM_MUSIC);
log(max)
//获取当前音量
toastLog('最大音量'+max)
sleep(2000)
var current = am.getStreamVolume(STREAM_MUSIC);
log(current)
toastLog('当前音量'+current)
}
common.微信扫一扫=function (){
context.startActivity(app.intent({
action: "VIEW",
className:"com.tencent.mm.ui.LauncherUI",
packageName:"com.tencent.mm",
extras: {
"LauncherUI.From.Scaner.Shortcut": true
}
}).setFlags(335544320));
}
common.公共字符串=function (str1,str2){
// var str1 = "aaabbba"
// var str2 = " bbbcaaa"
function find(str1, str2) {
//创建存放重复内容的数组
var all = new Array();
//字符串转字符数组
var str_1 = str1.split("");
var str_2 = str2.split("");
for (var i = 0; i < str_1.length; i++) {
for (var l = 0; l < str_2.length; l++) {
//判断是否重复
var lo = all.length;
all[lo] = "";
//判断之后的字符串是否相同
for (var k = 0; str_1[i + k] == str_2[l + k]; k++) {
all[lo] = all[lo] + str_1[i + k];
//防止数组越界,提前停止循环
if (i + k == str_1.length-1||i+k==str_2.length-1) {
break;
}
}
}
}
var most = 0;
var fu = new Array();
for (var j = 0; j < all.length; j++) {
//去除空的内容
if (all[j] != "") {
//按照大小排序(删除部分小的)
if (all[j].split("").length >= most) {
most = all[j].split("").length;
fu[fu.length] = all[j];
}
}
}
//将不重复内容写到新数组
var wu=new Array();
for(var i=0;i<fu.length;i++){
var c=false;
for(var l=0;l<wu.length;l++){
if(fu[i]==wu[l]){
c=true;
}
}
if(!c){
wu[wu.length]=fu[i];
}
}
//将最长的内容写到新数组
var ml=new Array();
//获得最后一个字符串的长度(最长)
var longest=wu[wu.length-1].split("").length;
//长度等于最长的内容放到新数组
for(var i=wu.length-1;i>=0;i--){
if(wu[i].split("").length==longest){
ml[ml.length]=wu[i];
}else{
//提前结束循环
break;
}
}
return ml
}
var result=find(str1, str2)
log(result)
return result
}
common.网络=function (){
var intent = new Intent();
importClass(android.content.BroadcastReceiver);
importClass(android.content.ContextWrapper);
importClass(android.content.IntentFilter);
importClass(android.net.ConnectivityManager);
var filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
new ContextWrapper(context).registerReceiver(a = new BroadcastReceiver({
onReceive: function(context, intent) {
var action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
var mConnectivityManager = context.getSystemService(context.CONNECTIVITY_SERVICE);
netInfo = mConnectivityManager.getActiveNetworkInfo();
if (netInfo != null && netInfo.isAvailable()) {
/////////////网络连接
var name = netInfo.getTypeName();
if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
/////WiFi网络
toastLog("WiFi网络");
return "WiFi网络"
} else if (netInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
/////有线网络
toastLog("有线网络");
return "有线网络"
} else if (netInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
/////////3g网络
toastLog("3g网络");
return "3g网络"
}
} else {
////////网络断开
toastLog("网络断开");
return "网络断开"
}
}
}
}), filter);
}
common.安卓intent源码=function (){
var intent = new Intent();
intent.setAction("android.settings.ACCESSIBILITY_SETTINGS");
//辅助功能
//intent.setAction("android.settings.ADD_ACCOUNT_SETTINGS");
//添加账户
//intent.setAction("android.settings.AIRPLANE_MODE_SETTINGS");
//系统设置首页
//intent.setAction("android.settings.APN_SETTINGS");
//APN设置
//intent.setAction("android.settings.APPLICATION_SETTINGS");
//应用管理
//intent.setAction("android.settings.BATTERY_SAVER_SETTINGS");
//节电助手
//intent.setAction("android.settings.BLUETOOTH_SETTINGS");
//蓝牙
//intent.setAction("android.settings.CAPTIONING_SETTINGS");
//字幕
//intent.setAction("android.settings.CAST_SETTINGS");
//无线显示
//intent.setAction("android.settings.DATA_ROAMING_SETTINGS");
//移动网络
//intent.setAction("android.settings.DATE_SETTINGS");
//日期和时间设置
//intent.setAction("android.settings.DEVICE_INFO_SETTINGS");
//关于手机
//intent.setAction("android.settings.DISPLAY_SETTINGS");
//显示设置
//intent.setAction("android.settings.DREAM_SETTINGS");
//互动屏保设置
//intent.setAction("android.settings.HARD_KEYBOARD_SETTINGS");
//实体键盘
//intent.setAction("android.settings.HOME_SETTINGS");
//应用权限,默认应用设置,特殊权限
//intent.setAction("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS");
//忽略电池优化设置
//intent.setAction("android.settings.INPUT_METHOD_SETTINGS");
//可用虚拟键盘设置
//intent.setAction("android.settings.INPUT_METHOD_SUBTYPE_SETTINGS");
//安卓键盘语言设置(AOSP)
//intent.setAction("android.settings.INTERNAL_STORAGE_SETTINGS");
//内存和存储
//intent.setAction("android.settings.LOCALE_SETTINGS");
//语言偏好设置
//intent.setAction("android.settings.LOCATION_SOURCE_SETTINGS");
//定位服务设置
//intent.setAction("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS");
//所有应用
//intent.setAction("android.settings.MANAGE_APPLICATIONS_SETTINGS");
//应用管理
//intent.setAction("android.settings.MANAGE_DEFAULT_APPS_SETTINGS");
//与ACTION_HOME_SETTINGS相同
//intent.setAction("android.settings.action.MANAGE_OVERLAY_PERMISSION");
//在其他应用上层显示,悬浮窗
//intent.setAction("android.settings.MANAGE_UNKNOWN_APP_SOURCES");
//安装未知应用 安卓8.0
//intent.setAction("android.settings.action.MANAGE_WRITE_SETTINGS");
//可修改系统设置 权限
//intent.setAction("android.settings.MEMORY_CARD_SETTINGS");
//内存与存储
//intent.setAction("android.settings.NETWORK_OPERATOR_SETTINGS");
//可用网络选择
//intent.setAction("android.settings.NFCSHARING_SETTINGS");
//NFC设置
//intent.setAction("android.settings.NFC_SETTINGS");
//网络中的 更多设置
//intent.setAction("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
//通知权限设置
//intent.setAction("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS");
//勿扰权限设置
//intent.setAction("android.settings.ACTION_PRINT_SETTINGS");
//打印服务设置
//intent.setAction("android.settings.PRIVACY_SETTINGS");
//备份和重置
//intent.setAction("android.settings.SECURITY_SETTINGS");
//安全设置
//intent.setAction("android.settings.SHOW_REGULATORY_INFO");
//监管信息
//intent.setAction("android.settings.SOUND_SETTINGS");
//声音设置
//intent.setAction("android.settings.SYNC_SETTINGS");
//添加账户设置
//intent.setAction("android.settings.USAGE_ACCESS_SETTINGS");
//有权查看使用情况的应用
//intent.setAction("android.settings.USER_DICTIONARY_SETTINGS");
//个人词典
//intent.setAction("android.settings.VOICE_INPUT_SETTINGS");
//辅助应用和语音输入
//intent.setAction("android.settings.VPN_SETTINGS");
//VPN设置
//intent.setAction("android.settings.VR_LISTENER_SETTINGS");
//VR助手
//intent.setAction("android.settings.WEBVIEW_SETTINGS");
//选择webview
//intent.setAction("android.settings.WIFI_IP_SETTINGS");
//高级WLAN设置
//intent.setAction("android.settings.WIFI_SETTINGS");
//选择WIFI,连接WIFI
app.startActivity(intent);
}
common.获取手机ip地理位置 = function () {
var ip地理位置 = false
var ip地理位置正则 = /本机IP:&nbsp;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}<\/span>([\s\S]*?)<\/td/
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"
var r = http.get(ipUrl);
log("code = " + r.statusCode);
var htmlResult = r.body.string()
ip地理位置 = ip地理位置正则.exec(htmlResult)
if (ip地理位置) {
ip地理位置 = ip地理位置正则.exec(ip地理位置)
ip地理位置 = ip地理位置[0]
if (ip地理位置) {
var ip正则 = /\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}/
var 地理位置正则 = /span>.+?\t/
var ip = ip地理位置.match(ip正则)
var 地理位置 = ip地理位置.match(地理位置正则)
if (ip) {
ip = ip[0]
}
if (地理位置) {
地理位置 = 地理位置[0].replace(/(span>|\t)/g, "")
}
var info = {
ip: ip,
地理位置: 地理位置
}
toastLog(info)
return info
} else {
log('没有查询到Ip地理位置,脚本停止')
return false
}
} else {
log('没有查询到Ip地理位置,脚本停止')
return false
}
}
common.获取app图标=function (appName){
importClass(java.io.File);
importClass(java.io.FileOutputStream);
importClass(android.graphics.Bitmap);
var pm = context.getPackageManager();
importClass(android.util.DisplayMetrics)
var name = appName
var packageName = app.getPackageName(name);
var appInfo = pm.getApplicationInfo(packageName, 0);
var bmp = appInfo.loadIcon(pm).getBitmap();
files.create("/sdcard/"+name+".jpg");
var f = new File("/sdcard/"+name+"qq.jpg");
var fOut = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
var img=images.read("sdcard/"+name+".jpg")
return img
// app.viewFile("sdcard/"+name+".jpg")
}
common.替换系统文件 = function (syspath,sdpath) {
// // var path = "/data/data/com.aaa.bbb"
// // var pathSD = "/sdcard/com.aaa.bbb"
// //删除原来的文件
// shell('chown root:root ' + path, true)
// shell('rm ' + path + " -rf", true);
// shell('rm ' + pathSD + " -rf", true);
// sleep(2000)
// // 解压备份的文件
// var inkeSdacrdPath = "/sdcard/com.aaa.bbb.zip"
// var 文件路径 = inkeSdacrdPath
// var 文件夹路径 = "/sdcard"
// com.stardust.io.Zip.unzip(new java.io.File(文件路径), new java.io.File(文件夹路径))
// sleep(2000)
// //移动解压后的文件
// shell("mv -f /sdcard/com.aaa.bbb /data/data/com.aaa.bbb", true);
// //修改权限
// shell("chmod -R 777 /data/data/com.aaa.bbb", true);
//------------------------------------------------
//------------------------------------------------
//------------------------------------------------
// var path = "/data/data/com.aaa.bbb"
// var pathSD = "/sdcard/com.aaa.bbb"
//删除原来的文件
shell('chown root:root ' + syspath, true)
shell('rm ' + path + " -rf", true);
sleep(2000)
//移动解压后的文件
shell("mv -f "+sdpath+" "+syspath, true);
//修改权限
shell("chmod -R 777 "+syspath, true);
}
common.编辑距离 = function (sm,sn){
var m=sm.length+1
var n=sn.length+1
var matrix = new Array();
for ( var i = 0; i < m; i++) {
matrix[i] = new Array();
for ( var j = 0; j < n; j++) {
matrix[i][j] = 0;
}
}
matrix[0][0]=0
for(let i=1;i<m;i++){
matrix[i][0] = matrix[i-1][0] + 1
}
for(let j=1;j<n;j++){
matrix[0][j] = matrix[0][j-1]+1
}
cost = 0
for(let i=1;i<m;i++){
for(let j=1;j<n;j++){
if(sm[i-1]==sn[j-1]){
cost = 0
}
else{
cost = 1
}
matrix[i][j]=Math.min(matrix[i-1][j]+1,matrix[i][j-1]+1,matrix[i-1][j-1]+cost)
}
}
return matrix[m-1][n-1]
// var mindist=minEditDist("126","456")
// print(mindist)
}
common.静默安装app = function (apk路径) {
shell("pm install -r " + apk路径 , true)
}
common.获取手机上所有的app名字 = function () {
var 所有的app名字=[]
var pm=context.getPackageManager()
let list=pm.getInstalledApplications(0)
for(let i=0;i<list.size();i++){
let p=list.get(i)
var app={
appName:p.loadLabel(pm),
packageName:p.packageName
}
所有的app名字.push(app.appName)
}
return 所有的app名字
}
common.数组交集=function(){
var 交集 = Array.intersect(arr1, arr2)
log(交集)
return 交集
}
common.控制app联网 = function (appName, 是否允许联网联网) {
var 是否允许联网联网 = 是否允许联网联网 || true
//作者: 家 QQ203118908
//本来打算用iptables-restore用文件形式更新防火墙规则,
//可是iptables-restore出现了bug,2013年就有人提过这个bug
//https://linux.debian.bugs.dist.narkive.com/J0hbJiR6/bug-710379-xtables-addons-common-quota2-module-iptables-save-creates-invalid-record
//又得改,坑爹
//马丹,iptables -D INPUT -lineNumber也有BUG,
//提示 index of deletion too big
//日了够了
//又得改,坑爹
// sudo iptables -D OUTPUT 1 -t nat
//
// uid=`cat /data/system/packages.list | grep com.sohu.inputmethod.sogou | busybox awk '{print $2}'`
// iptables -t filter -A OUTPUT -m owner --uid-owner=$uid -j DROP
// 以上是android iptables 屏蔽某个app网络访问的内容,
function 联网控制(appName) {
// -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT
// -A OUTPUT -m owner --uid-owner 10105 -j DROP
this.等待shell执行完毕的时间 = 0
this.防火墙规则路径 = '/sdcard/iptables.txt'
this.uid路径 = '/sdcard/' + appName + 'uidOwner.txt'
this.appName = appName
this.packageName = getPackageName(this.appName)
this.执行shell = (cmd) => {
var result = shell(cmd, true);
console.show();
log(result);
if (result.code == 0) {
toastLog("执行成功");
} else {
toastLog("执行失败!请到控制台查看错误信息");
}
sleep(this.等待shell执行完毕的时间)
}
this.uid = () => {
var cmd = 'cat /data/system/packages.list | grep ' + this.packageName + ' > ' + this.uid路径
log('cmd=', cmd)
this.执行shell(cmd)
// cat /data/system/packages.list | grep com.tencent.mobileqq > /sdcard/QQuidOwner.txt
var 包含uid的文本 = files.read('/sdcard/' + appName + 'uidOwner.txt')
log('包含uid的文本=', 包含uid的文本)
var uidReg = new RegExp(this.packageName + '\\s*(\\d+)')
log('uidReg=', uidReg)
var uid = 包含uid的文本.match(uidReg)[1]
log(uid)
return uid
}
this.允许联网规则 = 'iptables -t filter -A OUTPUT -m owner --uid-owner ' + this.uid() + ' -j ACCEPT'
this.禁止联网规则 = 'iptables -t filter -A OUTPUT -m owner --uid-owner ' + this.uid() + ' -j DROP'
this.允许 = () => {
this.清空该app的防火墙规则()
this.将防火墙规则写入系统(this.允许联网规则)
}
this.禁止 = () => {
this.清空该app的防火墙规则()
this.将防火墙规则写入系统(this.禁止联网规则)
}
this.将防火墙规则写入系统 = (防火墙规则) => {
var cmd = 防火墙规则
this.执行shell(cmd)
}
this.导出防火墙规则 = () => {
var cmd = 'iptables-save > ' + this.防火墙规则路径
this.执行shell(cmd)
}
this.防火墙规则 = () => {
this.导出防火墙规则()
var 防火墙规则 = files.read(this.防火墙规则路径)
log('防火墙规则=', 防火墙规则)
return 防火墙规则
}
this.清空该app的防火墙规则 = () => {
var 防火墙规则 = this.防火墙规则()
// stringObject.replace(regexp/substr,replacement)
// -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT
// -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT
// -A OUTPUT -m owner --uid-owner 10105 -j DROP
// -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT
// -A OUTPUT -m owner --uid-owner 10105 -j ACCEPT
// 删除之前添加的规则(iptables -A INPUT -s 192.168.1.5 -j DROP):
// [root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP
// iptables -t filter -A OUTPUT -m owner --uid-owner=$uid -j DROP
var 要删除的规则reg = new RegExp('-A (OUT|IN)PUT -m owner --uid-owner ' + this.uid() + ' -j (ACCEPT|DROP)', 'g')
// 要删除的规则reg= /-A OUTPUT -m owner --uid-owner 10105 -j (ACCEPT|DROP)/
// -A OUTPUT -m owner --uid-owner 10105 -j (ACCEPT|DROP)
// iptables -D OUTPUT -m owner --uid-owner 10105 -j ACCEPT
log('要删除的规则reg=', 要删除的规则reg)
var new防火墙规则 = 防火墙规则.match(要删除的规则reg, '')
log('new防火墙规则=', new防火墙规则)
// new防火墙规则= [
// '-A OUTPUT -m owner --uid-owner 10105 -j ACCEPT',
// '-A OUTPUT -m owner --uid-owner 10105 -j DROP'
// ]
if (new防火墙规则) {
for (let i = 0; i < new防火墙规则.length; i++) {
var 规则 = new防火墙规则[i]
规则 = 规则.replace('-A', '-D')
var cmd = 'iptables ' + 规则
this.执行shell(cmd)
}
}
log('清空了指定app的防火墙规则')
}
}
// var appName = 'QQ'
// var appName = '哔哩哔哩'
var appName = '微信'
var app联网控制 = new 联网控制(appName)
if (是否允许联网联网) {
app联网控制.允许()
} else {
app联网控制.禁止()
}
}
common.提取包含关键字的app = function (app关键字) {
importClass(android.content.pm.PackageManager)
var uc应用 = []
var ucapp = {}
pm = context.getPackageManager();
var 有的 = pm.getInstalledPackages(PackageManager.GET_SHARED_LIBRARY_FILES)
有的 = pm.getInstalledPackages(PackageManager.GET_META_DATA)
有的 = 有的 + ""
有的 = 有的.replace(/PackageInfo[^ ]+ /g, "")
有的 = 有的.replace(/[\}|\[|\]| ]/g, "")
有的 = 有的.split(",")
for (let i of 有的) {
var packageInfo = pm.getPackageInfo(i, 0);
var appName = packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString()
//appName = app.getAppName(i)
if (appName.match(app关键字)) {
// log(appName)
// log("包名:" + i)
ucapp = {
"包名": i,
"名称": appName
}
uc应用.push(ucapp) 
}
}
return uc应用
}
common.卸载app没root = function (appName) {
var packageName=getPackageName(appName);
app.uninstall(packageName);
}
common.获取页面所有文字 = function (setting) {
var setting = setting || {}
var defaultSetting = {
getText: true,
getDesc: true,
getId: false,
removeRepetitiveElements: true
}
Object.assign(defaultSetting, setting);
log(defaultSetting)
var allStr = []
var getDescAndTextAndIdOfNode = function (node) {
if (node) {
if (defaultSetting.getText) {
var text = node.text()
if (!!text) {
allStr.push(text)
}
}
if (defaultSetting.getDesc) {
var desc = node.desc()
if (!!desc) {
allStr.push(desc)
}
}
if (defaultSetting.getId) {
var id = node.id()
if (!!id) {
allStr.push(id)
}
}
}
for (let i = 0; i < node.childCount(); i++) {
getDescAndTextAndIdOfNode(node.child(i));
}
}
var getFrameLayoutNode = function () {
return className('FrameLayout').findOne(2000)
}
getDescAndTextAndIdOfNode(getFrameLayoutNode())
function removeRepetitiveElements(arr) {
var obj = {}
for (let i = 0; i < arr.length; i++) {
if (obj.hasOwnProperty(arr[i])) {} else {
obj[arr[i]] = true
}
}
return Object.keys(obj)
}
if (defaultSetting.removeRepetitiveElements) {
allStr = removeRepetitiveElements(allStr)
}
return allStr
}
common.悬浮控制 = function (window, windowid, ar) {
this.Orientation = context.resources.configuration.orientation;
this.Width = this.Orientation == 1 ? device.width : device.height;
this.Height = this.Orientation == 2 ? device.width : device.height;
this.Click = function () {};
this.Move = function () {};
this.LongClick = function () {};
this.setClick = (fun) => {
fun = fun || function () {};
this.Click = fun;
};
this.setMove = (fun) => {
fun = fun || function () {};
this.Move = fun;
};
this.setLongClick = (fun, ji) => {
fun = fun || function () {};
this.LongClick = fun;
if (parseInt(ji)) {
this.Tjitime = parseInt(ji) / 50;
};
};
setInterval(() => {
if (context.resources.configuration.orientation != this.Orientation) {
this.Orientation = context.resources.configuration.orientation;
this.Width = this.Orientation == 1 ? device.width : device.height;
this.Height = this.Orientation == 2 ? device.width : device.height;
var xy = this.windowGXY(window.getX(), window.getY(), this.G(window));
this.windowyidong([
[window.getX(), window.getY()],
[xy.x, xy.y]
]);
};
}, 100);
this.TX = 0;
this.TY = 0;
this.Tx = 0;
this.Ty = 0;
this.Tyidong = false;
this.Tkeep = false;
this.Tjitime = 12;
this.Ttime = 0;
setInterval(() => {
if (this.Tkeep) {
this.Ttime++;
if (!this.Tyidong && this.Ttime > this.Tjitime) {
//非移动且按下时长超过1秒判断为长按
this.Tkeep = false;
this.Ttime = 0;
this.LongClick();
};
};
}, 50);
if (windowid) {
windowid.setOnTouchListener(new android.view.View.OnTouchListener((view, event) => {
this.Move(view, event);
switch (event.getAction()) {
case event.ACTION_DOWN:
this.Tx = event.getRawX();
this.Ty = event.getRawY();
this.TX = window.getX();
this.TY = window.getY();
this.Tkeep = true; //按下,开启计时
break;
case event.ACTION_MOVE:
var sx = event.getRawX() - this.Tx;
var sy = event.getRawY() - this.Ty;
if (!this.Tyidong && this.Tkeep && this.weiyi(sx, sy) >= 10) {
this.Tyidong = true;
};
if (this.Tyidong && this.Tkeep) {
window.setPosition(this.TX + sx, this.TY + sy);
};
break;
case event.ACTION_UP:
if (!this.Tyidong && this.Tkeep && this.Ttime < 7) {
this.Click();
};
this.Tkeep = false;
this.Ttime = 0;
if (this.Tyidong) {
var A = this.windowGXY(window.getX(), window.getY(), this.G(window));
threads.start(new java.lang.Runnable(() => {
this.windowyidong([
[window.getX(), window.getY()],
[A.x, A.y]
]);
}));
this.Tyidong = false;
};
break;
};
return true;
}));
};
this.G = (win) => {
var K = 35, //悬浮窗的隐形边矩
H = 66; //手机通知栏的高度
if (!ar) {
return [
[-K, -K],
[this.Width - win.getWidth() + K, this.Height - win.getHeight() - H + K]
];
} else {
return [
[0, H],
[this.Width - win.getWidth(), this.Height - win.getHeight()]
];
};
};
this.weiyi = function () { //平方和开方
var num = 0;
for (var i = 0; i < arguments.length; i++) {
num += arguments[i] * arguments[i];
};
return Math.round(Math.sqrt(num) * 1000) / 1000
};
this.windowGXY = function (x, y, k) {
x = (k[0][0] < x && x < k[1][0]) ? x : (k[0][0] < x ? k[1][0] : k[0][0]);
y = (k[0][1] < y && y < k[1][1]) ? y : (k[0][1] < y ? k[1][1] : k[0][1]);
return {
x: x,
y: y
};
};
this.windowyidong = (A, s, w) => {
w = w || window;
s = s || 10;
var sx = A[1][0] - A[0][0],
sy = A[1][1] - A[0][1];
var sd = this.weiyi(sx, sy) / s;
var X = sx / sd,
Y = sy / sd;
var x = 0,
y = 0;
for (var i = 0; i < sd; i++) {
x += X;
y += Y;
sleep(1);
w.setPosition(A[0][0] + x, A[0][1] + y);
};
w.setPosition(A[1][0], A[1][1]);
};
this.OutScreen = () => {
var F = this.G(window);
var x = window.getX(),
y = window.getY();
var sx = window.getX() + window.getWidth() / 2,
sy = window.getY() + window.getHeight() / 2 + 66;
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,
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()));
return [
[x, y],
[cx, cy]
];
};
this.toScreenEdge = (d) => {
d = d || 0;
var F = this.G(window);
var x = window.getX(),
y = window.getY();
var sw = window.getWidth() * d;
var sx = window.getX() + window.getWidth() / 2,
sy = window.getY() + window.getHeight() / 2 + 66;
var cx = sx < (this.Width - sx) ? -sw : (this.Width + sw - window.getWidth());
return [
[x, y],
[cx, y]
];
};
this.centerXY = (F) => {
var w = window.getWidth();
var h = window.getHeight();
return [
[F[0] + w / 2, F[1] + h / 2],
[F[0] - w / 2, F[1] - h / 2]
];
};
this.autoIntScreen = () => {
var A = this.windowGXY(window.getX(), window.getY(), this.G(window));
threads.start(new java.lang.Runnable(() => {
this.windowyidong([
[window.getX(), window.getY()],
[A.x, A.y]
]);
}));
};
this.autoIntScreen();
};
common.闪光弹 = function (content, x, y, color, t) {
var single = (function () {
var unique;
function getInstance() {
if (unique === undefined) {
unique = new Flash();
}
return unique;
}
return {
getInstance: getInstance
}
})();
function Flash() {}
Flash.prototype.update = function (content, x, y, color, t) {
this.content = content || '未传入参数'
this.x = x || random(100, 300)
this.y = y || random(100, 900)
this.color = color || -2278181
this.t = t || 2000
}
Flash.prototype.show = function () {
var window = floaty.rawWindow( <card cardBackgroundColor = "#aa00FF00"
cardCornerRadius = "18dp" >
<text id = "text"
size = "30dp"
layout_width = "wrap_content"
layout_height = "wrap_content"
layout_gravity = "center"
gravity = "center"
paddingLeft = "10"
paddingRight = "10"
paddingTop = "10"
paddingBottom = "10" > 123 </text> </card>
);
window.text.setText(this.content);
window.text.setBackgroundColor(this.color);
window.setPosition(this.x, this.y);
setTimeout(() => {
window.close();
}, this.t);
}
function flash(content, x, y, color, t) {
var content = content.toString()
var f = single.getInstance()
f.update(content, x, y, color, t)
f.show()
}
var color = color || colors.rgb(random(0, 255), random(0, 255), random(0, 255))
flash(content, x, y, color, t);
// flash('hello world')
// flash('Are you ok?')
// flash('我很好')
// flash('you are beautiful')
}
common.打开开发者选项 = function () {
app.startActivity({
action: "android.intent.action.VIEW", //此处可为其他值
packageName: "com.android.settings",
className: "com.android.settings.Settings$DevelopmentSettingsActivity"
//此处可以加入其他内容,如data、extras
});
}
common.气泡 = function (msg, x, y) {
function toastAt0(msg, x, y) {
importClass(android.widget.Toast);
importClass(android.view.Gravity);
var toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP | Gravity.LEFT, x, y);
toast.show();
}
var x = x || device.width / 3
var y = y || device.height / 5 * 4
var msg = msg.toString()
ui.run(() => toastAt0(msg, x, y));
sleep(2000)
// toastAt('sdfsfdsdfs',300,300)
}
common.随机字符串 = function (PassLength) {
var PassLength = PassLength || 8
var str = 'abcdefghijklmnopqrstuvwxyz';
var STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var num = '0123456789';
var sym = '+=-@#~,.[]()!%^*$';
var text = str.split('').concat(STR.split(''))
var pw = '';
for (i = 0; i < PassLength; i++) {
var strpos = random(0, text.length - 1);
pw += text[strpos].charAt(random(0, text[strpos].length - 1));
}
return pw;
}
common.wifi状态 = function () {
importPackage(android.content);
let wifiManager = context.getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
log('wifi is opend')
return 'open'
} else {
log('wifi is closed')
return 'close'
}
}
common.开关飞行模式 = function (开关) {
// 0 关闭 1开启 默认开启飞行模式
var 开关 = 开关 || 1
function 打开飞行模式() {
// 打开飞行模式
new Shell().exec("su -c 'settings put global airplane_mode_on 1; am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true'")
}
function 关闭飞行模式() {
//关闭飞行模式
new Shell().exec("su -c 'settings put global airplane_mode_on 0; am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false'")
}
if (开关 == 1) {
打开飞行模式()
} else {
关闭飞行模式()
}
}
common.上滑 = function () {
var randomP = random(500, 600);
var points = [randomP];
var interval = 0.1;
var x0 = random(780, 900);
var y0 = random(1500, 1600);
var a = 240;
for (var t = 0; t < Math.PI / 2; t += interval) {
var x = x0 - a * (1.8 * Math.cos(t * 0.9) - Math.cos(2 * t * 0.9));
var y = y0 - a * (5 * Math.sin(t * 0.9) - Math.sin(2 * t * 0.9));
points.push([parseInt(x), parseInt(y)]);
}
gesture.apply(null, points);
sleep(1500);
}
common.获取deflate网页内容 = function (url,headers) {
importClass('java.io.BufferedReader');
importClass('java.io.InputStreamReader');
importClass("java.util.zip.InflaterInputStream")
importClass('java.io.ByteArrayInputStream');
importClass("java.util.zip.Inflater")
var res = http.get(
url, {
headers: headers
})
log("statusCode = " + res.statusCode);
var deflateFileContent = res.body.bytes()
var 网页内容 = null;
if (deflateFileContent) {
var br = new BufferedReader(new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(deflateFileContent), new Inflater(true))));
var lns = [],
cl;
while (cl = br.readLine()) lns.push(cl);
网页内容 = lns.join("\n")
// log('网页内容')
// log(网页内容)
return 网页内容
} else {
console.error('下载失败')
exit()
}
return false
}
common.获取gzip网页内容 = function (url,form,headers,method) {
var method=method || 'get'
var headers=headers || {}
function 保存zip文件(zipFile) {
var path = files.join(files.cwd(), "1下载bilibili弹幕专用/webPage.gzip.js")
files.createWithDirs(path)
log("path=", path)
// path= /storage/emulated/0/脚本/zip文件专用/test.zip
files.writeBytes(path, zipFile)
var r = 解压zip文件(path)
log(r)
return r
}
function 解压zip文件(文件路径) {
//同一目录下的同一文件名
// unzipGzipFile(sourceGzipFilePath, targetPath)
var fileName = files.getName(文件路径)
var 解压后的文件路径 = 文件路径.replace(fileName, 'webPage.js')
log('解压的解压后的文件路径=', 解压后的文件路径)
files.createWithDirs(解压后的文件路径)
// com.stardust.io.Zip.unzip(new java.io.File(文件路径), new java.io.File(解压后的文件路径))
var sourceGzipFilePath = 文件路径
var targetPath = 解压后的文件路径
unzipGzipFile(sourceGzipFilePath, targetPath)
return targetPath
}
function unzipGzipFile(sourceGzipFilePath, targetPath) {
importClass(java.io.FileInputStream);
importClass(java.util.zip.GZIPInputStream);
importClass('java.io.FileOutputStream');
var sourceGzipFilePath = sourceGzipFilePath || '/sdcard/tempSourceGzipFilePath.js'
var targetPath = targetPath || '/sdcard/tempTargetPath.js'
log('sourceGzipFilePath')
log(sourceGzipFilePath)
log('targetPath')
log(targetPath)
var sChunk = 8192;
var gzipFileInputStream = new FileInputStream(sourceGzipFilePath);
var zipin = new GZIPInputStream(gzipFileInputStream);
var buffer = util.java.array('byte', sChunk)
var out = new FileOutputStream(targetPath);
var length;
while ((length = zipin.read(buffer, 0, sChunk)) != -1)
out.write(buffer, 0, length);
out.close();
zipin.close();
}
var res=null;
if(method=='get'){
res = http.get(
url, {
headers: headers
})
}else if(method=='post'){
res = http.post(
url, form, {
headers: headers
})
}else{
alert('请自行添加get post 之外的方法')
exit()
}
log("statusCode = " + res.statusCode);
var gzipFileContent = res.body.bytes()
var 网页内容 = null;
if (gzipFileContent) {
var 网页保存路径 = 保存zip文件(gzipFileContent)
网页内容 = files.read(网页保存路径)
// log('网页内容')
// log(网页内容)
return 网页内容
} else {
console.error('下载失败')
exit()
}
return false
}
common.发送通知=function (){
var manager = context.getSystemService(android.app.Service.NOTIFICATION_SERVICE);
var notification;
if (device.sdkInt >= 26) {
var channel = new android.app.NotificationChannel("channel_id", "channel_name", android.app.NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(0xff0000);
channel.setShowBadge(false);
manager.createNotificationChannel(channel);
notification = new android.app.Notification.Builder(context, "channel_id")
.setContentTitle("通知栏标题"+new date())
.setContentText("这是消息的内容")
.setWhen(new Date().getTime())
.setSmallIcon(org.autojs.autojs.R.drawable.autojs_material)
.setTicker("这是状态栏显示的内容")
.build();
} else {
notification = new android.app.Notification.Builder(context)
.setContentTitle("通知栏标题")
.setContentText("这是消息的内容")
.setWhen(new Date().getTime())
.setSmallIcon(org.autojs.autojs.R.drawable.autojs_material)
.setTicker("这是状态栏显示的内容")
.build();
}
manager.notify(1, notification);
}
common.去除通知=function (){
var manager = context.getSystemService(android.app.Service.NOTIFICATION_SERVICE);
manager.cancelAll();
// manager.cancel(1);
}
common.获取拼音=function (src){
var path=common.确保有jar文件('pinyin4j')
runtime.loadJar(path)
importClass(net.sourceforge.pinyin4j.PinyinHelper);
importClass(net.sourceforge.pinyin4j.format.HanyuPinyinCaseType);
importClass(net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat);
importClass(net.sourceforge.pinyin4j.format.HanyuPinyinToneType);
importClass(net.sourceforge.pinyin4j.format.HanyuPinyinVCharType);
importClass(net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination);
importClass(java.io.UnsupportedEncodingException);
var src = new java.lang.String(src)
var hz = null;
hz = src.toCharArray(); //该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符
var py = new Array(hz.length); //该数组用来存储
//设置汉子拼音输出的格式
var format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
var pys = ""; //存放拼音字符串
var len = hz.length;
try {
for (var i = 0; i < len; i++) {
//先判断是否为汉字字符
if ((java.lang.Character.toString(hz[i])).match(/[\u4e00-\u9fa5]+/)) {
//将汉字的几种全拼都存到py数组中
py = PinyinHelper.toHanyuPinyinStringArray(hz[i], format);
//取出改汉字全拼的第一种读音,并存放到字符串pys后
pys += py[0];
} else {
//如果不是汉字字符,间接取出字符并连接到 pys 后
pys += java.lang.Character.toString(hz[i]);
}
}
} catch (e) {
log(e)
log(e.stack)
}
return pys;
}
common.clickAttr = function (attr, value, 找控件默认超时时间) {
var 找控件默认超时时间 = 找控件默认超时时间 || 10000
var view;
switch (attr) {
case 'id':
view = id(value).findOne(找控件默认超时时间)
break;
case 'text':
view = text(value).findOne(找控件默认超时时间)
break;
case 'desc':
view = desc(value).findOne(找控件默认超时时间)
break;
default:
alert('没有这个属性')
exit()
}
if (view) {
view.click()
return true
} else {
return false
}
}
common.pressAttr = function (attr, value, 找控件默认超时时间) {
var 找控件默认超时时间 = 找控件默认超时时间 || 10000
var view;
switch (attr) {
case 'id':
view = id(value).findOne(找控件默认超时时间)
break;
case 'text':
view = text(value).findOne(找控件默认超时时间)
break;
case 'desc':
view = desc(value).findOne(找控件默认超时时间)
break;
default:
alert('没有这个属性')
exit()
}
if (view) {
common.点击控件(view)
return true
} else {
return false
}
}
/**
* @功能 在qq消息周围画个框
* @作者 家
* @QQ 刷勋章被封了一天,203118908
*/
common.画出控件区域=function (view,duration){
var window, paint, bitmap, bitmapCanvas;
var duration=duration || 2000
function 创建悬浮窗() {
window = floaty.rawWindow( <canvas id = "board"
h = "{{device.height}}"
w = "{{device.width}}" />
);
// setInterval(() => {}, 3000)
window.setSize(device.width, device.height)
window.setTouchable(false);
// window.setPosition(0, 110)
// var bitmap = android.graphics.Bitmap.createBitmap(1080, 1920, android.graphics.Bitmap.Config.ARGB_8888);
bitmap = android.graphics.Bitmap.createBitmap(device.width, device.height, android.graphics.Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
paint = new Paint()
paint.setStrokeWidth(10);
var color = '#00ff00'
color = colors.parseColor(color)
paint.setColor(color)
paint.setStyle(Paint.Style.STROKE);
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(35);
window.board.on("draw", function (canvas) {
canvas.drawBitmap(bitmap, 0, 0, paint);
});
}
function showView(view) {
创建悬浮窗()
var bounds = view.bounds()
var left = bounds.left
var top = bounds.top
var right = bounds.right
var bottom = bounds.bottom
if (left > right) {
left = device.width / 3
right = device.width / 3 * 2
}
log(left, top, right, bottom)
var originalStrokeWidth = paint.getStrokeWidth()
var originalColor = paint.getColor()
var rndColor = getRndColor()
var color = colors.parseColor(rndColor)
paint.setColor(color)
paint.setStrokeWidth(20)
画矩形(left, top, right, bottom)
paint.setColor(originalColor)
paint.setStrokeWidth(originalStrokeWidth)
}
function 画矩形(left, top, right, bottom) {
bitmapCanvas.drawRect(left, top, right, bottom, paint)
}
function getRndColor() {
var a, r, g, b;
a = Math.floor(0), r = Math.floor(随机0_255()), g = Math.floor(随机0_255()), b = Math.floor(随机0_255());
// var 反色 = -1 - colors.argb(0, r, g, b);
var color = colors.argb(0, r, g, b);
color = colors.toString(color)
log(color)
return color
}
function 随机0_255() {
var r = parseInt(255 * Math.random())
return r
}
showView(view)
sleep(duration)
}
common.获取多开分身右侧字母区域控件=function (){
// 默认找10次,每次延迟一秒
var 查找次数=查找次数 || 10
//右侧字母框的特征, 就是长,细
// 长 高度的0.739
// 细 宽度的0.066
// 左上角 0.933 0.186
var width = device.width
var height = device.height
var 字母控件=false;
for(let i=0;i<查找次数;i++){
var 右侧字母区查找结果 = className('android.view.View').boundsInside(width * 0.9, height * 0.1, device.width, device.height * 0.95).filter(
function (view) {
var bounds = view.bounds()
var w = bounds.width()
var h = bounds.height()
if (w < width * 0.1 && w > width * 0.03 && h < height * 0.8 && h > height * 0.7) {
return true
} else {
return false
}
}
).find()
if(右侧字母区查找结果.length>0){
字母控件=右侧字母区查找结果[0]
break;
}
sleep(1000)
}
if(!字母控件){alert('没有找到多开分身右侧字母控件');exit()}
return 字母控件
}
common.画矩形=function (left,top,right,bottom,duration){
var window, paint, bitmap, bitmapCanvas;
var duration=duration || 2000
function 创建悬浮窗() {
window = floaty.rawWindow( <canvas id = "board"
h = "{{device.height}}"
w = "{{device.width}}" />
);
// setInterval(() => {}, 3000)
window.setSize(device.width, device.height)
window.setTouchable(false);
// window.setPosition(0, 110)
// var bitmap = android.graphics.Bitmap.createBitmap(1080, 1920, android.graphics.Bitmap.Config.ARGB_8888);
bitmap = android.graphics.Bitmap.createBitmap(device.width, device.height, android.graphics.Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
paint = new Paint()
paint.setStrokeWidth(10);
var color = '#00ff00'
color = colors.parseColor(color)
paint.setColor(color)
paint.setStyle(Paint.Style.STROKE);
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(35);
window.board.on("draw", function (canvas) {
canvas.drawBitmap(bitmap, 0, 0, paint);
});
}
function showView(left,top,right,bottom) {
创建悬浮窗()
if (left > right) {
left = device.width / 3
right = device.width / 3 * 2
}
log(left, top, right, bottom)
var originalStrokeWidth = paint.getStrokeWidth()
var originalColor = paint.getColor()
var rndColor = getRndColor()
var color = colors.parseColor(rndColor)
paint.setColor(color)
paint.setStrokeWidth(20)
画矩形(left, top, right, bottom)
paint.setColor(originalColor)
paint.setStrokeWidth(originalStrokeWidth)
}
function 画矩形(left, top, right, bottom) {
bitmapCanvas.drawRect(left, top, right, bottom, paint)
}
function getRndColor() {
var a, r, g, b;
a = Math.floor(0), r = Math.floor(随机0_255()), g = Math.floor(随机0_255()), b = Math.floor(随机0_255());
// var 反色 = -1 - colors.argb(0, r, g, b);
var color = colors.argb(0, r, g, b);
color = colors.toString(color)
log(color)
return color
}
function 随机0_255() {
var r = parseInt(255 * Math.random())
return r
}
showView(left,top,right,bottom)
sleep(duration)
}
common.画点=function (x,y,r,duration){
var r=r || 6;
var window, paint, bitmap, bitmapCanvas;
var duration=duration || 2000
function 创建悬浮窗() {
window = floaty.rawWindow( <canvas id = "board"
h = "{{device.height}}"
w = "{{device.width}}" />
);
// setInterval(() => {}, 3000)
window.setSize(device.width, device.height)
window.setTouchable(false);
// window.setPosition(0, 110)
// var bitmap = android.graphics.Bitmap.createBitmap(1080, 1920, android.graphics.Bitmap.Config.ARGB_8888);
bitmap = android.graphics.Bitmap.createBitmap(device.width, device.height, android.graphics.Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
paint = new Paint()
paint.setStrokeWidth(10);
var color = '#00ff00'
color = colors.parseColor(color)
paint.setColor(color)
paint.setStyle(Paint.Style.STROKE);
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(35);
window.board.on("draw", function (canvas) {
canvas.drawBitmap(bitmap, 0, 0, paint);
});
}
function showView(x,y,r) {
创建悬浮窗()
var originalStrokeWidth = paint.getStrokeWidth()
var originalColor = paint.getColor()
var rndColor = getRndColor()
var color = colors.parseColor(rndColor)
paint.setColor(color)
paint.setStrokeWidth(20)
画点(x,y,r)
paint.setColor(originalColor)
paint.setStrokeWidth(originalStrokeWidth)
}
function 画点(x,y,r) {
bitmapCanvas.drawCircle(x,y,r,paint)
}
function getRndColor() {
var a, r, g, b;
a = Math.floor(0), r = Math.floor(随机0_255()), g = Math.floor(随机0_255()), b = Math.floor(随机0_255());
// var 反色 = -1 - colors.argb(0, r, g, b);
var color = colors.argb(0, r, g, b);
color = colors.toString(color)
log(color)
return color
}
function 随机0_255() {
var r = parseInt(255 * Math.random())
return r
}
showView(x,y,r)
sleep(duration)
}
//去除头尾空格
common.strip = function (str) {
log(arguments.callee.name + '开始')
var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
for (var i = 0, len = str.length; i < len; i++) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(i);
break;
}
}
for (i = str.length - 1; i >= 0; i--) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(0, i + 1);
break;
}
}
log(arguments.callee.name + '结束')
return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
common.大数组包含小数组 = function (bigArr, smallArr) {
//对于重复的元素采用计数的方式对比
var bigArrObj = {}
var smallArrObj = {}
for (let i = 0; i < bigArr.length; i++) {
var has = bigArrObj.hasOwnProperty(bigArr[i])
if (has) {
bigArrObj[bigArr[i]]++;
} else {
bigArrObj[bigArr[i]] = 1
}
}
for (let i = 0; i < smallArr.length; i++) {
var has = smallArrObj.hasOwnProperty(smallArr[i])
if (has) {
smallArrObj[smallArr[i]]++;
} else {
smallArrObj[smallArr[i]] = 1
}
}
for (var k in smallArrObj) {
if (bigArrObj.hasOwnProperty(k) && bigArrObj[k] >= smallArrObj[k]) {} else {
return false
}
}
return true
}
common.getObjType = function (obj) {
// JavaScript 标准文档中定义: [[Class]] 的值只可能是下面字符串中的一个: Arguments, Array, Boolean, Date, Error, Function, JSON, Math, Number, Object, RegExp, String.
var result = Object.prototype.toString.call(obj)
result=result.match(/ \w+/)[0]
result=result.replace(/ /g,'')
return result
}
common.deepCopy=function (obj) {
if (typeof obj != 'object') {
return obj;
}
var newobj = {};
for (var attr in obj) {
newobj[attr] = deepCopy(obj[attr]);
}
return newobj;
};
common.反色=function (color) {
return (-1 - colors.argb(0, colors.red(color), colors.green(color), colors.blue(color)));
};
common.指定特征的控件是否存在=function (propFeature, searchCount, intervalTime) {
var searchCount = searchCount || 3
var intervalTime = intervalTime || 1000
//propFeature是一个json格式
//desc,text,id,boundsInside,bounds,boundsContains
if (!(getObjType(propFeature) == "Object")) {
log('你传入的propFeature是')
log(propFeature)
log('propFeature--控件特征描述是一个对象,正确的对象例子')
var obj = {
k1: "v1",
k2: "v2",
k3: "v3"
}
log(JSON.stringify(obj))
throw '请传入一个对象'
}
var propFeature = propFeature || {}
var mySelector = ""
for (var k in propFeature) {
if (k == "boundsInside" || k == "bounds" || k == "boundsContains") {
mySelector += k + "(" + propFeature[k][0] + "," + propFeature[k][1] + "," + propFeature[k][2] + "," + propFeature[k][3] + ")."
continue;
}
mySelector += k + "(\"" + propFeature[k] + "\")."
}
mySelector += 'findOnce()'
for (var i = 0; i < searchCount; i++) {
// log('查找第%d次',i)
var searchResult = eval(mySelector)
if (searchResult) {
return searchResult
}
sleep(intervalTime)
}
return false
}
common.bmob上传文件 = function (url, path, appId, restKey) {
// 注意:url尾部必须带后缀名,后缀名随意
// 使用例子
// var url = "https://api2.bmob.cn/2/files/pinyin4j.jar"
// // var path = "/storage/emulated/0/pinyin4j.jar"
// var path = files.join(files.getSdcardPath(), "/pinyin4j.jar")
// log('path=', path)
// log(files.exists(path))
// // exit()
// bomb上传文件Stream(url, path)
var config = {
appId: appId,
restKey: restKey
}
importClass("java.io.IOException")
importClass("java.util.HashMap")
importClass(java.io.FileInputStream);
importClass(java.util.zip.GZIPInputStream);
importClass("java.util.ArrayList")
importClass("java.io.DataInputStream");
importClass("java.io.DataOutputStream");
importClass("java.io.OutputStreamWriter");
importClass("java.io.BufferedWriter");
importClass('java.io.BufferedReader');
importClass('java.io.IOException');
importClass('java.io.InputStream');
importClass('java.io.InputStreamReader');
importClass('java.io.OutputStream');
importClass('java.io.BufferedOutputStream');
importClass('java.io.ByteArrayInputStream');
importClass('java.io.BufferedInputStream');
importClass('java.io.ByteArrayOutputStream');
importClass('java.io.PrintWriter');
importClass('java.io.FileOutputStream');
importClass('java.lang.StringBuffer');
importClass('java.io.File');
importClass('java.net.Socket');
importClass('java.net.UnknownHostException');
importClass("java.util.zip.CRC32")
importClass("java.util.zip.CheckedOutputStream")
importClass("java.util.zip.ZipEntry")
importClass("java.util.zip.ZipOutputStream")
importClass("java.util.zip.ZipFile")
importClass("java.util.zip.InflaterInputStream")
importClass("java.util.zip.Inflater")
importClass("java.net.HttpURLConnection");
importClass("java.net.URL");
//创建URL对象,xxx是服务器API
var url = new URL(url);
//调用URL对象的openConnection( )来获取HttpURLConnection对象实例
var conn = url.openConnection();
//请求方法为GET
conn.setRequestMethod("POST");
//设置连接超时为5秒
conn.setConnectTimeout(5000);
//允许输入输出
conn.setDoInput(true);
conn.setDoOutput(true);
//不能缓存
conn.setUseCaches(false);
//至少要设置的两个请求头
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestProperty("X-Bmob-Application-Id", config.appId);
conn.setRequestProperty("X-Bmob-REST-API-Key", config.restKey);
//输出流包含要发送的数据,要注意数据格式编码
var op = conn.getOutputStream();
op.write(文件流(path));
// op.write(new String("name=zhylioooo").getBytes());
//服务器返回东西了,先对响应码判断
//用getInputStream()方法获得服务器返回的输入流
var info = conn.getInputStream();
var html = getStreamString(info); //流转换为二进制数组,read()是转换方法
// html = new String(data, "UTF-8");
log(html);
info.close();
if (conn.getResponseCode() == 200) {
return html
} else {
return false
}
function 文件流(path) {
// importClass('java.io.FileInputStream');
var fileForInput = new FileInputStream(path)
var length = fileForInput.available()
var bytes = util.java.array('byte', length)
fileForInput.read(bytes);
fileForInput.close();
return bytes
}
function getStreamString(tInputStream) {  
if (tInputStream != null) {  
var tBufferedReader = new BufferedReader(new InputStreamReader(tInputStream));  
var tStringBuffer = new StringBuffer();  
var sTempOneLine = new String("");  
while ((sTempOneLine = tBufferedReader.readLine()) != null) {  
tStringBuffer.append(sTempOneLine);  
}  
return tStringBuffer.toString();  
}  
return null;
}
}
/**
* 真人模拟滑动函数
*
* 传入值:起点终点坐标
* 效果:模拟真人滑动
*/
common.模拟真人滑动 = function (sx, sy, ex, ey) {
function bezierCreate(x1, y1, x2, y2, x3, y3, x4, y4) {
//构建参数
var h = 100;
var cp = [{
x: x1,
y: y1 + h
}, {
x: x2,
y: y2 + h
}, {
x: x3,
y: y3 + h
}, {
x: x4,
y: y4 + h
}];
var numberOfPoints = 100;
var curve = [];
var dt = 1.0 / (numberOfPoints - 1);
//计算轨迹
for (var i = 0; i < numberOfPoints; i++) {
var ax, bx, cx;
var ay, by, cy;
var tSquared, tCubed;
var result_x, result_y;
cx = 3.0 * (cp[1].x - cp[0].x);
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
ax = cp[3].x - cp[0].x - cx - bx;
cy = 3.0 * (cp[1].y - cp[0].y);
by = 3.0 * (cp[2].y - cp[1].y) - cy;
ay = cp[3].y - cp[0].y - cy - by;
var t = dt * i
tSquared = t * t;
tCubed = tSquared * t;
result_x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
result_y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
curve[i] = {
x: result_x,
y: result_y
};
}
//轨迹转路数组
var array = [];
for (var i = 0; i < curve.length; i++) {
try {
var j = (i < 100) ? i : (199 - i);
xx = parseInt(curve[j].x)
yy = parseInt(Math.abs(100 - curve[j].y))
} catch (e) {
break
}
array.push([xx, yy])
}
return array
}
//设置随机滑动时长范围
var timeMin = 1000
var timeMax = 3000
//设置控制点极限距离
var leaveHeightLength = 500
//根据偏差距离,应用不同的随机方式
if (Math.abs(ex - sx) > Math.abs(ey - sy)) {
var my = (sy + ey) / 2
var y2 = my + random(0, leaveHeightLength)
var y3 = my - random(0, leaveHeightLength)
var lx = (sx - ex) / 3
if (lx < 0) {
lx = -lx
}
var x2 = sx + lx / 2 + random(0, lx)
var x3 = sx + lx + lx / 2 + random(0, lx)
} else {
var mx = (sx + ex) / 2
var y2 = mx + random(0, leaveHeightLength)
var y3 = mx - random(0, leaveHeightLength)
var ly = (sy - ey) / 3
if (ly < 0) {
ly = -ly
}
var y2 = sy + ly / 2 + random(0, ly)
var y3 = sy + ly + ly / 2 + random(0, ly)
}
//获取运行轨迹,及参数
var time = [0, random(timeMin, timeMax)]
var track = bezierCreate(sx, sy, x2, y2, x3, y3, ex, ey)
log("随机控制点A坐标:" + x2 + "," + y2)
log("随机控制点B坐标:" + x3 + "," + y3)
log("随机滑动时长:" + time[1])
//滑动
gestures(time.concat(track))
}
common.过微信QQ滑块 = function (){
var y = 1058//设置滑动按钮高度
/**
*脚本来源:浩然
*QQ:2125764918
*b站UID:275511084
*
*适用版本:所有安卓版本
*适用分辨率:1080p720p
*
*转载请附注来源,谢谢
*成功率实测百次:成功率100%
*
*防检测功能:模拟真人滑动
*通过四阶贝塞尔曲线,生成完全模仿真的滑动方式
*
*/
//显示控制台
console.show()
console.setPosition(100, 1300)
//请求权限
if (!requestScreenCapture()) {
alert("请求截图权限失败!");
exit();
}
//启动
start()
/**
* 识别滑块位置
*
* 传入值img,ratio
* img为要识别的图片
* ratio为识别图片的分辨率(暂时只可选择720或1080)
*
* 返回值x
* 识别出方块位置的左端横坐标
*/
function discernSlidingblock(img, ratio) {
//创建识别变量
var temp, temp2, x, y, num, color, p, temp3, arr1;
//分析设备分辨率
if (ratio == 720) {
var tb = [348, 253, 691, 638, 81]
log("您的设备分辨率为:720p");
} else if (ratio == 1080) {
var tb = [463, 387, 912, 831, 125]
log("您的设备分辨率为:1080p");
} else {
log("当前设备分辨率不符合规范")
return -2
}
num = Math.ceil(tb[4] / 3.3 - 4);
//计算滑块位置
for (var k = 29; k <= 40; k++) {
temp2 = "";
color = "#" + k + "" + k + "" + k + "";
for (var i = 1; i <= num; i++) {
temp2 = temp2 + "0|" + i + "|" + color + ",";
temp2 = temp2 + i + "|0|" + color + ",";
temp2 = temp2 + "1|" + i + "|" + color + ",";
temp2 = temp2 + i + "|1|" + color + ",";
temp2 = temp2 + "2|" + i + "|" + color + ",";
temp2 = temp2 + i + "|2|" + color + ",";
}
x = 0;
while (x > -2) {
y = 0;
while (y > -2) {
temp = "";
for (var i = 1; i <= num; i += 2) {
temp = temp + "0|" + (tb[4] + y - i - 1) + "|" + color + ",";
temp = temp + (tb[4] + x) + "|" + i + "|" + color + ",";
temp = temp + (tb[4] + x) + "|" + (tb[4] + y - i - 1) + "|" + color + ",";
temp = temp + (tb[4] + x - i - 1) + "|0|" + color + ",";
temp = temp + i + "|" + (tb[4] + y) + "|" + color + ",";
temp = temp + (tb[4] + x - i - 1) + "|" + (tb[4] + y) + "|" + color + ",";
temp = temp + "1|" + (tb[4] + y - i - 1) + "|" + color + ",";
temp = temp + (tb[4] + x - 1) + "|" + i + "|" + color + ",";
temp = temp + (tb[4] + x - 1) + "|" + (tb[4] + y - i - 1) + "|" + color + ",";
temp = temp + (tb[4] + x - i - 1) + "|1|" + color + ",";
temp = temp + i + "|" + (tb[4] + y - 1) + "|" + color + ",";
temp = temp + (tb[4] + x - i - 1) + "|" + (tb[4] + y - 1) + "|" + color + ",";
}
temp = temp + temp2 + "0|0|" + color;
arr1 = temp.split(",");
var arr2 = new Array();
for (var i = 0; i < arr1.length - 1; i++) {
arr2[i] = new Array();
temp3 = arr1[i].split("|");
arr2[i] = [Number(temp3[0]), Number(temp3[1]), temp3[2]];
}
try {
p = images.findMultiColors(img, color, arr2, {
region: [tb[0], tb[1], tb[2] - tb[0], tb[3] - tb[1]],
threshold: (Math.floor(k / 10) * 16 + k % 10)
});
if (p) {
img.recycle();
return p.x
}
} catch (error) {
//出错
console.log("识别失败,错误原因:" + error);
return -1;
}
y = --y;
}
x = --x;
}
}
try {
img.recycle();
} catch (error) {
console.log("识别失败,错误原因:" + error);
}
return -1;
}
function start() {
auto.waitFor()
for(var i=0;i<0;i++){sleep(1000);log(i);}
while (true) {
img = images.captureScreen();
if (img) {
log("截图成功。进行识别滑块!");
break;
} else {
log('截图失败,重新截图');
}
}
var x = discernSlidingblock(img, device.width) + 65
console.info("识别结果滑块X坐标:" + x);
if (x > -1) {
randomSwipe(220, y, x, y)
//滑动完成
} else {
console.log("识别有误,请确认是否在滑块界面");
}
}
function bezierCreate(x1,y1,x2,y2,x3,y3,x4,y4){
//构建参数
var h=100;
var cp=[{x:x1,y:y1+h},{x:x2,y:y2+h},{x:x3,y:y3+h},{x:x4,y:y4+h}];
var numberOfPoints = 100;
var curve = [];
var dt = 1.0 / (numberOfPoints - 1);
//计算轨迹
for (var i = 0; i < numberOfPoints; i++){
var ax, bx, cx;
var ay, by, cy;
var tSquared, tCubed;
var result_x, result_y;
cx = 3.0 * (cp[1].x - cp[0].x);
bx = 3.0 * (cp[2].x - cp[1].x) - cx;
ax = cp[3].x - cp[0].x - cx - bx;
cy = 3.0 * (cp[1].y - cp[0].y);
by = 3.0 * (cp[2].y - cp[1].y) - cy;
ay = cp[3].y - cp[0].y - cy - by;
var t=dt*i
tSquared = t * t;
tCubed = tSquared * t;
result_x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
result_y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
curve[i] = {
x: result_x,
y: result_y
};
}
//轨迹转路数组
var array=[];
for (var i = 0;i<curve.length; i++) {
try {
var j = (i < 100) ? i : (199 - i);
xx = parseInt(curve[j].x)
yy = parseInt(Math.abs(100 - curve[j].y))
} catch (e) {
break
}
array.push([xx, yy])
}
return array
}
/**
* 真人模拟滑动函数
*
* 传入值:起点终点坐标
* 效果:模拟真人滑动
*/
function randomSwipe(sx,sy,ex,ey){
//设置随机滑动时长范围
var timeMin=1000
var timeMax=3000
//设置控制点极限距离
var leaveHeightLength=500
//根据偏差距离,应用不同的随机方式
if(Math.abs(ex-sx)>Math.abs(ey-sy)){
var my=(sy+ey)/2
var y2=my+random(0,leaveHeightLength)
var y3=my-random(0,leaveHeightLength)
var lx=(sx-ex)/3
if(lx<0){lx=-lx}
var x2=sx+lx/2+random(0,lx)
var x3=sx+lx+lx/2+random(0,lx)
}else{
var mx=(sx+ex)/2
var y2=mx+random(0,leaveHeightLength)
var y3=mx-random(0,leaveHeightLength)
var ly=(sy-ey)/3
if(ly<0){ly=-ly}
var y2=sy+ly/2+random(0,ly)
var y3=sy+ly+ly/2+random(0,ly)
}
//获取运行轨迹,及参数
var time=[0,random(timeMin,timeMax)]
var track=bezierCreate(sx,sy,x2,y2,x3,y3,ex,ey)
log("随机控制点A坐标:"+x2+","+y2)
log("随机控制点B坐标:"+x3+","+y3)
log("随机滑动时长:"+time[1])
//滑动
gestures(time.concat(track))
}
}
common.bmob下载文件 = function (url,path){
// var fileName='pinyin4j.jar'
// var path=files.join(files.getSdcardPath(), "/jar/",fileName)
// log(path)
// /storage/emulated/0/jar/pinyin4j.jar
// var url="http://bmob-cdn-11368.b0.upaiyun.com/2019/03/01/9a8b935d40dfd2bb80e5eb964c168b0a.jar"
var r = http.get(url);
log("code = " + r.statusCode);
files.writeBytes(path,r.body.bytes())
log('bmom下载文件完毕'+path)
}
common.确保有jar文件 = function (jarFileName){
// 确保有jar文件("pinyin4j")
var jsoupUrl="http://bmob-cdn-11368.b0.upaiyun.com/2019/03/01/33dd4f2f40b9a65980765ec28535c906.jar"
var pinyin4jUrl="http://bmob-cdn-11368.b0.upaiyun.com/2019/03/01/ef62e76940139d50808131442e9bc1fc.jar"
var webViewClassesDexUrl="http://bmob-cdn-11368.b0.upaiyun.com/2019/03/12/d7732a7f40429bd3809acbfbc0e991a4.dex"
var sdPath=files.getSdcardPath()
var path = files.join(sdPath, "/autojsLib/",jarFileName+".jar")
files.ensureDir(path)
var r=files.exists(path)
if(r){
return path;
}else{
switch(jarFileName)
{
case 'jsoup':
common.bmob下载文件(jsoupUrl,path)
break;
case 'pinyin4j':
common.bmob下载文件(pinyin4jUrl,path)
break;
case 'webViewClasses.dex':
var path = files.join(sdPath, "/autojsLib/",jarFileName)
files.ensureDir(path)
common.bmob下载文件(webViewClassesDexUrl,path)
break;
default:
toastLog('没加这个jar,你自己加吧==>>'+jarFileName)
alert('没加这个jar,你自己加吧==>>'+jarFileName)
exit()
}
}
return path;
}
common.获取QQ收藏内容=function(url){
/**
* 作者: 家
* Q Q: 203118908
* 时间: 20190204
* 功能: 提取QQ收藏的完整内容,保留原文本格式
* 注意: 需要将jsoup放到/sdcard/jsoup.jar
* 注意: jsoup第一次加载需要几秒钟,之后就很快
*/
var jarFileName="jsoup"
common.确保有jar文件(jarFileName)
var sdPath=files.getSdcardPath()
var path = files.join(sdPath, "/autojsLib/",jarFileName+".jar")
runtime.loadJar(path)
importClass("org.jsoup.Jsoup")
importClass("java.io.IOException")
importClass("java.util.HashMap")
importClass("org.jsoup.Jsoup")
importClass("org.jsoup.nodes.Document")
importClass("org.jsoup.nodes.Element")
importClass("org.jsoup.select.Elements")
// var url = "https://sharechain.qq.com/b9084714857c5d5bb2a2ef4d775f4e24";
var r = http.get(url, {
headers: {
'Accept-Language': 'zh-cn,zh;q=0.5',
'User-Agent': 'Mozilla/5.0(Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11'
}
});
var result = r.body.string()
// result = result.match(/window.syncData.*?script/)
result = result.match(/<script type="text\/javascript">window.syncData.*?<\/script>/)
result = result[0]
result = result.match(/window.syncData = {.*}/)
result = result[0]
result = result.replace("window.syncData = ", '')
result = result.replace(/(\\n|\\u003Cbr \/>)/g, '这个一会要换成换行符')
//
result = JSON.parse(result)
result = result.shareData
result = result.html_content
var doc = Jsoup.parseBodyFragment(result);
var body = doc.body();
result = Jsoup.parse(body).text()
result = result.replace(/这个一会要换成换行符/g, '\n')
// log(result)
return result
}
common.获取多开分身右侧字母区域指定字母的位置 = function (多开分身右侧字母区域控件, 字母,字母数量) {
var 字母数量=字母数量 || 26
var bounds = 多开分身右侧字母区域控件.bounds()
log(bounds)
var width = bounds.width()
var height = bounds.height()
var left = bounds.left
var top = bounds.top
var right = bounds.right
var bottom = bounds.bottom
var 单元格高度 = height / 字母数量
var 单元格宽度 = right - left
var str = 'abcdefghijklmnopqrstuvwxyz';
if(字母数量==26){
str = 'abcdefghijklmnopqrstuvwxyz';
}else if(字母数量==27){
str = 'abcdefghijklmnopqrstuvwxyz#';
}else{
alert('你的多开分身多少个字母?')
exit()
}
var 字母的序号=null
if(str.indexOf(字母) > -1){
字母的序号=str.indexOf(字母)
}else{
字母的序号=str.indexOf('#')
}
log('字母的序号=',字母的序号," 字母=",字母)
var x=left+width/2
var y=top+ 单元格高度 * 字母的序号 + 单元格高度/2
return {
x:x,
y:y
}
}
/**
* 产生随机整数,包含下限值,包括上限值
* @param {Number} lower 下限
* @param {Number} upper 上限
* @return {Number} 返回在下限到上限之间的一个随机整数
*/
common.random = function (lower, upper) {
return Math.floor(Math.random() * (upper - lower+1)) + lower;
}
common.日期变时间戳 = function (date) {
// 调用示例
// log(common.日期变时间戳('2019-04-28 18:24:23'))
var 参数符合格式吗 = /\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/.test(date)
if (!参数符合格式吗) {
console.log('日期格式错误,正确的日期格式 = yyyy-MM-dd HH:mm:ss')
alert('日期格式错误,正确的日期格式 = yyyy-MM-dd HH:mm:ss')
return false
}
var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
var ts = java.lang.String.valueOf(sdf.parse(date).getTime());
ts = new java.math.BigDecimal(ts).toPlainString().toString();
return (ts);
}
common.画手势=function(){
/**
* 作者: 家
* QQ: 203118908
* 功能: 显示你的手势
*/
画坐标操作 = function (duration, xyArr) {
log('duration=',duration)
if(xyArr.length<10){
log('xyArr=',xyArr)
}else{
log('xyArr.length=',xyArr.length)
}
var 多于多少个压缩数组=200
var path = new android.graphics.Path();
var window, paint, bitmap, bitmapCanvas;
var duration = duration || 2000
function 创建悬浮窗() {
window = floaty.rawWindow( <canvas id = "board"
h = "{{device.height}}"
w = "{{device.width}}" />
);
// setInterval(() => {}, 3000)
window.setSize(device.width, device.height)
window.setTouchable(false);
// window.setPosition(0, 110)
// var bitmap = android.graphics.Bitmap.createBitmap(1080, 1920, android.graphics.Bitmap.Config.ARGB_8888);
bitmap = android.graphics.Bitmap.createBitmap(device.width, device.height, android.graphics.Bitmap.Config.ARGB_8888);
bitmapCanvas = new Canvas(bitmap);
paint = new Paint()
paint.setStrokeWidth(20);
var color = '#ff0000'
color = colors.parseColor(color)
paint.setColor(color)
paint.setStyle(Paint.Style.STROKE);
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(35);
window.board.on("draw", function (canvas) {
canvas.drawBitmap(bitmap, 0, 0, paint);
});
}
function showView(xyArr) {
创建悬浮窗()
var originalStrokeWidth = paint.getStrokeWidth()
var originalColor = paint.getColor()
// var rndColor = getRndColor()
// var color = colors.parseColor(rndColor)
// paint.setColor(color)
paint.setStrokeWidth(20)
画xyArr(duration, xyArr)
paint.setColor(originalColor)
paint.setStrokeWidth(originalStrokeWidth)
}
function 画矩形(left, top, right, bottom) {
bitmapCanvas.drawRect(left, top, right, bottom, paint)
}
function 扩充数组(arr) {
var 最低距离 = 10
var xy1=arr[0]
var xy2=arr[1]
function 输入两个坐标之间的坐标集合(xy1, xy2) {
var x1 = xy1[0]
var y1 = xy1[1]
var x2 = xy2[0]
var y2 = xy2[1]
var xyArr = []
var distance = Math.pow(((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)), 0.5);
// log('distance=', distance)
if (distance == 0) {
return [
[xy1]
]
}
var xUnit = (x2 - x1) / distance
var yUnit = (y2 - y1) / distance
// log('xUnit=', xUnit)
// log('yUnit=', yUnit)
for (var i = 0; i <= distance; i++) {
var xTemp = xUnit * i
var yTemp = yUnit * i
xyArr.push([Math.floor(xTemp + x1), Math.floor(yTemp + y1)])
}
// log(xyArr)
return xyArr
}
return 输入两个坐标之间的坐标集合(xy1, xy2)
}
function 两点距离(xy1, xy2) {       
var dx = Math.abs(xy2[0] - xy1[0]);         
var dy = Math.abs(xy2[1] - xy1[1]);         
var dis = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
return parseInt(dis)
}
function 两个坐标的弧度(xy1,xy2){
var angle = Math.atan2((xy2[1]-xy1[1]), (xy2[0]-xy1[0]))
return angle
}
// canvas.drawPath(this.TouchPointRecord[i], this.paint);
function 画xyArr2(duration, xyArr) {
var xStart=xyArr[0][0]
var yStart=xyArr[0][1]
if(xyArr.length==1){
bitmapCanvas.drawPoint(xStart,yStart,paint)
}else{
path.reset();
path.moveTo(xStart, yStart);
for (var i = 0; i < xyArr.length; i++) {
var x = xyArr[i][0]
var y = xyArr[i][1]
path.lineTo(x, y);
}
bitmapCanvas.drawPath(path, paint);
}
}
function 画xyArr(duration, xyArr) {
var xStart=xyArr[0][0]
var yStart=xyArr[0][1]
var count=xyArr.length
// var 画点间隔时间=0.9
// var 画点间隔时间=duration/count
// log("画点间隔时间=",画点间隔时间)
log('count=',count)
if(count==1){
bitmapCanvas.drawPoint(xStart,yStart,paint)
sleep(duration)
}else if(count==2){
log('两个坐标')
path.reset();
path.moveTo(xStart, yStart);
xyArr=扩充数组(xyArr)
xyArr=压缩数组(xyArr)
var count=xyArr.length
log('扩充后count=',count)
var 画点间隔时间=duration/count
for (var i = 0; i < xyArr.length; i++) {
log(i)
var x = xyArr[i][0]
var y = xyArr[i][1]
log(x,",",y)
bitmapCanvas.drawPoint(x,y,paint)
sleep(画点间隔时间)
}
}else if(count < 100){
var 画点间隔时间=duration/count
for (var i = 0; i < xyArr.length; i++) {
var x = xyArr[i][0]
var y = xyArr[i][1]
bitmapCanvas.drawPoint(x,y,paint)
sleep(画点间隔时间)
}
}else{
xyArr=压缩数组(xyArr)
log('压缩后的数组长度=',xyArr.length)
var 画点间隔时间=duration/多于多少个压缩数组
for (var i = 0; i < xyArr.length; i++) {
var x = xyArr[i][0]
var y = xyArr[i][1]
bitmapCanvas.drawPoint(x,y,paint)
sleep(画点间隔时间)
}
}
}
function 压缩数组(arr){
var newArr=[]
var count=arr.length
log('压缩数组(arr).count=',count)
var 多于100的个数=count-多于多少个压缩数组
log('多于100的个数=',多于100的个数)
var 倍数=Math.floor(count/多于多少个压缩数组)
log("倍数=",倍数)
for(var i=0;i<arr.length;i++){
if(Number.isInteger(i/倍数)){
newArr.push(arr[i])
}
}
return newArr
}
function getRndColor() {
var a, r, g, b;
a = Math.floor(0), r = Math.floor(随机0_255()), g = Math.floor(随机0_255()), b = Math.floor(随机0_255());
// var 反色 = -1 - colors.argb(0, r, g, b);
var color = colors.argb(0, r, g, b);
color = colors.toString(color)
log(color)
return color
}
function 随机0_255() {
var r = parseInt(255 * Math.random())
return r
}
showView(xyArr)
// sleep(1000)
path = null;
}
// 画坐标操作
function 画press(x, y, duration) {
threads.start(
function () {
press(x, y, duration)
}
)
var xyArr = [
[x, y]
]
画坐标操作(duration, xyArr)
}
function 画swipe(x1, y1, x2, y2, duration) {
threads.start(
function () {
swipe(x1, y1, x2, y2, duration)
}
)
var xyArr = [
[x1, y1],
[x2, y2]
]
画坐标操作(duration, xyArr)
}
// gesture(duration, [x1, y1], [x2, y2], ...)
function 画gesture(duration, xyArr) {
var points = []
points = [duration].concat(xyArr)
threads.start(
function () {
gesture.apply(null, points)
}
)
画坐标操作(duration, xyArr)
}
return {
画press:画press,
画swipe:画swipe,
画gesture:画gesture,
}
// setScreenMetrics(1080, 1920);
// var points = [];
// var interval = 0.1;
// var x0 = device.width / 2;
// var y0 = device.height / 2;
// for (var t = -3; t <= 3; t = t + 0.001) {
// //坐标系的 x,y
// var x = 16 * Math.pow(Math.sin(t), 3);
// var y = 13 * Math.cos(t) - 5 * Math.cos(t * 2) - 2 * Math.cos(t * 3) - Math.cos(t * 4);
// //增大心
// x = x * 16;
// y = y * 16;
// //算出对于手机机的坐标 手机左上角是0,0
// x = x0 + x;
// y = y0 - y;
// //存入数组
// if (x < x0) {
// points.push([parseInt(x), parseInt(y)]);
// }
// if (x > x0) {
// points.push([parseInt(x), parseInt(y)]);
// }
// }
// // gesture.apply(null, points);
// 画press(device.width/2, device.height/2,300)
// x1=device.width/6
// y1=device.height/2
// x2=device.width/6*5
// y2=device.height/2
// duration=1000
// 画swipe(x1, y1, x2, y2, duration)
// var xyArr=points
// 画gesture(3000, xyArr)
}
// var r=common
// log(r)
// var arr=[]
// for(var k in common){
// arr.push(k)
// }
// log(arr)
module.exports = common
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/helzaasd/cangku.git
git@gitee.com:helzaasd/cangku.git
helzaasd
cangku
auto.js 停止更新前 备份下来的脚本仓库
master

搜索帮助