78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
// ==UserScript==
|
|
// @name Skinrave Rain Notifier
|
|
// @namespace https://pube.tk
|
|
// @version 2025-06-03
|
|
// @description Notifies the user of joinable rains via sound and favicon cues
|
|
// @author Abhorrent_Anger
|
|
// @match https://skinrave.gg/*
|
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=skinrave.gg
|
|
// @grant none
|
|
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
|
|
// @require https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.3/waitForKeyElements.js
|
|
// @run-at document-end
|
|
// ==/UserScript==
|
|
|
|
const RECHECK_TIMER = 5000;
|
|
const INITIAL_TIMER = 2000;
|
|
const MAIN_WINDOW_SELECTOR = "div.flex.overflow-y-auto.overflow-x-hidden";
|
|
const RAIN_BUTTON_SELECTOR = 'div.mt-3.w-full.rounded button.relative.z-10.inline-flex.items-center.justify-center.rounded > span';
|
|
const RAIN_AMOUNT_SELECTOR = 'span[data-testid="rain-pot"] > span';
|
|
|
|
var player = document.createElement('audio');
|
|
player.src = 'https://cdn.pixabay.com/download/audio/2022/03/15/audio_05a708055d.mp3?filename=water-drop-85731.mp3';
|
|
player.preload = 'auto';
|
|
|
|
var title = document.title;
|
|
var rainTitle = title;
|
|
|
|
function checkRain() {
|
|
let rainJoinButton = $(RAIN_BUTTON_SELECTOR);
|
|
let rainAmount = $(RAIN_AMOUNT_SELECTOR).text();
|
|
rainTitle = title + ' (Rain: ' + rainAmount + ')';
|
|
if (rainJoinButton.length == 0 || rainJoinButton.text().toLowerCase() == 'joined') {
|
|
setTitle(rainTitle);
|
|
return false;
|
|
}
|
|
player.play();
|
|
blink();
|
|
}
|
|
|
|
function blink() {
|
|
let blinkInterval = Math.floor(RECHECK_TIMER / 4);
|
|
setBlinkOn();
|
|
setTimeout(setBlinkOff, blinkInterval);
|
|
setTimeout(setBlinkOn, blinkInterval * 2);
|
|
setTimeout(setBlinkOff, blinkInterval * 3);
|
|
}
|
|
|
|
function setBlinkOn() {
|
|
setTitle('🌧️ ' + rainTitle);
|
|
setFavicon('https://icons.iconarchive.com/icons/gartoon-team/gartoon-weather/256/weather-shower-icon.png');
|
|
}
|
|
|
|
function setBlinkOff() {
|
|
setTitle('⛈️ ' + rainTitle);
|
|
setFavicon('/favicon.ico');
|
|
}
|
|
|
|
function setTitle(newTitle) {
|
|
document.title = newTitle;
|
|
}
|
|
|
|
function setFavicon(url) {
|
|
var link = document.querySelector("link[rel~='icon']") || document.createElement('link');
|
|
link.rel = 'icon';
|
|
link.type = 'image/x-icon';
|
|
link.href = url;
|
|
(document.head || document.getElementsByTagName("head")[0]).appendChild(link);
|
|
}
|
|
|
|
function runRoutines() {
|
|
checkRain();
|
|
setTimeout(runRoutines, RECHECK_TIMER);
|
|
}
|
|
|
|
waitForKeyElements(MAIN_WINDOW_SELECTOR, () => {
|
|
title = document.title;
|
|
setTimeout(runRoutines, INITIAL_TIMER);
|
|
}); |