Last active
August 10, 2023 00:16
-
-
Save oddlyfunctional/336628ae0922c7535df90c3ba66bf267 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const downloadURI = (uri, name) => { | |
const link = document.createElement("a"); | |
link.download = name; | |
link.href = uri; | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
} | |
const downloaded = new Set() | |
function downloadAndLoadNext() { | |
const title = document.getElementById('PastaTxt') | |
.innerText | |
.replaceAll('\\', '-') | |
.replaceAll(' ', '-') | |
const [currentMatch, lastMatch] = document.getElementById('OcorNroLbl') | |
.innerText | |
.split('/') | |
.map(Number); | |
const currentUrl = document.getElementById('DocumentoImg').src | |
const nextPage = document.getElementById('OcorPosBtn') | |
if (!downloaded.has(currentUrl)) { | |
downloaded.add(currentUrl) | |
const currentPage = document.getElementById('PagAtualTxt').value | |
downloadURI(currentUrl, `${title}-Página-${currentPage}.jpg`) | |
} | |
if (currentMatch === lastMatch) { | |
alert('Terminou!') | |
} else { | |
nextPage.click() | |
function waitUntilLoaded() { | |
const newUrl = document.getElementById('DocumentoImg').src | |
if (newUrl === currentUrl) { | |
setTimeout(waitUntilLoaded, 0) | |
} else { | |
setTimeout(downloadAndLoadNext, 0) | |
} | |
} | |
waitUntilLoaded() | |
} | |
} | |
downloadAndLoadNext() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment