-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
72 lines (52 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
var currentTabId = undefined;
var currentWindowTitle = undefined;
chrome.tabs.onActivated.addListener(function(activeInfo) {
currentTabId = activeInfo.tabId;
var currentWindowId = activeInfo.windowId;
console.log("currentTabId: " + currentTabId);
console.log("currentWindowId: " + currentWindowId);
updateTabList();
});
chrome.tabs.onCreated.addListener(function(tab) {
console.log("tab was created");
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
console.log("Tab was updated");
if (tabId == currentTabId) {
currentWindowTitle = changeInfo.title;
}
updateTabList();
});
function updateTabList() {
var queryInfo = { currentWindow: true };
chrome.tabs.query(queryInfo, function(tabs) {
var customTabList = [];
for(var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
var isCurrent = currentTabId == tab.id;
console.log("index:" + i);
console.log("id:" + tab.id);
console.log("url: " + tab.url);
console.log("title: " + tab.title);
console.log("isCurrent: " + isCurrent);
console.log("currentTabId: " + currentTabId);
console.log("windowId: " + tab.windowId);
// Moeglicherweise stimmt der neue Tabtitel nicht. Falls er nicht stimmt muss man
// den Wert aus onUpdated param changeInfo.title verwenden
customTabList.push({
index: i,
id: tab.id,
title: tab.title,
isCurrent: isCurrent,
windowId: tab.windowId
});
}
console.log(customTabList);
$.post(
SPRUNG_REST_API + "/chrome",
JSON.stringify(customTabList),
function(response) { console.log(response) },
"json"
);
});
}