Skip to content

Instantly share code, notes, and snippets.

@saenai255
Last active May 4, 2022 12:13
Show Gist options
  • Save saenai255/a80f8eef937ebe78c3cf6ebc33576d40 to your computer and use it in GitHub Desktop.
Save saenai255/a80f8eef937ebe78c3cf6ebc33576d40 to your computer and use it in GitHub Desktop.
TamperMonkey Utilities
const delay = ms => new Promise(r => setTimeout(r, ms));
const waitFor = async fn => {
let el = null;
while (!el) {
await delay(50);
el = await fn();
}
return el;
}
const byText = (text, selector) =>
[...document.querySelectorAll(selector)].find(el => el.innerText.includes(text));
const waitForElem = async sel =>
await waitFor(() => document.querySelector(sel));
const waitForElemText = async (text, sel) =>
await waitFor(() => byText(text, sel));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment