-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
53 lines (47 loc) · 1.58 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
document.querySelector('#copy-localStorage').onclick = () => {
sendMessage('copy-localStorage');
};
document.querySelector('#copy-sessionStorage').onclick = () => {
sendMessage('copy-sessionStorage');
};
document.querySelector('#paste-localStorage').onclick = () => {
sendMessage('paste-localStorage');
};
document.querySelector('#paste-sessionStorage').onclick = () => {
sendMessage('paste-sessionStorage');
};
const sendMessage = (message) => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { morty: { action: message }});
});
};
chrome.runtime.onMessage.addListener(msgObj => {
const actionMessage = msgObj?.morty?.action;
switch (actionMessage) {
case 'copy-localStorage-reply':
if (msgObj?.morty?.actionReply) {
chrome.storage.local.set({
'localStorageClipboard': msgObj.morty.actionReply,
});
}
break;
case 'copy-sessionStorage-reply':
if (msgObj?.morty?.actionReply) {
chrome.storage.local.set({
'sessionStorageClipboard': msgObj.morty.actionReply,
});
}
break;
case 'paste-localStorage-reply':
break;
case 'paste-sessionStorage-reply':
break;
}
});
document.querySelector('#view-clipboard').onclick = () => {
if (chrome.runtime.openOptionsPage) {
chrome.runtime.openOptionsPage();
} else {
window.open(chrome.runtime.getURL('clipboard.html'));
}
}