fetch-for-osascript.js
· 472 B · JavaScript
Surowy
/*
Try it from the command line on Mac:
`osascript -l JavaScript fetch-for-osascript.js`
*/
function fetch(url) {
const queryURL = $.NSURL.URLWithString(url);
const requestData = $.NSData.dataWithContentsOfURL(queryURL);
const requestString = $.NSString.alloc.initWithDataEncoding(
requestData,
$.NSUTF8StringEncoding,
).js;
return JSON.parse(requestString);
}
const json = fetch("https://melaniekat.com/gifs/api")
console.log(JSON.stringify(json))
1 | /* |
2 | Try it from the command line on Mac: |
3 | `osascript -l JavaScript fetch-for-osascript.js` |
4 | */ |
5 | function fetch(url) { |
6 | const queryURL = $.NSURL.URLWithString(url); |
7 | const requestData = $.NSData.dataWithContentsOfURL(queryURL); |
8 | const requestString = $.NSString.alloc.initWithDataEncoding( |
9 | requestData, |
10 | $.NSUTF8StringEncoding, |
11 | ).js; |
12 | return JSON.parse(requestString); |
13 | } |
14 | |
15 | const json = fetch("https://melaniekat.com/gifs/api") |
16 | console.log(JSON.stringify(json)) |
17 |