-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbackground.js
55 lines (53 loc) · 1.52 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
var QueueWorker = function() {
this.queues = [];
this.tabId = null;
this.loaded = false;
this.push = function(details) {
this.queues.push(details);
this.notify();
}
this.notify = function() {
if(this.tabId === null || !this.loaded) {
return;
}
while (this.queues.length != 0) {
var details = this.queues.shift();
chrome.tabs.sendMessage(this.tabId, details, function(response){
if (chrome.runtime.lastError) {
console.log("chrome.runtime.lastError" + chrome.runtime.lastError.message);
}
});
}
}
}
var worker = new QueueWorker();
function check(tabId, changeInfo, tab) {
if (tab.url.indexOf('backlog.jp') > 0
|| tab.url.indexOf('backlogtool.com') > 0
|| tab.url.indexOf('backlog.com') > 0) {
chrome.pageAction.show(tabId);
if (tab.status === 'complete') {
worker.tabId = tabId;
worker.notify();
}
}
};
chrome.tabs.onUpdated.addListener(check);
chrome.runtime.onMessage.addListener(function(request, sender, callback) {
if(request.message === "unload") {
worker.tabId = null;
worker.loaded = false;
} else if(request.message === "loaded") {
worker.loaded = true;
worker.notify();
}
});
chrome.webRequest.onHeadersReceived.addListener(function (details) {
if(details.statusCode !== 302) {
worker.push(details);
}
}, {
urls: ["https://*.backlog.jp/*", "https://*.backlog.com/*", "https://*.backlogtool.com/*"],
types: ["main_frame", "xmlhttprequest"]
}, ["responseHeaders"]
);