import { elementReady } from "./es6-element-ready" ; function addListener ( ) { elementReady ( ".chat-list--default" ) . then ( ( element ) => { const chatWindow = element ; const oldWaifuMessages = [ ] ; const observer = new MutationObserver ( function ( ) { const chatLines = chatWindow . querySelectorAll ( ".chat-line__message" ) ; const waifu4uLines = [ ] ; chatLines . forEach ( function ( chatLine ) { const from = chatLine . querySelector ( ".chat-author__display-name" ) . textContent ; if ( from . toUpperCase ( ) === "WAIFU4U" ) { const message = chatLine . querySelector ( "span[data-a-target='chat-message-text'],a[data-a-target='chat-line__message--link'],a.ffz-tooltip" ) . textContent ; if ( ! oldWaifuMessages . includes ( message ) ) { oldWaifuMessages . push ( message ) ; waifu4uLines . push ( message ) ; } } } ) ; for ( const line of waifu4uLines ) { chrome . runtime . sendMessage ( { message : line , } , function ( ) { } ) ; console . log ( "-\nnew message from Waifu:\n" + line ) ; } observer . takeRecords ( ) ; } ) ; observer . observe ( chatWindow , { attributes : true , childList : true , subtree : true , } ) ; } ) ; } let triggered = false ; document . onreadystatechange = function ( ) : void { if ( document . readyState === "complete" ) { triggered = true ; addListener ( ) ; } } ; if ( ! triggered && document . readyState === "complete" ) { triggered = true ; addListener ( ) ; } setTimeout ( ( ) => { if ( $ ( "div[data-a-target='chat-welcome-message']" ) . length === 0 ) { window . location . reload ( ) ; } } , 20000 ) ; setTimeout ( function ( ) { window . location . reload ( ) ; } , 3600000 ) ;