From 9931dc6a34399b6485a3a17faa1d92290c74133e Mon Sep 17 00:00:00 2001 From: joe <> Date: Tue, 2 May 2023 01:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=88=90=E6=9F=A5=E8=A9=A2=E5=AE=8C?= =?UTF-8?q?=E5=BE=8C=EF=BC=8Ctabindex=20=E6=9C=83=E6=9C=89=20bug=20?= =?UTF-8?q?=E7=9A=84=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/content.js | 52 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/js/content.js b/js/content.js index 73fc1b4..d37ad70 100644 --- a/js/content.js +++ b/js/content.js @@ -3049,8 +3049,13 @@ function findGroupAndIndex(promptId) { (mutations) => mutations.type === "attributes" ); modifyAttributeElement.forEach((mutation) => { - if(mutation.target && mutation.target.classList.contains('dialog-wrapper')){ - mutation.target.style.display === 'flex' ? disableMenuItemTabindex() : restoreMenuItemTabindex(); + if ( + mutation.target && + mutation.target.classList.contains("dialog-wrapper") + ) { + mutation.target.style.display === "flex" + ? disableMenuItemTabindex() + : restoreMenuItemTabindex(); } }); } catch (error) { @@ -3874,8 +3879,8 @@ function findGroupAndIndex(promptId) { suffixInputElements[index].value = promptList[index].suffix; promptSlideElements[index].checked = promptList[index].isVisible; - prefixInputElements[index].style.height = '85px'; - suffixInputElements[index].style.height = '85px'; + prefixInputElements[index].style.height = "85px"; + suffixInputElements[index].style.height = "85px"; } currentSettingFormType === 1 @@ -3970,7 +3975,7 @@ function findGroupAndIndex(promptId) { superPromptSlideElements[index].checked = nowSuperPromptList[index].isVisible; superPromptIdElements[index].innerHTML = nowSuperPromptList[index].key; - superPromptTextElements[index].style.height = '85px'; + superPromptTextElements[index].style.height = "85px"; } if (focusElementIndex) { @@ -4170,7 +4175,8 @@ function findGroupAndIndex(promptId) { ); SuperPromptCategoryListLimit.forEach((_, index) => { - superPromptCategoryList[index].name = superPromptCategoryNameInputs[index].value; + superPromptCategoryList[index].name = + superPromptCategoryNameInputs[index].value; }); localStorage.setItem( @@ -4212,7 +4218,7 @@ function findGroupAndIndex(promptId) { quickReplyMessageElements[index].value = settings.quickReplyMessage; quickReplySlideElements[index].checked = settings.isVisible; - quickReplyMessageElements[index].style.height = '85px'; + quickReplyMessageElements[index].style.height = "85px"; }); quickReplyButtonTextElements[0].focus(); @@ -4804,6 +4810,7 @@ function findGroupAndIndex(promptId) { customTemplateButton.style.display = "none"; } }); + controlCustomMenuTabindex(); }, 300); }); @@ -4848,11 +4855,13 @@ function findGroupAndIndex(promptId) { } const { group } = findGroupAndIndex(settings.key); - + const button = createButton( `${settings.text}`, "warning", - `${superPromptCategoryList[group-1].name} \n #${settings.key} ${settings.text}` + `${superPromptCategoryList[group - 1].name} \n #${settings.key} ${ + settings.text + }` ); button.tabIndex = index + 13; @@ -5200,21 +5209,36 @@ function findGroupAndIndex(promptId) { ); } + var controlCustomMenuTabindexHandler = null; + function controlCustomMenuTabindex() { - const allTabindexElements = [ + let allTabindexElements = [ document.querySelector("#customKeywordInput"), ...document.querySelector(".prompt-list-area").querySelectorAll("button"), ]; + allTabindexElements = allTabindexElements.filter( + (element) => element.style.display !== "none" + ); + const firstTabindexElement = allTabindexElements[0]; const lastTabindexElement = allTabindexElements[allTabindexElements.length - 1]; + if (controlCustomMenuTabindexHandler) { + document + .querySelector(".custom-menu") + .removeEventListener("keydown", controlCustomMenuTabindexHandler); + } + + controlCustomMenuTabindexHandler = handleTabindex.bind( + null, + firstTabindexElement, + lastTabindexElement + ); + document .querySelector(".custom-menu") - .addEventListener( - "keydown", - handleTabindex.bind(null, firstTabindexElement, lastTabindexElement) - ); + .addEventListener("keydown", controlCustomMenuTabindexHandler); } })();