Skip to content

Instantly share code, notes, and snippets.

@lorenzoferrante
Created January 20, 2019 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzoferrante/f780dc1bdaa8009f35e16c34d2b47f84 to your computer and use it in GitHub Desktop.
Save lorenzoferrante/f780dc1bdaa8009f35e16c34d2b47f84 to your computer and use it in GitHub Desktop.
// 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