New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add elementReady
-like helper for DOM detections
#85
Labels
Comments
fregante
added
enhancement
New feature or request
help wanted
Extra attention is needed
labels
Nov 23, 2021
Wrapper ideaElementReady is nothing but a requestAnimationFrame-based loop that calls querySelector until found. This means we can offer a simple wrapper that does this with any detection: import {wait, canEditSidebar} from '';
function init() {
if(!await wait(canEditSidebar))
return false
}
Alternatively the detections could internally replace await canEditSidebar({async: true}) |
fregante
changed the title
How to turn DOM-based into checks that can be run with elementReady?
Add Jul 28, 2022
elementReady
-like helper for DOM detections
Something like: export async function wait(detection) {
while (!detection() && document isn't ready) {
await Promise(requestAnimationFrame)
}
return detection();
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sometimes we want to test whether a page matches before it's done downloading, this can be done by passing a selector to
element-ready
.I have 2 ideas:
Static definitions
Instead of being just a function, we can define the detections as a list of constraints like:
But this gets wordy FAST
Duplicate functions
const canUserEditOrg = (url) => isOrganizationProfile() && exists('.pagehead-tabs-item[href$="/settings/profile"]') + const canUserEditOrgAsync = async (url) => isOrganizationProfile() && await existsReady('.pagehead-tabs-item[href$="/settings/profile"]')
The text was updated successfully, but these errors were encountered: