Created
August 22, 2024 20:31
-
-
Save kevinkub/20d7e089a337086a70f00aeb0ec3edd1 to your computer and use it in GitHub Desktop.
andante.js
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
(($0) => { | |
const pages = Array.from($0.querySelectorAll(':scope > div[style^="width"]')).slice(1); // drop first page | |
const urls = new Set(); | |
const scanNextPage = () => { | |
const oldUrlsSize = urls.size; | |
$0.querySelectorAll('img[src*=".svg"]').forEach(img => urls.add(img.src)); | |
if (oldUrlsSize !== urls.size) { | |
if(pages.length > 0) { | |
pages.shift().scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' }); | |
} else if (pages.length === 0) { | |
document.body.innerHTML = [...urls].sort().map(i => '<img src="'+i+'">').join('') + | |
'<style>img { max-width: 100%; max-height: 100%; page-break-after: always;</style>'; | |
} | |
} | |
}; | |
const observer = new MutationObserver(scanNextPage); | |
observer.observe($0, { subtree: true, childList: true, attributes: true }); | |
scanNextPage(); | |
})(document.querySelector('[id*="-scroller-"]')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment