Forked from foyez/lightshot-image-extractor.js
Last active
December 26, 2021 15:30
-
-
Save NightScript370/be2096a001964d52f913c25050a1973b to your computer and use it in GitHub Desktop.
LightShot Image Extractor: scrapes the jpg screenshot link from a LightShot page
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
import { DOMParser, Element, HTMLDocument } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts"; | |
/** | |
* Extracts the jpg url from a LightShot page | |
* lightshot_image('http://prntscr.com/dki21q') | |
* http://image.prntscr.com/image/1aaf571d0adf4aa098eb565bbb196af6.png | |
*/ | |
export default async function lightshotImageExtractor(url:URL):URL { | |
const connection = await fetch(url.href); | |
if (!connection.ok) throw Error("Connection not OK"); | |
const document:HTMLDocument = new DOMParser().parseFromString(await connection.text(), "text/html")!; | |
const imageElement:Element = document.getElementsByClassName('screenshot-image')[0]; | |
return new URL(imageElement.getAttribute('src')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment