Skip to content

Instantly share code, notes, and snippets.

@Basicprogrammer10
Created April 23, 2021 12:24
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/b705c24a7cbd2b719def0b29ee156ecf to your computer and use it in GitHub Desktop.
Save Basicprogrammer10/b705c24a7cbd2b719def0b29ee156ecf to your computer and use it in GitHub Desktop.
Get random images from Lightshot and display them (For Scriptable)
// Random LightShot
// Get an image from LightShot and display it
// Get Request
async function getRequest(url) {
let req = new Request(url);
let data = await req.loadString();
return data;
}
// Display Image with QuickLook
async function showImage(url) {
req = new Request(url);
let img = await req.loadImage();
QuickLook.present(img, false);
}
// Gen Lightshot image code
function stringGen(len) {
var text = "";
var charset = "abcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < len; i++) text += charset.charAt(Math.floor(Math.random() * charset.length));
return text;
}
// Parse responce for image url
function parseResponce(data) {
let working = data.split('<img class="no-click screenshot-image" src="')[1];
working = working.split('"')[0];
return working;
}
// Main Function
async function main() {
let url = "https://prnt.sc/" + stringGen(6);
let responce = await getRequest(url);
let imageUrl = parseResponce(responce);
showImage(imageUrl);
}
// 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