BloxFlip Rain Notification

Makes a sound when rain

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         BloxFlip Rain Notification
// @name:ru      BloxFlip Уведомление на дожди
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Makes a sound when rain
// @description:ru  Издает звук когда начинается дождь
// @author       HProgram
// @match        https://bloxflip.com/*
// @icon         https://i.imgur.com/U8U9VYV.png
// @license GPL-3.0-only
// ==/UserScript==

// Discord: Serzh1204#9186

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();
    isRaining = true;
  } else if (!historyJson.rain.active && isRaining) {
    isRaining = false;
  }
}, 5000);