forked from ghouet/chrome-hls
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.js
35 lines (32 loc) · 1.18 KB
/
event.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
var enabled = true;
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse){
if (request == "getState") {
sendResponse(enabled);
} else {
enabled = request == "Enable";
enabled ? chrome.browserAction.setIcon({path:"img/icon128.png"}) : chrome.browserAction.setIcon({path:"img/icon128grey.png"})
}
}
);
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
if (enabled && info.url.split("?")[0].split("#")[0].endsWith(".flv")) {
var playerUrl = chrome.runtime.getURL('player.html') + "#" + info.url
if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){
chrome.tabs.update(info.tabId, {url: playerUrl});
return {cancel: true}
} else {
return { redirectUrl: playerUrl }
}
}
},
{urls: ["*://*/*.flv*"], types:["main_frame"]},
["blocking"]
);
chrome.omnibox.onInputEntered.addListener(function (input){
var playerUrl = chrome.runtime.getURL('player.html') + "#" + input;
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
chrome.tabs.update(tabs[0].id, {url: playerUrl});
});
});