/
popup.js
32 lines (24 loc) · 986 Bytes
/
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
const endpoint = document.getElementById('endpoint')
const enableAutoSync = document.getElementById('enableAutoSync')
chrome.storage.local.get(['endpoint', 'enableAutoSync'], function (data) {
if (data.endpoint) {
endpoint.value = data.endpoint
}
if (data.enableAutoSync) {
enableAutoSync.checked = !!data.enableAutoSync
}
})
endpoint.oninput = function () {
sendMessageToActiveTab({ key: 'endpoint', value: endpoint.value })
chrome.storage.local.set({ endpoint: endpoint.value })
}
enableAutoSync.onchange = function () {
sendMessageToActiveTab({ key: 'enableAutoSync', value: enableAutoSync.checked })
chrome.storage.local.set({ enableAutoSync: enableAutoSync.checked })
}
async function sendMessageToActiveTab(message) {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
if(new URL(tab.url).hostname === 'www.notion.so') {
await chrome.tabs.sendMessage(tab.id, message);
}
}