Skip to content

Instantly share code, notes, and snippets.

@oddlyfunctional
Last active August 10, 2023 00:16
Show Gist options
  • Save oddlyfunctional/336628ae0922c7535df90c3ba66bf267 to your computer and use it in GitHub Desktop.
Save oddlyfunctional/336628ae0922c7535df90c3ba66bf267 to your computer and use it in GitHub Desktop.
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