forked from anthilemoon/plus-roam
/
background.js
33 lines (29 loc) · 846 Bytes
/
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
chrome.browserAction.onClicked.addListener((tab) => {
chrome.tabs.executeScript(tab.id, { file: "bookmarklet.js" });
});
chrome.runtime.onMessage.addListener((message) => {
if (message && message.type === "save") {
const url = `https://roamresearch.com?title=${
encodeURIComponent(message.text)
}#/quick-capture`;
chrome.windows.getCurrent((win) => {
chrome.windows.create({
type: "popup",
url,
focused: true,
width: 400,
height: 700,
left: (screen.width / 2) - 200 + win.left,
top: 100,
});
});
}
});
chrome.contextMenus.create({
title: "Save to Roam",
id: "save",
contexts: ["page", "frame", "selection"],
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
chrome.tabs.executeScript(tab.id, { file: "bookmarklet.js" });
});