fetch-for-alfred.js
· 418 B · JavaScript
Неформатований
function fetch(url, useJson = true) {
const queryURL = $.NSURL.URLWithString(url);
const requestData = $.NSData.dataWithContentsOfURL(queryURL);
const requestString = $.NSString.alloc.initWithDataEncoding(
requestData,
$.NSUTF8StringEncoding,
).js;
if (useJson) {
return JSON.parse(requestString);
} else {
return requestString;
}
}
console.log(fetch("https://melaniekat.com/gifs/api"))
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")) |
16 |