Created
April 23, 2021 12:24
-
-
Save Basicprogrammer10/b705c24a7cbd2b719def0b29ee156ecf to your computer and use it in GitHub Desktop.
Get random images from Lightshot and display them (For Scriptable)
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
// 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