-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
39 lines (35 loc) · 1007 Bytes
/
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
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [new chrome.declarativeContent.PageStateMatcher({ pageUrl: { hostEquals: 'www.netflix.com' }, })],
actions: [new chrome.declarativeContent.ShowPageAction()]
}
]);
});
});
let pagePort;
chrome.runtime.onConnect.addListener(function(port) {
if (
port &&
port.sender &&
port.sender.url &&
port.sender.url.indexOf('netflix') > 0 // tedious
) {
pagePort = port;
}
port.postMessage({
from: 'Subtitle Substitute',
type: 'CONNECTION_ESTABLISHED',
});
port.onMessage.addListener((event) => {
if (event.from !== 'Subtitle Substitute') return;
if (event.type !== 'TRIGGER') return;
w = window.open(
chrome.extension.getURL('popup.html'),
'_blank',
'width=400,height=400'
);
w.port = pagePort;
});
});