Skip to content

Commit 6c6b840

Browse files
committed
push
1 parent 13169c4 commit 6c6b840

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

web/src/FloatingButton.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import { motion } from "framer-motion";
88

99
interface FloatingButtonProps {
1010
textArea: HTMLTextAreaElement | HTMLElement;
11-
getContentEditableText?: (el: HTMLElement) => string;
11+
getContentEditableText: boolean;
1212
}
1313

14-
const FloatingButton: React.FC<FloatingButtonProps> = ({ textArea, getContentEditableText }) => {
14+
const FloatingButton: React.FC<FloatingButtonProps> = ({
15+
textArea,
16+
getContentEditableText,
17+
}) => {
1518
const [open, setOpen] = useState(false);
1619
const [text, setText] = useState("");
1720
const [isTyping, setIsTyping] = useState(false);
@@ -41,10 +44,10 @@ const FloatingButton: React.FC<FloatingButtonProps> = ({ textArea, getContentEdi
4144
}, [textArea]);
4245

4346
const handleOpen = () => {
44-
const extractedText = getContentEditableText
45-
? getContentEditableText(textArea as HTMLElement)
46-
: (textArea as HTMLTextAreaElement).value;
47-
47+
const extractedText =
48+
getContentEditableText === true
49+
? (textArea as HTMLElement).innerText
50+
: (textArea as HTMLTextAreaElement).value;
4851
setText(extractedText);
4952
setOpen(true);
5053
};
@@ -86,7 +89,10 @@ const FloatingButton: React.FC<FloatingButtonProps> = ({ textArea, getContentEdi
8689

8790
<motion.div
8891
animate={isTyping ? { rotate: 360 } : { scale: [1, 1.1, 1] }}
89-
transition={{ duration: isTyping ? 0.5 : 0.3, repeat: isTyping ? Infinity : 1 }}
92+
transition={{
93+
duration: isTyping ? 0.5 : 0.3,
94+
repeat: isTyping ? Infinity : 1,
95+
}}
9096
whileTap={{ scale: 0.9 }}
9197
whileHover={{ scale: 1.1 }}
9298
style={{
@@ -101,7 +107,12 @@ const FloatingButton: React.FC<FloatingButtonProps> = ({ textArea, getContentEdi
101107
</Fab>
102108
</motion.div>
103109

104-
<Sidebar open={open} onClose={() => setOpen(false)} text={text} textArea={textArea} />
110+
<Sidebar
111+
open={open}
112+
onClose={() => setOpen(false)}
113+
text={text}
114+
textArea={textArea}
115+
/>
105116
</>
106117
);
107118
};

web/src/inject.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,29 @@ import FloatingButton from "./FloatingButton";
33

44
console.log("✅ Inject script running...");
55

6-
const getContentEditableText = (el: HTMLElement) => {
7-
return el.innerText || "";
8-
};
9-
106
function injectUI() {
11-
const textAreas = document.querySelectorAll("textarea, [contenteditable='true']");
7+
let textAreas: Element[] = Array.from(document.querySelectorAll("textarea, [contenteditable='true']"));
128

139
if (textAreas.length === 0) {
1410
console.warn("⚠️ No text areas found.");
1511
return;
1612
}
1713

14+
console.log("Before Filter", textAreas);
15+
16+
if (textAreas.length > 1) {
17+
const hasTextarea = textAreas.some((el) => el.tagName.toLowerCase() === "textarea");
18+
const hasContentEditable = textAreas.some(
19+
(el) => el.getAttribute("contenteditable") === "true"
20+
);
21+
22+
if (hasTextarea && hasContentEditable) {
23+
textAreas = textAreas.filter((el) => el.tagName.toLowerCase() !== "textarea");
24+
}
25+
}
26+
27+
console.log("After Filter", textAreas);
28+
1829
textAreas.forEach((textArea) => {
1930
if (!textArea.parentElement) return;
2031

@@ -34,15 +45,14 @@ function injectUI() {
3445
const root = createRoot(buttonContainer);
3546
root.render(
3647
<FloatingButton
37-
textArea={textArea as HTMLTextAreaElement}
38-
getContentEditableText={textArea.hasAttribute("contenteditable") ? getContentEditableText : undefined}
48+
textArea={textArea as HTMLElement}
49+
getContentEditableText={textArea.hasAttribute("contenteditable") ? true : false}
3950
/>
4051
);
4152
});
4253
}
4354

4455
injectUI();
4556

46-
4757
const observer = new MutationObserver(() => injectUI());
48-
observer.observe(document.body, { childList: true, subtree: true });
58+
observer.observe(document.body, { childList: true, subtree: true });

web/src/sidebar.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const Sidebar: React.FC<SidebarProps> = ({ open, onClose, text, textArea }) => {
3636
}, [text]);
3737

3838
const fetchRephrasedPrompts = async () => {
39+
40+
console.log("Chrome runtime",chrome.runtime);
3941
setLoading(true);
4042
if (transcript && transcript.length > 0) {
4143
console.log("First coniditon", transcript);

0 commit comments

Comments
 (0)