Untitled
unknown
plain_text
a year ago
967 B
17
Indexable
function waitForElementVisible(selector, threshold = 0.1) {
return new Promise(resolve => {
const el = document.querySelector(selector);
if (!el) {
// Se não existir, fica de olho até aparecer no DOM
const intervalId = setInterval(() => {
const elRetry = document.querySelector(selector);
if (elRetry) {
clearInterval(intervalId);
observe(elRetry);
}
}, 500);
} else {
observe(el);
}
function observe(element) {
const observer = new IntersectionObserver((entries, obs) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
obs.disconnect();
resolve(true);
}
});
}, { threshold });
observer.observe(element);
}
});
}
waitForElementVisible('.gren-product-details-buy-button').then(() => {
//pronto para aplicar mudanças
console.log('teste');
});Editor is loading...
Leave a Comment