Skip to content

Instantly share code, notes, and snippets.

@s1n7ax
Last active August 16, 2020 10:54
Show Gist options
  • Save s1n7ax/ef632074cf4f0c001691167d8da266cf to your computer and use it in GitHub Desktop.
Save s1n7ax/ef632074cf4f0c001691167d8da266cf to your computer and use it in GitHub Desktop.
poke em all
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