Skip to content

Instantly share code, notes, and snippets.

@Basicprogrammer10
Created April 22, 2021 14:40
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 Basicprogrammer10/5eca08bbfa15b122153875955a70b4f0 to your computer and use it in GitHub Desktop.
Save Basicprogrammer10/5eca08bbfa15b122153875955a70b4f0 to your computer and use it in GitHub Desktop.
Scriptable script to get Memes from reddit
// π“œ 𝓔 π“œ 𝓔
// 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