Refactoring, change favicon on blink
This commit is contained in:
parent
68df40a848
commit
a4fa573179
@ -1,9 +1,9 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Skinrave Rain Notifier
|
// @name Skinrave Rain Notifier
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 2025-03-03
|
// @version 2025-03-05
|
||||||
// @description Not
|
// @description Not
|
||||||
// @author You
|
// @author Abhorrent_Anger
|
||||||
// @match https://skinrave.gg/*
|
// @match https://skinrave.gg/*
|
||||||
// @icon https://www.google.com/s2/favicons?sz=64&domain=skinrave.gg
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=skinrave.gg
|
||||||
// @grant none
|
// @grant none
|
||||||
@ -23,31 +23,50 @@ player.src = 'https://cdn.pixabay.com/download/audio/2022/03/15/audio_05a708055d
|
|||||||
player.preload = 'auto';
|
player.preload = 'auto';
|
||||||
|
|
||||||
var title = document.title;
|
var title = document.title;
|
||||||
|
var rainTitle = title;
|
||||||
|
|
||||||
function checkRain() {
|
function checkRain() {
|
||||||
let rainJoinButton = $(RAIN_BUTTON_SELECTOR);
|
let rainJoinButton = $(RAIN_BUTTON_SELECTOR);
|
||||||
let rainAmount = $(RAIN_AMOUNT_SELECTOR).text();
|
let rainAmount = $(RAIN_AMOUNT_SELECTOR).text();
|
||||||
var rainTitle = title + ' (Rain: ' +rainAmount + ')';
|
rainTitle = title + ' (Rain: ' + rainAmount + ')';
|
||||||
if (rainJoinButton.length == 0 || rainJoinButton.text().toLowerCase() == 'joined') {
|
if (rainJoinButton.length == 0 || rainJoinButton.text().toLowerCase() == 'joined') {
|
||||||
console.log('There is no joinable rain');
|
|
||||||
setTitle(rainTitle);
|
setTitle(rainTitle);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
console.log('Rain available to join!');
|
|
||||||
player.play();
|
player.play();
|
||||||
let drizzleTitle = '🌧️ ' + title;
|
blink();
|
||||||
let exclaimTitle = '⛈️ ' + title;
|
}
|
||||||
setTitle(drizzleTitle);
|
|
||||||
|
function blink() {
|
||||||
let blinkInterval = Math.floor(RECHECK_TIMER / 4);
|
let blinkInterval = Math.floor(RECHECK_TIMER / 4);
|
||||||
setTimeout(() => { setTitle(exclaimTitle); }, blinkInterval);
|
setBlinkOn();
|
||||||
setTimeout(() => { setTitle(drizzleTitle); }, blinkInterval * 2);
|
setTimeout(setBlinkOff, blinkInterval);
|
||||||
setTimeout(() => { setTitle(exclaimTitle); }, blinkInterval * 3);
|
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) {
|
function setTitle(newTitle) {
|
||||||
document.title = 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() {
|
function runRoutines() {
|
||||||
checkRain();
|
checkRain();
|
||||||
setTimeout(runRoutines, RECHECK_TIMER);
|
setTimeout(runRoutines, RECHECK_TIMER);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user