$(document).ready(function(){const n=new Audio("/assets/ding.mp3"),a=$(".js-messages-block .app-nav__item"),g=document.title.trim();function o(e){if(!a.length||!e?.success||e.countMessages<=0)return;const t=e.countMessages,s=a.find(".badge");s.length?s.text(t):a.append(`<span class="badge bg-notify">${t}</span>`);const c=parseInt(localStorage.getItem("messageCount")||"0");t>c&&(n.play().catch(()=>{}),document.title=`🔴 ${g}`),localStorage.setItem("messageCount",t)}$(window).on("storage",e=>{e.originalEvent.key==="messageData"&&o(JSON.parse(e.originalEvent.newValue))}),setInterval(()=>{const e=Date.now(),t=parseInt(localStorage.getItem("messageTime")||"0");e-t<59900||localStorage.getItem("messageLock")||(localStorage.setItem("messageLock","1"),localStorage.setItem("messageTime",e),$.get("/messages/new").then(s=>{localStorage.setItem("messageData",JSON.stringify(s)),o(s),localStorage.removeItem("messageLock")}).catch(()=>{localStorage.removeItem("messageLock")}))},6e4)});
