forked from Enjoyee/Scriptable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload_gh.js
44 lines (36 loc) · 1.06 KB
/
download_gh.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// download script from github
// input script name
// download and write local
const download_url = 'https://raw.githubusercontent.com/coodajingang/Scriptable/v2/'
const fm = FileManager.iCloud();
let alert = new Alert();
alert.title = "Please input script name";
alert.message = "输入script名称,带后缀";
alert.addTextField("",'');
alert.addAction("确定");
alert.addCancelAction("退出");
let response = await alert.presentAlert();
let input_name = ''
if (response == 0) {
input_name = alert.textFieldValue(0)
}
log('Input: ' + input_name)
if (!input_name || input_name == '') {
log('No input script name!')
Script.complete()
return
}
let url = download_url + input_name
log("Download from: " + url)
const req = new Request(url)
code = await req.loadString()
if (!code || code == '' || code.startsWith("404: Not Found")) {
log('Downlad result empty')
Script.complete()
return
}
let filename = input_name
log(`saving ${filename}`)
const path = fm.joinPath(fm.documentsDirectory(), filename)
fm.writeString(path, code)
Script.complete()