-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinject.js
36 lines (32 loc) · 1.01 KB
/
inject.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
33
34
35
36
/*
code injected into the actual tab context rather than running in our
"isolated world" context. Allows us to access various globals
within the page itself. Most important for tana Node access
*/
function invokeDocumentCopy() {
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
};
(() => {
window.addEventListener("message",
function (event) {
const command = event.data?.command;
// initial invocation message handler
if (command === "clip2tana") {
console.log("INJECT GOT MESSAGE: " + event.data.command);
// TODO: ask the user what command to run
// for now assume it is 'chatgpt'
invokeDocumentCopy();
}
// helper messages for getting/setting clipboard
else if (command === "get-clipboard") {
}
else if (command === "set-clipboard") {
}
});
//console.log("GOT INSIDE");
})();