Modifiy stealth mode

This commit is contained in:
elijah 2024-11-01 03:21:01 +01:00
parent df231c0a90
commit 343828d018
3 changed files with 50 additions and 2 deletions

BIN
src/build.xpi Normal file

Binary file not shown.

View File

@ -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 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 selection = window.getSelection();
const selectedText = selection.toString().trim(); const selectedText = selection.toString().trim();

View File

@ -35,13 +35,13 @@
}, },
"fill-input": { "fill-input": {
"suggested_key": { "suggested_key": {
"default": "Ctrl+Shift+0" "default": "Ctrl+Alt+Space"
}, },
"description": "Process question and fill into nearest input field" "description": "Process question and fill into nearest input field"
}, },
"toggle-stealth": { "toggle-stealth": {
"suggested_key": { "suggested_key": {
"default": "Ctrl+Shift+Space" "default": "Ctrl+E"
}, },
"description": "Toggle stealth mode" "description": "Toggle stealth mode"
} }