Skip to content

Instantly share code, notes, and snippets.

@victor141516
Created November 17, 2022 14:42
Show Gist options
  • Save victor141516/fc7091b3850fa0f4336182fc3621c58f to your computer and use it in GitHub Desktop.
Save victor141516/fc7091b3850fa0f4336182fc3621c58f to your computer and use it in GitHub Desktop.
Copy text from Google Play Books
// Select the proper frame in devtools and run this script
const nextPageButton = Array.from(document.querySelectorAll('mat-icon')).find((e) => e.innerHTML === 'chevron_right');
const getCurrentPageText = () => Array.from(document.querySelectorAll('reader-page'))
.filter(e => e.checkVisibility())
.map((e) => e.textContent)
.join('');
const isLastPage = () => nextPageButton.classList.contains('mat-button-disabled');
const sleep = async () => new Promise(res => setTimeout(res, 5));
let allText = '';
;(async () => {
while (!isLastPage()) {
const currentPageText = getCurrentPageText()
allText += currentPageText
console.log(allText)
nextPageButton.click()
while (currentPageText !== '' && currentPageText === getCurrentPageText()) {
await sleep()
}
}
})()
console.log(allText)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment