Bloxflip Rain Autojoin

sends a notification as soon as a rain event occurs & automatically joins the rain (captcha solver included for free)

// ==UserScript==
// @name         Bloxflip Rain Autojoin
// @namespace    http://tampermonkey.net/
// @version      3.3
// @description  sends a notification as soon as a rain event occurs & automatically joins the rain (captcha solver included for free)
// @author       blueiicey
// @match        https://bloxflip.com/*
// @icon         https://bloxflip.com/favicon.ico
// @license      MIT
// ==/UserScript==

//modified from https://greasyfork.org/en/scripts/452347-bloxflip-rain-autojoin and https://greasyfork.org/en/scripts/467108-bloxflip-rain-notification

if(confirm(`Bloxflip Rain Autojoin requires you to have the hektCaptcha extension installed. Install it?`)){
  window.location.href = "https://chrome.google.com/webstore/detail/hektcaptcha-hcaptcha-solv/bpfdbfnkjelhloljelooneehdalcmljb";
}

console.log(Notification.permission)
      if(Notification.permission === "granted") {
        //yay!
      } else if(Notification.permission !== "denied") {
        alert("Allow notifications for bloxflip to get notified when a rain occurs.")
        Notification.requestPermission().then(permission => {
          console.log(permission)
        })
      }
      function showNotification(title, txt) {
        const notification = new Notification(title, {
          body: txt
        })
      }



let isRaining = false;

function sleep(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}

function playSound() {
  let audio = new Audio('https://www.myinstants.com/media/sounds/bepbob.mp3');
audio.muted = true;
sleep(1000);
audio.muted = false;
  audio.play();
}


setInterval(async function() {
  let history = await fetch('https://api.bloxflip.com/chat/history');
  let historyJson = JSON.parse(await history.text());

  if (historyJson.rain.active && !isRaining) {
    playSound();
     showNotification("Bloxflip Rain", "A bloxflip rain event is happening!")
    isRaining = true;
    document.querySelector("#__next > div.menu_container__5j6Ow > div.menu_containerItem__vtjZE.menu_chat__TrD_Q > aside > div:nth-child(4) > p.text_text__fMaR4.text_semibold14__cxkXo.chat_chatBannerJoinButton__avNuN").click();
  } else if (!historyJson.rain.active && isRaining) {
    isRaining = false;
  }
}, 5000);