-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
23 lines (21 loc) · 781 Bytes
/
background.js
File metadata and controls
23 lines (21 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function createSpirit () {
chrome.storage.sync.set({'wedone': false});
chrome.tabs.create({'url': chrome.extension.getURL('spirit.html'), 'selected': true});
}
function focusOnSpirit() {
chrome.tabs.query({'url': chrome.extension.getURL('spirit.html')}, function (tabs) {
!tabs.length && createSpirit();
tabs.length && chrome.tabs.update(tabs[0].id, {'selected': true});
});
}
chrome.tabs.onActivated.addListener(function() {
chrome.storage.sync.get(function (data) {
var count = data.tabsCount || 0;
var nextTime = data.nextTime || count;
chrome.storage.sync.set({'tabsCount': count += 1});
if (count > nextTime) {
data.wedone = false;
}
!data.wedone && focusOnSpirit()
});
});