-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
71 lines (62 loc) · 1.92 KB
/
Copy pathcontent.js
File metadata and controls
71 lines (62 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Knowledge Base Chat - Content Script
*
* Runs on any page to capture selected text and send it to the extension.
* Allows users to highlight text on a page and use it as context for their question.
*/
// Listen for text selection
document.addEventListener("mouseup", handleTextSelection);
document.addEventListener("keyup", (e) => {
if (e.shiftKey && e.key === "ArrowUp") {
handleTextSelection();
}
});
function handleTextSelection() {
const selection = window.getSelection();
const selectedText = selection.toString().trim();
if (selectedText.length > 10 && selectedText.length < 5000) {
// Send to extension
chrome.runtime.sendMessage({
type: "TEXT_SELECTED",
text: selectedText
});
// Visual feedback that text was captured
showNotification(selectedText);
}
}
function showNotification(text) {
// Remove existing notification if any
const existing = document.getElementById("kb-chat-notification");
if (existing) existing.remove();
const notification = document.createElement("div");
notification.id = "kb-chat-notification";
notification.textContent = "Added to chat context";
notification.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background: #1a1a1a;
color: white;
padding: 10px 16px;
border-radius: 8px;
font-family: -apple-system, sans-serif;
font-size: 13px;
z-index: 999999;
animation: kb-fade-in 0.2s ease-out;
`;
// Add animation
const style = document.createElement("style");
style.textContent = `
@keyframes kb-fade-in {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
`;
document.head.appendChild(style);
document.body.appendChild(notification);
// Remove after 2 seconds
setTimeout(() => {
notification.style.animation = "kb-fade-out 0.2s ease-out";
setTimeout(() => notification.remove(), 200);
}, 2000);
}