-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.min.js
1 lines (1 loc) · 13.2 KB
/
script.min.js
1
"use strict";(function(){function e(){function e(e){"blue"==e&&(document.documentElement.classList.remove("styleDarkTheme"),document.documentElement.classList.add("styleOriginalTheme")),"dark"==e&&(document.documentElement.classList.remove("styleOriginalTheme"),document.documentElement.classList.add("styleDarkTheme"))}function h(){(Math.abs(S-y)>50||Math.abs(E-v)>50)&&(v>E&&(m=!1,l("#chatGoToBottom")),v<E&&$.addEventListener("scroll",function(e){this.scrollTop+this.clientHeight==this.scrollHeight&&(m=!0,s("#chatGoToBottom"))},{passive:!0}))}if(console.log("%cHello ! Enjoy 😃\n 🌸🌸🌸🌸🌸","background: #222; color: #FFF; font-size: 20px;"),document.getElementById("notCoChannelInputSubmit").addEventListener("click",function(){document.getElementById("notCoChannelInput").value&&(window.location.href=`./?channel=${document.getElementById("notCoChannelInput").value.toLowerCase()}`)},{passive:!0}),document.getElementById("notCoChannelInput").focus(),document.getElementById("notCoChannelInput").addEventListener("keydown",e=>{e.repeat||"Enter"==e.key&&document.getElementById("notCoChannelInputSubmit").click()}),document.querySelectorAll("#backToHomeButton, .backToHome").forEach(function(e){e.addEventListener("click",function(){ComfyJS.Disconnect(),window.location.href="./"},{passive:!0})}),null!=sessionStorage.getItem(`${d}onlyHighlightedCheck`)&&(document.getElementById("onlyHighlightedCheck").checked=JSON.parse(sessionStorage.getItem(`${d}onlyHighlightedCheck`)),r=JSON.parse(sessionStorage.getItem(`${d}onlyHighlightedCheck`))),document.getElementById("onlyHighlightedCheck").addEventListener("input",function(){document.getElementById("onlyHighlightedCheck").checked?(r=!0,i('[data-type="normal"]'),sessionStorage.setItem(`${d}onlyHighlightedCheck`,!0)):(r=!1,sessionStorage.setItem(`${d}onlyHighlightedCheck`,!1))}),null!=localStorage.getItem(`${d}highlightedNotifSound`)&&(document.getElementById("highlightedNotifSound").checked=JSON.parse(localStorage.getItem(`${d}highlightedNotifSound`)),g=JSON.parse(localStorage.getItem(`${d}highlightedNotifSound`))),document.getElementById("highlightedNotifSound").addEventListener("input",function(){document.getElementById("highlightedNotifSound").checked?(g=!0,localStorage.setItem(`${d}highlightedNotifSound`,!0)):(g=!1,localStorage.setItem(`${d}highlightedNotifSound`,!1))}),null!=sessionStorage.getItem(`${d}enableModCommand`)&&(document.getElementById("enableModCommand").checked=JSON.parse(sessionStorage.getItem(`${d}enableModCommand`)),p=JSON.parse(sessionStorage.getItem(`${d}enableModCommand`))),document.getElementById("enableModCommand").addEventListener("input",function(){document.getElementById("enableModCommand").checked?(p=!0,sessionStorage.setItem(`${d}enableModCommand`,!0)):(p=!1,sessionStorage.setItem(`${d}enableModCommand`,!1))}),null!=localStorage.getItem(`${d}mentionIsColorised`)&&(document.getElementById("mentionIsColorised").checked=JSON.parse(localStorage.getItem(`${d}mentionIsColorised`)),f=JSON.parse(localStorage.getItem(`${d}mentionIsColorised`))),document.getElementById("mentionIsColorised").addEventListener("input",function(){document.getElementById("mentionIsColorised").checked?(f=!0,document.querySelectorAll(".chat-messageMention").forEach(function(e){e.classList.remove("off")})):(f=!1,document.querySelectorAll(".chat-messageMention").forEach(function(e){e.classList.add("off")})),localStorage.setItem(`${d}mentionIsColorised`,f)}),null!=localStorage.getItem(`${d}nameIsColorized`)&&(document.getElementById("nameIsColorized").checked=JSON.parse(localStorage.getItem(`${d}nameIsColorized`)),C=JSON.parse(localStorage.getItem(`${d}nameIsColorized`))),document.getElementById("nameIsColorized").addEventListener("input",function(){document.getElementById("nameIsColorized").checked?(C=!0,document.querySelectorAll(".chat-lineName").forEach(function(e){e.classList.remove("noColor")})):(C=!1,document.querySelectorAll(".chat-lineName").forEach(function(e){e.classList.add("noColor")})),localStorage.setItem(`${d}nameIsColorized`,C)}),null!=localStorage.getItem(`${d}theme`)&&(document.querySelector(`#choiceTheme input[value="${localStorage.getItem(`${d}theme`)}"]`).checked=!0,e(localStorage.getItem(`${d}theme`))),document.querySelectorAll("#choiceTheme input").forEach(function(t){t.addEventListener("input",function(){t.checked?(localStorage.setItem(`${d}theme`,t.value),console.log("theme:",t.value),e(t.value)):console.log("false",t.value)})}),document.getElementsByClassName("mainContainer")[0].addEventListener("click",function(){document.getElementById("headerBurger").classList.remove("menuVisible"),document.getElementById("headerNav").classList.remove("menuVisible")}),document.getElementById("clearCacheButton").addEventListener("click",function(){l("#popupDivContainer")}),document.getElementById("clearCachePopupDelete").addEventListener("click",function(){sessionStorage.clear(),localStorage.clear(),s("#popupDivContainer"),document.getElementById("headerBurger").classList.remove("menuVisible"),document.getElementById("headerNav").classList.remove("menuVisible"),n("Cache clear !")}),document.getElementById("clearCachePopupCancel").addEventListener("click",function(){s("#popupDivContainer")}),document.getElementById("headerBurger").addEventListener("click",function(){this.classList.toggle("menuVisible"),document.getElementById("headerNav").classList.toggle("menuVisible")}),document.getElementById("chatGoToBottom").addEventListener("click",function(){let e=document.getElementById("hightlitedMessageChatContainer");e.scrollTop=e.scrollHeight,s("#chatGoToBottom"),m=!0},{passive:!0}),console.log(location.search.substring(1).split("&")[0]),"channel"==location.search.substring(1).split("&")[0].split("=")[0]&&(c=location.search.substring(1).split("&")[0].split("=")[1].toLowerCase(),c)){ComfyJS.Init(c);let e=document.querySelector(".titleChat p");e.innerHTML=e.textContent+'<span translate="no">'+c+"</span>",fetch(`https://decapi.me/twitch/avatar/${c}`).then(function(e){return e.text()}).then(function(e){let t=document.createElement("div"),n=document.createElement("a");n.href=`https://twitch.tv/${c}`,n.target="_blank";let o=document.createElement("img");o.src=e,o.id="channelProfilePicturePic",o.alt="profile picture",t.appendChild(n),n.appendChild(o),document.querySelector(".titleChat").insertBefore(t,document.querySelector(".titleChat p"))}),"ponce"==c&&(e.textContent="🌸 "+e.textContent+" 🌸"),document.title=`${c} - Twitch Highlighted Chat`,t(),ComfyJS.onConnected=((e,t,o)=>{if(n("Connected !"),u&&null!=localStorage.getItem(`${d}messagesSave-${c}`)){let e=JSON.parse(localStorage.getItem(`${d}messagesSave-${c}`)),t=[];e.forEach(function(e){let n=new Date(e.date),o=new Date;o.getTime()-n.getTime()>864e5*I?console.log("delete elements older than "+I+" day"):t.push(e),e.isRead?a(e.user,e.message,e.flags,e.self,e.extra,!0,new Date(e.date)).setAttribute("read",""):a(e.user,e.message,e.flags,e.self,e.extra,!0,new Date(e.date))}),localStorage.setItem(`${d}messagesSave-${c}`,JSON.stringify(t));let n=document.createElement("span");n.style="display: block; height: 1px; background-color: #fff; margin: 2px 0;",document.getElementById("hightlitedMessageChatContainer").appendChild(n)}}),ComfyJS.onChat=((e,t,n,s,l)=>{r||a(e,t,n,s,l),1==n.highlighted&&(r&&a(e,t,n,s,l),u&&o(e,t,n,s,l))}),ComfyJS.onCommand=((e,t,n,s,l)=>{if(p&&"hlt"===t&&(s.broadcaster||s.mod||"quentinperou"==e.toLowerCase()))if(s.highlighted)a(e,"!"+t+" "+n,s,!1,l),u&&o(e,"!"+t+" "+n,s,!1,l);else{let t=a(e,n,s,!1,l,!1);t.style.backgroundColor="var(--main-bg-color0)",t.style.padding="2px 5px"}else r?s.highlighted&&a(e,"!"+t+" "+n,s,!1,l):a(e,"!"+t+" "+n,s,!1,l)}),ComfyJS.onMessageDeleted=((e,t)=>{document.getElementById(e).remove()}),ComfyJS.onSub=((e,t,n,o)=>{}),ComfyJS.onResub=((e,t,n,o,a,s)=>{}),ComfyJS.onError=(e=>{console.log(e)})}document.getElementById("hightlitedMessageChatContainer").addEventListener("wheel",function(e){e.deltaY<0?this.clientHeight!=this.scrollHeight&&(m=!1,l("#chatGoToBottom")):e.deltaY>0&&this.scrollTop+this.clientHeight==this.scrollHeight&&(m=!0,s("#chatGoToBottom"))},{passive:!0});let S=0,y=0,E=0,v=0;const $=document.getElementById("hightlitedMessageChatContainer");document.getElementById("hightlitedMessageChatContainer").addEventListener("touchstart",e=>{S=e.changedTouches[0].screenX,E=e.changedTouches[0].screenY}),document.getElementById("hightlitedMessageChatContainer").addEventListener("touchend",e=>{y=e.changedTouches[0].screenX,v=e.changedTouches[0].screenY,h()})}function t(){l("#optionsDiv"),l("#optionsDiv div"),l("#choiceTheme"),l("#backToHomeButton"),l("#clearCacheButton"),l(".divConnect"),s(".divNotConnect"),document.getElementById("headerBurger").classList.add("displayOn")}function n(e){var t=Math.floor(Math.random()*Date.now());document.getElementById("notifContainer").innerHTML+=`<div class="oneNotifContainer hide"> <div id="notifNow${t}" class="notif"> <p class="notifTitle">${e}</p> </div></div>`,setTimeout(function(){document.getElementById(`notifNow${t}`).parentElement.classList.remove("hide")},10),setTimeout(function(){document.getElementById(`notifNow${t}`).parentElement.classList.add("hide"),setTimeout(function(){document.getElementById(`notifNow${t}`).parentElement.remove()},400)},2700)}function o(e,t,n,o,a){if(null==localStorage.getItem(`${d}messagesSave-${c}`)){let s={user:e,message:t,flags:n,self:o,extra:a,isRead:!1,date:new Date};localStorage.setItem(`${d}messagesSave-${c}`,JSON.stringify([s]))}else{let s={user:e,message:t,flags:n,self:o,extra:a,isRead:!1,date:new Date},l=JSON.parse(localStorage.getItem(`${d}messagesSave-${c}`));l.push(s),localStorage.setItem(`${d}messagesSave-${c}`,JSON.stringify(l))}}function a(e,t,n,o,a,s,l){null==s&&(s=!1);let i=!1;null==l&&(l=new Date,i=!0);let r=a.id,u=t.toString(),p=l,I="0"+p.getHours(),S="0"+p.getMinutes();I=I.substr(-2),S=S.substr(-2);let y="";1==n.subscriber&&null!=a.userBadges.subscriber&&4==a.userBadges.subscriber.length&&(y=`(Tier ${a.userBadges.subscriber.match(/^[0-9]/g)[0]})`);let E=document.createElement("div");E.classList.add("chat-lineMessage"),E.id=r;let v=document.createElement("div");if(v.classList.add("chat-lineNameDiv"),E.appendChild(v),v.innerHTML=`${n.mod?'<img src="img/mod.png" title="Moderator" class="chat-lineBadge">':""}\n ${n.vip?'<img src="img/vip.png" title="VIP" class="chat-lineBadge">':""}\n ${n.broadcaster?'<img src="img/broadcaster.png" title="Broadcaster" class="chat-lineBadge">':""}\n ${n.subscriber?`<img src="img/sub.png" title="${a.userState["badge-info"].subscriber?a.userState["badge-info"].subscriber.match(/[0-9]+$/g)+"-Month Subscriber "+y:""}" class="chat-lineBadge">`:""}\n <span class="chat-lineName" translate="no" style="color:${a.userColor}">${e}</span>`,!s||!i){let e=document.createElement("span");if(e.classList.add("chat-messageTime"),e.textContent=`${I}:${S}`,v.prepend(e),s){let t=document.createElement("span");t.classList.add("chat-messageDate"),t.textContent=`${(p.getDate()+1<10?"0":"")+p.getDate()}/${(p.getMonth()+1<10?"0":"")+(p.getMonth()+1)}/${p.getFullYear()} - `,v.insertBefore(t,e),E.setAttribute("data-archive",!0)}}0==C&&v.querySelector(".chat-lineName").classList.add("noColor");let $=document.createElement("span");$.classList.add("chat-messageSeparator"),$.textContent=":",v.appendChild($);let B=document.createElement("span");if(B.classList.add("chat-message"),B.setAttribute("translate","no"),1==n.highlighted){if(B.classList.add("chat-message-highlighted"),E.setAttribute("data-type","highlighted"),B.setAttribute("title","Click to mark as read"),B.addEventListener("click",function(){let e=JSON.parse(localStorage.getItem(`${d}messagesSave-${c}`)),t=e.findIndex(e=>e.extra.id==r);this.hasAttribute("read")?(this.removeAttribute("read"),e[t].isRead=!1):(this.setAttribute("read",""),e[t].isRead=!0),localStorage.setItem(`${d}messagesSave-${c}`,JSON.stringify(e))}),!s&&g){let e=new Audio("sound_notif2.aac");e.volume=.5,"ponce"==c&&(e=new Audio("sound_notif_ponce.aac"),e.volume=.7),e.play()}}else E.setAttribute("data-type","normal");B.textContent=u,E.appendChild(B),document.getElementById("hightlitedMessageChatContainer").appendChild(E);let b=document.getElementById("hightlitedMessageChatContainer");m&&(b.scrollTop=b.scrollHeight);let L=a.messageEmotes;if(null!=L){let e=[],t=B.textContent,n=t;for(const[o,a]of Object.entries(L))for(const[s,l]of Object.entries(a)){let a=l.split("-"),s=t.substring(a[0],parseInt(a[1],10)+1);e.some(e=>e===s)||(e.push(s),n=n.replaceAll(s,`</span><img alt="${s}" title="${s}" class="chat-messageEmote" src="https://static-cdn.jtvnw.net/emoticons/v2/${o}/default/dark/1.0"><span class="messageFragment">`))}B.innerHTML=n,B.classList.add("chat-message-withEmote")}let k=B.innerHTML,N=/(@[a-zA-Z0-9_]+)/gim;if(k=k.replace(N,`<span class="chat-messageMention ${f?"":"off"}">$1</span>`),B.innerHTML=k,h&&m)for(;document.querySelectorAll('.chat-lineMessage[data-type="normal"]').length>150;)document.querySelector('.chat-lineMessage[data-type="normal"]').remove();return B}function s(e){document.querySelectorAll(e).forEach(e=>e.hidden=!0)}function l(e){document.querySelectorAll(e).forEach(e=>e.hidden=!1)}function i(e){document.querySelectorAll(e).forEach(e=>e.remove())}let c;document.addEventListener("DOMContentLoaded",e);const d="HgltCt-";let r=!0,m=!0,g=!1,u=!0,h=!0,p=!0,f=!1,C=!1;const I=7})();