diff --git a/js/switch_tabs.js b/js/switch_tabs.js index 22cef9d0..7fb78aea 100644 --- a/js/switch_tabs.js +++ b/js/switch_tabs.js @@ -1,24 +1,14 @@ -let chat_tab = document.getElementById("chat-tab"); -let main_parent = chat_tab.parentNode; - function scrollToTop() { - window.scrollTo({ - top: 0, - // behavior: 'smooth' - }); + window.scrollTo({ top: 0 }); } function findButtonsByText(buttonText) { const buttons = document.getElementsByTagName("button"); const matchingButtons = []; - buttonText = buttonText.trim(); for (let i = 0; i < buttons.length; i++) { - const button = buttons[i]; - const buttonInnerText = button.textContent.trim(); - - if (buttonInnerText === buttonText) { - matchingButtons.push(button); + if (buttons[i].textContent.trim() === buttonText) { + matchingButtons.push(buttons[i]); } } @@ -26,28 +16,23 @@ function findButtonsByText(buttonText) { } function switch_to_chat() { - let chat_tab_button = main_parent.childNodes[0].childNodes[1]; - chat_tab_button.click(); + document.getElementById("chat-tab-button").click(); scrollToTop(); } function switch_to_notebook() { - let notebook_tab_button = main_parent.childNodes[0].childNodes[9]; - notebook_tab_button.click(); + document.getElementById("notebook-parent-tab-button").click(); findButtonsByText("Raw")[1].click(); scrollToTop(); } function switch_to_generation_parameters() { - let parameters_tab_button = main_parent.childNodes[0].childNodes[13]; - parameters_tab_button.click(); + document.getElementById("parameters-button").click(); findButtonsByText("Generation")[0].click(); scrollToTop(); } function switch_to_character() { - let parameters_tab_button = main_parent.childNodes[0].childNodes[13]; - parameters_tab_button.click(); - findButtonsByText("Character")[0].click(); + document.getElementById("character-tab-button").click(); scrollToTop(); }