-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
90 lines (78 loc) · 3.13 KB
/
Copy pathbackground.js
File metadata and controls
90 lines (78 loc) · 3.13 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// background.js
let sessionBuffer = [];
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
// Single file download
if (message.action === 'download_md') {
const blobUrl = 'data:text/markdown;charset=utf-8,' + encodeURIComponent(message.content);
chrome.downloads.download({
url: blobUrl,
filename: message.filename,
saveAs: true
});
sendResponse(true);
return true;
}
// --- SESSION MANAGEMENT --- //
if (message.action === 'get_session_status') {
sendResponse({
count: sessionBuffer.length,
totalText: sessionBuffer.join('\n\n')
});
return true;
}
if (message.action === 'add_to_session') {
sessionBuffer.push(message.content);
sendResponse({
count: sessionBuffer.length,
totalText: sessionBuffer.join('\n\n')
});
return true;
}
if (message.action === 'clear_session') {
sessionBuffer = [];
sendResponse({ success: true });
return true;
}
if (message.action === 'download_session') {
if (sessionBuffer.length === 0) {
sendResponse(false);
return true;
}
const combinedContent = sessionBuffer.join('\n\n\n--------------------------------------------------------------\n\n\n');
const sessionDate = new Date().toISOString().split('T')[0];
const blobUrl = 'data:text/markdown;charset=utf-8,' + encodeURIComponent(combinedContent);
chrome.downloads.download({
url: blobUrl,
filename: `rixai_session_${sessionDate}.md`,
saveAs: true
});
// Clear session after download
sessionBuffer = [];
sendResponse(true);
return true;
}
// --- INTERACTIVE SELECTOR --- //
// Listen for the content script completing an interactive selection
if (message.action === 'interactive_element_selected') {
// Automatically put it in the clipboard using markdown
if (message.markdown) {
// Write to clipboard indirectly via scripting or alert
chrome.scripting.executeScript({
target: { tabId: sender.tab.id },
func: (textToCopy) => {
navigator.clipboard.writeText(textToCopy).then(() => {
// Show a non-intrusive toast on the page
const toast = document.createElement('div');
toast.textContent = "RixAI: Блок скопирован!";
toast.style.cssText = "position:fixed; bottom:20px; right:20px; background:#0077ff; color:white; padding:12px 20px; border-radius:8px; z-index:999999; font-family:sans-serif; box-shadow:0 4px 12px rgba(0,0,0,0.3); font-weight:bold;";
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 2500);
}).catch(e => console.error(e));
},
args: [message.markdown]
});
}
sendResponse(true);
return true;
}
});