Created
April 22, 2021 14:40
-
-
Save Basicprogrammer10/5eca08bbfa15b122153875955a70b4f0 to your computer and use it in GitHub Desktop.
Scriptable script to get Memes from reddit
This file contains 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
// π π π π | |
// Get a meme from an api and display it | |
// Get Request | |
async function getRequest(url) { | |
let req = new Request(url); | |
let json = await req.loadJSON(); | |
return json; | |
} | |
// Display Image with QuickLook | |
async function showImage(url) { | |
req = new Request(url); | |
let img = await req.loadImage(); | |
QuickLook.present(img, false); | |
} | |
// Main Function | |
async function main() { | |
let jsonResponse = await getRequest("https://meme-api.herokuapp.com/gimme"); | |
let alert = new Alert(); | |
alert.title = "π π π π"; | |
alert.message = "Title: " + jsonResponse["title"] + "\nAuthor: " + jsonResponse["author"] + "\nUpVotes: " + jsonResponse["ups"]; | |
alert.addAction("Show"); | |
alert.addCancelAction("No"); | |
let info = await alert.present(); | |
if (info === -1) return; | |
showImage(jsonResponse["url"]); | |
} | |
// Run Main Function and Exit Script | |
main(); | |
Script.complete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment