skip to Main Content

how to autoclick the retry button after 3 secounds?

https://msg.cityline.com/LSPS2023HK-3fad52ed-6629-4777-9f2d-17b707dd723f.html?loc=%2FutsvInternet%2FLSPS2023HK%2Fhome%3Flang%3DEN

<button id="btn-retry-en-1" class="btn_cta" type="button" onclick="javascript:goEvent()">請重試 Retry<span id="remainTime1">(6)</span></button>

2

Answers


  1. Here is the working example:

    let btnToClick = document.querySelector("#btn");
    
    let t = setInterval(() => {
    //it clicks the btn at every 1 second
      btnToClick.click();
    },1000);
    
    //if any event occurs then clear out the setInterval reference t
     setTimeout(() => {
        clearTimeout(t);
     },3000)
    
    function demo() {
      console.log("clicked")
    }
    <button id="btn" onclick="demo()">click</button>
    Login or Signup to reply.
  2. Add the following to Tampermonkey:

    (function() {
      setTimeout(() => document.getElementById("btn-retry-en-1").click(), 3000);
    })();
    

    Details are commented in example

    // For demo purposes - countdown function
    let countdown = setInterval(() => {
      const timer = document.getElementById("remainTime1");
      let seconds = Number(timer.textContent.charAt(1));
      seconds--;
      timer.textContent = `(${seconds})`;
    }, 1000);
    
    // For demo purposes - click handler function
    function goEvent() {
      clearInterval(countdown);
      document.querySelector("dialog").showModal();
    }
    
    // Add this to Tampermonkey
    (function() {
      setTimeout(() => document.getElementById("btn-retry-en-1").click(), 3000);
    })();
    :root {
      font: 2ch/1.15 "Segoe UI"
    }
    
    button {
      display: block;
      width: 100%;
      padding: 0.25rem 0.5rem;
      font: inherit;
      cursor: pointer
    }
    <button id="btn-retry-en-1" class="btn_cta" type="button" onclick="javascript:goEvent()">請重試 Retry<span id="remainTime1">(6)</span></button>
    
    <!-- For demo purposes -->
    <dialog>
      <form method="dialog">
        <p>The "Retry()" button was clicked after 3 seconds.</p>
        <p>Countdown on "Retry()" button should be frozen at (3).</p>
        <button>OK</button>
      </form>
    </dialog>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search