BloxFlip Rain Notification

Makes a sound when rain

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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);