FIX: loading extension after chat popout and url change
WIP: Transforming to TypeScript
This commit is contained in:
35
src/index.ts
Normal file
35
src/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import './styles/main.scss';
|
||||
import TwitchNote from "./TwitchNote";
|
||||
|
||||
const ChatContainerClass = 'chat-scrollable-area__message-container';
|
||||
const twitchNote = new TwitchNote();
|
||||
let chatExists = false;
|
||||
let lastUrl = '';
|
||||
|
||||
function init() {
|
||||
|
||||
// check for chat container existence
|
||||
setInterval(() => {
|
||||
// check for URL changes (going through different channels)
|
||||
const currentUrl = window.location.href;
|
||||
if (lastUrl !== currentUrl) {
|
||||
lastUrl = currentUrl;
|
||||
chatExists = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// check for chat container appearing in DOM
|
||||
const targetNode = document.querySelector(`.${ChatContainerClass}`);
|
||||
if (targetNode) {
|
||||
if (!chatExists) {
|
||||
// chat container appeared
|
||||
twitchNote.init(targetNode);
|
||||
}
|
||||
chatExists = true;
|
||||
} else {
|
||||
chatExists = false;
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
init();
|
||||
Reference in New Issue
Block a user