From 672b610dba5f1910be5be28d06accad101d38acd Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:22:15 -0700 Subject: [PATCH] Improve tab switching js --- js/switch_tabs.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/js/switch_tabs.js b/js/switch_tabs.js index 56279193..e49fef4e 100644 --- a/js/switch_tabs.js +++ b/js/switch_tabs.js @@ -8,6 +8,23 @@ function scrollToTop() { }); } +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); + } + } + + return matchingButtons; +} + function switch_to_chat() { let chat_tab_button = main_parent.childNodes[0].childNodes[1]; chat_tab_button.click(); @@ -23,21 +40,20 @@ function switch_to_default() { function switch_to_notebook() { let notebook_tab_button = main_parent.childNodes[0].childNodes[7]; notebook_tab_button.click(); + findButtonsByText('Raw')[1].click() scrollToTop(); } function switch_to_generation_parameters() { let parameters_tab_button = main_parent.childNodes[0].childNodes[10]; - let generation_tab_button = document.getElementById('character-menu').parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[1]; parameters_tab_button.click(); - generation_tab_button.click(); + findButtonsByText('Generation')[0].click() scrollToTop(); } function switch_to_character() { let parameters_tab_button = main_parent.childNodes[0].childNodes[10]; - let character_tab_button = document.getElementById('character-menu').parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[4]; parameters_tab_button.click(); - character_tab_button.click(); + findButtonsByText('Character')[0].click() scrollToTop(); }