Created
January 20, 2019 18:18
-
-
Save lorenzoferrante/f780dc1bdaa8009f35e16c34d2b47f84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shows latest news from MacStories in a table. | |
// The table shows an image from the article, if available, and the title of the article. | |
let numberOfArticles = URLScheme.parameter("number") | |
let url = "https://macstories.net/feed/json" | |
let shjortifyURL = "shortifyactions2:///addJSON?" | |
var jsonData = {"items": []} | |
let req = new Request(url) | |
let json = await req.loadJSON() | |
let items = json.items | |
var i = 0 | |
for (item of items) { | |
if (i >= numberOfArticles) { break } | |
let title = encodeURIComponent(decode(item.title)) | |
let url = item.url | |
var item = {"name": title, "url": url, "collection": "Web%20Links"} | |
jsonData["items"].push(item) | |
i+=1 | |
//let openURL = shjortifyURL + `name=${title}&url=${url}&collection=Web%20Links` | |
} | |
let jsonToString = JSON.stringify(jsonData) | |
let openURL = shjortifyURL + `items=${jsonToString}` | |
console.log(jsonToString) | |
let callbackURL = new CallbackURL(shjortifyURL) | |
callbackURL.addParameter("items", jsonToString) | |
callbackURL.open() | |
//Safari.openInApp(openURL) | |
function decode(str) { | |
let regex = /&#(\d+);/g | |
return str.replace(regex, (match, dec) => { | |
return String.fromCharCode(dec) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment