MarseyWorld/files/assets/js/flash.js

36 lines
878 B
JavaScript
Raw Normal View History

2023-09-26 20:20:43 +00:00
const SITE_NAME = document.querySelector("[name='application-name']").content
2023-09-26 20:05:39 +00:00
const icon = document.querySelector("link[rel~='icon']")
const page_title = document.getElementsByTagName('title')[0].innerHTML
let notifs = 0
let focused = true
let alert = true;
addEventListener('blur', function(){
focused = false
})
addEventListener('focus', function(){
focused = true
})
function flash(){
let title = document.getElementsByTagName('title')[0]
if (notifs >= 1 && !focused){
title.innerHTML = `[+${notifs}] ${page_title}`
if (alert) {
2023-09-28 23:58:09 +00:00
icon.href = `${SITE_FULL_IMAGES}/i/${SITE_NAME}/alert.ico?x=3009`
2023-09-26 20:05:39 +00:00
alert = false
}
else {
2023-12-22 20:14:21 +00:00
icon.href = `${SITE_FULL_IMAGES}/i/${SITE_NAME}/icon.webp?x=7`
2023-09-26 20:05:39 +00:00
alert = true
}
setTimeout(flash, 500)
}
else {
2023-12-22 20:14:21 +00:00
icon.href = `${SITE_FULL_IMAGES}/i/${SITE_NAME}/icon.webp?x=7`
2023-09-26 20:05:39 +00:00
notifs = 0
title.innerHTML = page_title
}
}