-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
executable file
·40 lines (39 loc) · 1.48 KB
/
background.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
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === "install") {
chrome.storage.sync.get(["commands"], (result) => {
if (result.commands === undefined) {
chrome.storage.sync.set({ commands: [] });
}
});
chrome.storage.sync.get(["commandEnv"], (result) => {
if (result.commandEnv === undefined) {
chrome.storage.sync.set({ commandEnv: {} });
}
});
chrome.tabs.create({ url: "https://notion-palette.ruterly.com" });
} else if (details.reason === "update") {
chrome.storage.sync.get(["commands"], (result) => {
if (result.commands === undefined) {
chrome.storage.sync.set({ commands: [] });
}
});
chrome.storage.sync.get(["commandEnv"], (result) => {
if (result.commandEnv === undefined) {
chrome.storage.sync.set({ commandEnv: {} });
}
});
}
});
chrome.commands.onCommand.addListener(async (command) => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab.url.startsWith("https://www.notion.so")) {
if (command === 'show_command_palette') {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ["palette.js"]
}, (results) => {
chrome.tabs.sendMessage(tab.id, {command: command});
});
}
}
});