Disable a button for 10 sec

Hello guys, i read the articles before with similiar names, couldnt figure it out how should i do it for my case. Im suing Pusbullet to send push to my phones, but i can spam the button if i like, but this isn’t good for me. I need to disable the buttons for 10sec, and then enable it again. Can u help me with that?
This is my code:

let apiURL = 'https://api.pushbullet.com/v2/pushes';
let apiKey = 'MyUniqueCode';

function buttonAction(title, body) {
  if (apiURL) {
    notify('Request has been sent', 'info');
    fetch(apiURL, {
      method: 'POST',
      headers: {
        'Access-Token': apiKey,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        'type': 'note',
        'title': title,
        'body': body
      })
    })
      .then((response) => {
        console.log(response)
        if (response.ok) {
          notify('OK', 'success');
        } else {
          notify('ERROR', 'error');
        }
      }).catch((error) => { console.log(error) });
  } else {
    notify('There is no API URL', 'info');
  }
}

let apiURL = 'https://api.pushbullet.com/v2/pushes';
let apiKey = 'MyUniqueCode';

function buttonAction(title, body) {
  const button = document.getElementById("YourButtonID");
  button.disabled = true;
  setTimeout(() =>
  {
        button.disabled = false;
  }, 10000);
  if (apiURL) {
    notify('Request has been sent', 'info');
    fetch(apiURL, {
      method: 'POST',
      headers: {
        'Access-Token': apiKey,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        'type': 'note',
        'title': title,
        'body': body
      })
    })
      .then((response) => {
        console.log(response)
        if (response.ok) {
          notify('OK', 'success');
        } else {
          notify('ERROR', 'error');
        }
      }).catch((error) => { console.log(error) });
  } else {
    notify('There is no API URL', 'info');
  }
}
1 Like

Thank you very much! It’s working.
At this moment it’s working on “but1” ID, but I have 2 buttons, “but1” and “but2” ID, how can i apply the same on both buttons?

I figured it out. Thanks for the help!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.