-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
74 lines (59 loc) · 1.69 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var currentTabId = undefined;
var currentWindowTitle = undefined;
var logging = false;
browser.tabs.onCreated.addListener(handleTabCreated);
browser.tabs.onUpdated.addListener(handleTabUpdate);
browser.tabs.onActivated.addListener(handleTabActivated);
function handleTabActivated(activeInfo) {
var tabId = activeInfo.tabId;
var windowId = activeInfo.windowId;
currentTabId = tabId;
updateTabList();
}
function handleTabUpdate(tabId, changeInfo, tab) {
logTabInfo("UPDATED", tab);
if (tabId == currentTabId) {
currentWindowTitle = changeInfo.title;
}
updateTabList();
}
function handleTabCreated(tab) {
logTabInfo("CREATED", tab);
}
function logTabInfo(action, tab) {
if(!logging) return;
console.log(action);
console.log("tabid = " + tab.id);
console.log("title = " + tab.title);
console.log("url = " + tab.url);
console.log("window id = " + tab.windowId);
}
function updateTabList() {
var queryInfo = { currentWindow: true };
var querying = browser.tabs.query(queryInfo);
querying.then(handleUpdateTabs, handleUpdateTabListError);
}
function handleUpdateTabListError(error) {
console.log(error);
}
function handleUpdateTabs(tabs) {
var customTabList = [];
for(var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
var isCurrent = currentTabId == tab.id;
logTabInfo("HANDLEUPDATETABS", tab);
customTabList.push({
index: i,
id: tab.id,
title: tab.title,
isCurrent: isCurrent,
windowId: tab.windowId
});
}
$.post(
SPRUNG_REST_API + "/firefox",
JSON.stringify(customTabList),
function(response) { console.log(response) },
"json"
);
}