autojs云控_autojs实现云端脚本(七)在autojs实现云端脚本(六)中, 我们实现了下载运⾏指定脚本,
今天,我们把代码整理⼀下, 完完整整的.
autojs交流: 284029554
以下代码在前六节课中都可以到, 这⾥只是整理到⼀块了, 经过测试可正常运⾏.
云脚本功能完成
'ui';
ui.layout(
bg='{{this.bg}}' layout_weight="1" gravity='left|center'>
)
threads.start(
function () {
js脚本开发
var config = {
appId: '填写你⾃⼰的',
appKey: '填写你⾃⼰的',
}
var scriptList = downLoadScriptList(config)
console.log('scriptList=')
console.log(scriptList)
// 间隔⾏变⾊
for (var i = 0; i < scriptList.length; i++) {
if (i % 2 == 0) {
scriptList[i].bg = '#87CEEB'
} else {
scriptList[i].bg = '#C0FF3E'
}
}
log('ui.scripts.setDataSource(scriptList) scriptList=')
log(scriptList)
// 设置list内容, 添加点击事件
ui.run(
function () {
ui.scripts.setDataSource(scriptList)
("item_click", function (item, i, itemView, listView) {
var scriptName = ()
// 点击后,下载后运⾏该脚本
threads.start(
function () {
console.log('多线程⾥的scriptName=', scriptName)
scriptName = place('脚本名字: ', '').trim()
console.log('点击的脚本scriptName=', scriptName)
console.log('config=', config)
var scriptPath = downloadScript(scriptName, config)
log('开始执⾏下载的⽂件')
log('结束执⾏下载的⽂件')
}
)
});
}
)
}
)
function downLoadScriptList(config) {
var scriptListUrl = 'n2y09qsw.api.lncld/1.1/classes/_File' var url = encodeURI(scriptListUrl)
var r = (url, {
headers: {
"X-LC-Id": config.appId,
"X-LC-Key": config.appKey,
"Content-Type": "application/json"
}
}).body.json()
console.log(r)
if (r.results && r.results.length > 0) {
log('脚本列表下载成功')
log('脚本数量=', r.results.length)
var results = r.results
var scriptList = []
// 提取脚本名字
for (var i = 0; i < results.length; i++) {
var result = results[i]
var scriptName = result.name
scriptList.push({
scriptName: scriptName
})
}
console.log(scriptList)
return scriptList
} else {
log('脚本列表下载失败')
}
}
function downloadScript(scriptName, config) {
// 查指定名字脚本的下载链接
var scriptUrl = util.format('n2y09qsw.api.lncld/1.1/classes/_File?where={"name":"%s"}', scriptName) console.log('下载的脚本链接=', scriptUrl)
var url = encodeURI(scriptUrl)
var r = (url, {
headers: {
"X-LC-Id": config.appId,
"X-LC-Key": config.appKey,
"Content-Type": "application/json"
}
}).body.json()
console.log(r)
if (r.results && r.results.length > 0 && r.results[0].name === scriptName) {
log('到了指定名字的脚本')
console.sults[0].url)
var scriptPath = sults[0].url)
console.log('下载完毕, scriptPath=', scriptPath)
return scriptPath
} else {
log('没到指定名字的脚本')
}
// 这是知道了下载链接,下载脚本
function downloadScript(scriptUrl) { var r = (scriptUrl).body.bytes() var scriptPath = './' + scriptName files.writeBytes(scriptPath, r)
return scriptPath
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论