-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
41 lines (31 loc) · 1.09 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
41
var currentTab;
function handleClicked() {
console.log("title: " + currentTab.title + ", url: " + currentTab.url);
var note = currentTab.url;
browser.tabs.create({
"url": "omnifocus:///add?name=" + encodeURIComponent(currentTab.title) + "¬e=" + encodeURIComponent(note)
}).then(function(tab) {
setTimeout(function() {
browser.tabs.remove(tab.id);
browser.tabs.update(currentTab.id, {active: true});
});
});
}
browser.browserAction.onClicked.addListener(handleClicked);
// https://github.com/mdn/webextensions-examples/blob/master/bookmark-it/background.js
function updateActiveTab(tabs) {
function updateTab(tabs) {
if (tabs[0]) {
currentTab = tabs[0];
}
}
var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
gettingActiveTab.then(updateTab);
}
// listen to tab URL changes
browser.tabs.onUpdated.addListener(updateActiveTab);
// listen to tab switching
browser.tabs.onActivated.addListener(updateActiveTab);
// listen for window switching
browser.windows.onFocusChanged.addListener(updateActiveTab);
updateActiveTab();