while(explr_status) {
try {
document.getElementsByClassName(" class")[0].click()
explr_status = !explr_status
}
catch (err) {
setTimeout(()=> {console.log(err)}, 2000)
}
}
function waitElements(selector, regexp, where) {
return new Promise(function(returnResult) {
var search_result = false;
var local_reactive_function = function() {
var wait_elements = searchElements(selector, regexp, where);
if (wait_elements.length > 0) {
if (search_result === false) {
search_result = true;
observer.disconnect();
returnResult(wait_elements);
}
}
}
var observer = new MutationObserver(local_reactive_function);
observer.observe(document.body, {
characterData: true,
attributes: true,
childList: true,
subtree: true
});
local_reactive_function();
});
}
function searchElements(selector, regexp, where) {
var search_elements = [];
if (typeof where !== 'undefined') {
var all_elements = where.querySelectorAll(selector);
}
else {
var all_elements = document.querySelectorAll(selector);
}
for (var n = 0; n < all_elements.length; n++) {
if (typeof regexp == 'object') {
if (typeof regexp.test == 'function') {
if (regexp.test(all_elements[n].innerText.trim())) {
search_elements.push(all_elements[n]);
}
}
}
else {
search_elements.push(all_elements[n]);
}
}
return search_elements;
}
elements = await waitElements('.class');
console.log('Элементы успешно найдены:');
console.dir(elements);