fetch-for-alfred.js(檔案已創建)
@@ -0,0 +1,15 @@ | |||
1 | + | function fetch(url, useJson = true) { | |
2 | + | const queryURL = $.NSURL.URLWithString(url); | |
3 | + | const requestData = $.NSData.dataWithContentsOfURL(queryURL); | |
4 | + | const requestString = $.NSString.alloc.initWithDataEncoding( | |
5 | + | requestData, | |
6 | + | $.NSUTF8StringEncoding, | |
7 | + | ).js; | |
8 | + | if (useJson) { | |
9 | + | return JSON.parse(requestString); | |
10 | + | } else { | |
11 | + | return requestString; | |
12 | + | } | |
13 | + | } | |
14 | + | ||
15 | + | console.log(fetch("https://melaniekat.com/gifs/api")) |
上一頁
下一頁