I want to make an autoclicker on the site, so that it stops when this button appears (code below) on the page, the button is initially hidden under the Display:none; style Display:none; , you can not take any text from the block, not necessarily this button

 <button class="btn btn-success" id="confirmButton" data-tid="0">Check Status</button> 

I made the autoclicker so, by timer it searches for text on the page, if it doesn’t exist, it clicks the button, and if the text was found, the timer is reset, but I don’t, because the condition finds values ​​from the source code, this doesn’t suit to. If there is a button in the source code, this does not mean that it has no display: none style. It seems explained more clearly.

  var b = $('b'), timer = setInterval(function() { if (b.filter(':contains("тСкст")').length) { clearInterval(timer); console.log('ΠŸΡ€ΠΈΠ΅Ρ…Π°Π»ΠΈ'); return false; } document.getElementById("showConfirmButton").click(); }, 2000); button.on('click', function() { console.log('Клик'); }); 

but I’m wrong about something and I’m having trouble ... help me fix the problem

Button on which we click <button class="btn btn-danger btn-lg" style="width:100%" onclick="showConfirm()" id="showConfirmButton">Withdraw Items</button>

  • How exactly does a new button appear? - user207618
  • we don't know how to fill in the button array, what's going on inside click() and what timer is - Igor
  • @Igor, click is the trigger for the click event; developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click . - user207618 2:46 pm
  • timer = setInterval (function () { - SloGS
  • Add this to the code! - user207618 2:46 pm

1 answer 1

MutationObserver can help.

 // Для ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π° ΠΊΠ»ΠΈΠΊΠ° let value = 0; function up() { this.value = this.value.replace(/\(\d+\)/, `(${++value})`); } document.addEventListener('DOMContentLoaded', e => { // Установим Π½Π°Ρ‡Π°Π»ΡŒΠ½Ρ‹Π΅ значСния let button = document.querySelector('#confirmButton'), someButton = document.querySelector('#someButton'); someButton.addEventListener('click', up); setTimeout(() => { button.style.display = 'inline-block'; }, 1000); // Π’Π΅ΠΏΠ΅Ρ€ΡŒ Π»ΠΎΠ²ΠΈΠΌ ΠΌΠΎΠΌΠ΅Π½Ρ‚ появлСния! // Π‘Ρ‚Π°Π²ΠΈΠΌ Π°Π²Ρ‚ΠΎΠΊΠ»ΠΈΠΊΠ΅Ρ€ let timer = setInterval(() => { someButton.click(); }, 300); // ΠžΡ‚ΡΠ»Π΅ΠΆΠΈΠ²Π°Π΅ΠΌ измСнСния ΠΊΠ½ΠΎΠΏΠΊΠΈ let observer; (observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if(getComputedStyle(button).display !== 'none'){ observer.disconnect(); // Если ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΏΡ€ΠΈΠ²Π΅Π»ΠΎ ΠΊ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΡŽ ΠΊΠ½ΠΎΠΏΠΊΠΈ, ΡƒΠ±ΠΈΡ€Π°Π΅ΠΌ Ρ‚Π°ΠΉΠΌΠ΅Ρ€ clearInterval(timer); // И Π΄Π΅Π»Π°Π΅ΠΌ Ρ‡Ρ‚ΠΎ Ρ…ΠΎΡ‚Π΅Π»ΠΈ console.log('ΠŸΡ€ΠΈΠ΅Ρ…Π°Π»ΠΈ'); } }); })).observe(button, { attributes: true, childList: true, characterData: true }); }); 
 #confirmButton { display: none; } 
 <input type='button' id='someButton' value='Count (0)' /> <button class="btn btn-success" id="confirmButton" data-tid="0">Check Status</button> 

  • You really helped, thank you very much - SloGS