-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbackground.js
67 lines (65 loc) · 1.99 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
var listeners = {};
var mpdurl = "";
var sourcedomain = "https://*";
chrome.tabs.onActivated.addListener( function(info) {
var tabId = info.tabId;
if (Object.keys(listeners).length === 0) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var mytab = tabs[0];
var currenturl = mytab.url;
if(currenturl){
var domain = (new URL(currenturl));
sourcedomain = domain.origin;
}
//console.log(mytab);
});
listeners[tabId] = function(details) {
//console.info("URL :" + details.url);
if(details.url.indexOf(".mpd") != -1){
console.info("URL :" + details.url);
mpdurl = details.url;
chrome.cookies.set({ url: sourcedomain, name: "last_mpd", value: mpdurl });
}
};
chrome.webRequest.onCompleted.addListener(listeners[tabId], {
urls: ['<all_urls>'],
tabId: tabId
}, []);
}
});
chrome.tabs.onActiveChanged.addListener( function(tabId, info) {
for (var x in listeners){
if(!listeners[x].hasOwnProperty(tabId)){
chrome.webRequest.onCompleted.removeListener(listeners[x]);
delete listeners[x];
} else{
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var mytab = tabs[0];
var currenturl = mytab.url;
if(currenturl){
var domain = (new URL(currenturl));
sourcedomain = domain.origin;
}
//console.log(mytab);
});
listeners[tabId] = function(details) {
//console.info("URL :" + details.url);
if(details.url.indexOf(".mpd") != -1){
console.info("URL :" + details.url);
mpdurl = details.url;
chrome.cookies.set({ url: sourcedomain, name: "last_mpd", value: mpdurl });
}
};
chrome.webRequest.onCompleted.addListener(listeners[tabId], {
urls: ['<all_urls>'],
tabId: tabId
}, []);
}
}
});
chrome.tabs.onRemoved.addListener(function(tabId) {
if (listeners[tabId]) {
chrome.webRequest.onCompleted.removeListener(listeners[tabId]);
delete listeners[tabId];
}
});