Skip to content

Commit

Permalink
Fix #148
Browse files Browse the repository at this point in the history
  • Loading branch information
r2dev2 committed Feb 13, 2021
1 parent bdc1552 commit 9372560
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion LiveTL/js/lib/translator-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getStorage, setupDefaultTranslatorMode } from './storage.js';

const TranslatorMode = (() => {

const [container, chatbox] = document.querySelectorAll('#input');
let [container, chatbox] = document.querySelectorAll('#input');
const defaultt = false;
let sendButton = document.querySelector('#send-button');
const postMessage = window.parent.postMessage;
Expand All @@ -20,9 +20,35 @@ const TranslatorMode = (() => {
async function run() {
if (is_ytc()) {
await ytc_run();
window.addEventListener('click', e => {
if (switchedChat(e)) {
rebindChatbox();
}
});
}
}

function switchedChat(e) {
e = e.target;
while (e.parentElement) {
if (e.tagName === 'A' && e.getAttribute('aria-selected')) {
return true;
}
e = e.parentElement;
}
return false;
}

function rebindChatbox() {
setTimeout(async () => {
chatbox.removeEventListener('keydown', checkAndAddTLTag);
sendButton.removeEventListener('mouseup', checkAndAddTLTag);
chatbox.removeEventListener('focus', checkAndAddTLTag);
[container, chatbox] = document.querySelectorAll('#input');
await ytc_run();
}, 1000);
}

async function ytc_run() {
if (chatbox) {
chatbox.style.whiteSpace = `pre-wrap`;
Expand Down

0 comments on commit 9372560

Please sign in to comment.