From 6a567ed3bf2c93a801dd22bb50c51b63a8477776 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Fri, 8 Oct 2021 07:15:55 +1000 Subject: [PATCH] Fix input element lookup from label (#2102) --- src/content/contextMenuHandler.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/content/contextMenuHandler.ts b/src/content/contextMenuHandler.ts index 6a2c1eca7f..5d6b1c0a0b 100644 --- a/src/content/contextMenuHandler.ts +++ b/src/content/contextMenuHandler.ts @@ -12,27 +12,24 @@ function getClickedElementIdentifier() { return invalidElement; } - const tagName = clickedEl.nodeName.toLowerCase(); + const clickedTag = clickedEl.nodeName.toLowerCase(); let inputEl = null; // Try to identify the input element (which may not be the clicked element) - if (inputTags.includes(tagName)) { - inputEl = clickedEl; - } else if (labelTags.includes(tagName)) { - let inputName = null; - if (tagName === 'label') { - inputName = clickedEl.getAttribute('for'); + if (labelTags.includes(clickedTag)) { + let inputId = null; + if (clickedTag === 'label') { + inputId = clickedEl.getAttribute('for'); } else { - inputName = clickedEl.closest('label')?.getAttribute('for'); + inputId = clickedEl.closest('label')?.getAttribute('for'); } - if (inputName != null) { - inputEl = document.querySelector('input[name=' + inputName + '], select[name=' + inputName + - '], textarea[name=' + inputName + ']'); - } + inputEl = document.getElementById(inputId); + } else { + inputEl = clickedEl; } - if (inputEl == null) { + if (inputEl == null || !inputTags.includes(inputEl.nodeName.toLowerCase())) { return invalidElement; }