Last active
August 16, 2020 10:54
-
-
Save s1n7ax/ef632074cf4f0c001691167d8da266cf to your computer and use it in GitHub Desktop.
poke em all
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 resolveXpath = $x; | |
const wait = (timeout) => { | |
return new Promise((res) => setTimeout(res, timeout)); | |
}; | |
const clickPoke = () => { | |
const wrap = async () => { | |
const buttons = resolveXpath( | |
`//span[text() = 'Poke']/ancestor::div[@role="button" and @aria-label="Poke"]` | |
); | |
if (buttons.length > 0) { | |
buttons[0].click(); | |
console.log('poking'); | |
await wait(1000); | |
await wrap(); | |
} | |
}; | |
return wrap(); | |
}; | |
const poke = () => { | |
let retry = 0; | |
const maxRetry = 30; | |
let height = 0; | |
const timeout = 1000; | |
const scrollUntilEOP = () => { | |
if (height < document.body.scrollHeight) { | |
retry = 0; | |
height = document.body.scrollHeight; | |
window.scrollTo(0, document.body.scrollHeight); | |
console.log('scrolling'); | |
wait(timeout) | |
.then(() => { | |
return clickPoke(); | |
}) | |
.then(() => scrollUntilEOP()); | |
} else if (height === document.body.scrollHeight) { | |
if (retry < maxRetry) { | |
++retry; | |
wait(timeout) | |
.then(() => console.log('retrying::', retry)) | |
.then(() => scrollUntilEOP()); | |
} | |
} | |
return; | |
}; | |
scrollUntilEOP(); | |
}; | |
poke(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment