diff --git a/src/build.xpi b/src/build.xpi new file mode 100644 index 0000000..3bfa8bd Binary files /dev/null and b/src/build.xpi differ diff --git a/src/content.js b/src/content.js index 20cb3aa..f7879d5 100644 --- a/src/content.js +++ b/src/content.js @@ -87,7 +87,55 @@ const handleStealthTyping = (event) => { } }; +const findQuestionTextAbove = (inputElement) => { + const inputRect = inputElement.getBoundingClientRect(); + const spans = Array.from( + document.querySelectorAll("span.text-format-content"), + ); + + return ( + spans + .filter((span) => { + const spanRect = span.getBoundingClientRect(); + return ( + spanRect.bottom <= inputRect.top && + Math.abs(spanRect.left - inputRect.left) < 200 + ); // Allow some horizontal tolerance + }) + .sort((a, b) => { + const aRect = a.getBoundingClientRect(); + const bRect = b.getBoundingClientRect(); + return bRect.bottom - aRect.bottom; // Get the closest span above + })[0] + ?.textContent.trim() || null + ); +}; + const activateStealthMode = async () => { + const activeElement = document.activeElement; + const isInputField = activeElement.matches( + 'input[type="text"], input:not([type]), textarea', + ); + + if (isInputField) { + // Input field is focused, find question text above + const questionText = findQuestionTextAbove(activeElement); + if (questionText) { + try { + stealthAnswer = await queryLLM(questionText); + stealthMode = true; + stealthFields.add(activeElement); + activeElement.addEventListener("keypress", handleStealthTyping); + } catch (error) { + console.error("Error activating stealth mode:", error); + stealthMode = false; + stealthAnswer = null; + } + } + return; + } + + // Original selection-based functionality const selection = window.getSelection(); const selectedText = selection.toString().trim(); diff --git a/src/manifest.json b/src/manifest.json index 9df21a0..69c63ac 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -35,13 +35,13 @@ }, "fill-input": { "suggested_key": { - "default": "Ctrl+Shift+0" + "default": "Ctrl+Alt+Space" }, "description": "Process question and fill into nearest input field" }, "toggle-stealth": { "suggested_key": { - "default": "Ctrl+Shift+Space" + "default": "Ctrl+E" }, "description": "Toggle stealth mode" }