-
Notifications
You must be signed in to change notification settings - Fork 2
/
popup.js
43 lines (42 loc) · 1.24 KB
/
popup.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
37
38
39
40
41
42
43
'use strict';
(() => {
// Make privacy cookie available in iframe
chrome.cookies.get({
url: 'https://www.deepl.com',
name: 'privacySettings',
},
(cookie) => {
chrome.cookies.set({
url: 'https://www.deepl.com',
name: cookie.name,
value: cookie.value,
domain: cookie.domain,
path: cookie.path,
secure: cookie.secure,
httpOnly: cookie.httpOnly,
sameSite: 'no_restriction',
expirationDate: cookie.expirationDate,
storeId: cookie.storeId,
});
});
// Get selected text and open deepl.com
chrome.tabs.executeScript({
code: "window.getSelection().toString();"
}, async (selection) => {
const selectedText = selection[0];
let url = await generateUrl(selectedText);
if (selectedText !== "") {
document.getElementsByTagName("iframe")[0].setAttribute('src', url);
chrome.storage.sync.set({'lastText': selectedText }, () => {
console.log('Saved:' + selectedText);
});
} else {
chrome.storage.sync.get(['lastText'], async (result) => {
if (result.lastText !== "") {
url = await generateUrl(result.lastText);
}
document.getElementsByTagName("iframe")[0].setAttribute('src', url);
});
}
});
})();