-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
32 lines (28 loc) · 889 Bytes
/
content.js
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
// We need to save it to prevent user changing selection when making ChatGPT request
let range;
function handle_runtime_message(message, _, sendResponse) {
switch (message.type) {
case 'get-selected-text': {
selection = window.getSelection();
range = selection.getRangeAt(0);
const text = selection.toString();
sendResponse({text});
}
break;
case 'replace-selected-text': {
range.deleteContents();
range.insertNode(document.createTextNode(message.text));
range = null;
}
break;
case 'change-cursor': {
document.body.style.cursor = message.cursor;
}
break;
}
}
function content_main() {
console.debug('content_main');
chrome.runtime.onMessage.addListener(handle_runtime_message);
}
content_main();