maybe try a DOMContentLoaded event listener to begin?
document.addEventListener("DOMContentLoaded", (event) => {
console.log("DOM fully loaded and parsed");
setTimeout(startObserver, 2000);
});
function startObserver() {
const observedArea = document.querySelector(".c_ChatRoom__list-item-counter");
if (!observedArea) {
console.log("⚠️ Observed area not found! Retrying in 1s...");
setTimeout(startObserver, 1000);
return;
}
const observer = new MutationObserver(() => {
const highlightedElement = observedArea.querySelector(".c_ChatRoom__list-item-counter.is-highlighted");
if (highlightedElement) {
console.log("🔥 Spot available! Waiting 0.1s before clicking...");
setTimeout(() => {
const counter = highlightedElement.closest(".c_ChatRoom__list-item").querySelector(".c_ChatRoom__list-item-counter");
if (counter) {
console.log("🖱️ Clicking on the available spot now!");
counter.click();
}
observer.disconnect();
console.log("🔌 Observer deactivated.");
setTimeout(() => {
console.log("🔄 Reactivating observer...");
observer.observe(observedArea, { childList: true, subtree: true });
}, 5000);
}, 100);
}
});
observer.observe(observedArea, { childList: true, subtree: true });
console.log("👀 Observing changes inside the chat rooms availability list...");
}