Last active
May 4, 2022 12:13
-
-
Save saenai255/a80f8eef937ebe78c3cf6ebc33576d40 to your computer and use it in GitHub Desktop.
TamperMonkey Utilities
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 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