-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
39 lines (29 loc) · 976 Bytes
/
main.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
var scripts = [
'lib/jquery.min.js',
'lib/gamepad.min.js',
'plex_injection.js'
];
function main()
{
// Are we on a plex page?
if (document.title != "Plex" || !document.getElementById("plex") )
return;
for (i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
s.src = chrome.extension.getURL(scripts[i]);
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
}
var port = chrome.runtime.connect({name: "toggleFullscreen"}); // Communication to background script for fullscreen
window.addEventListener("message", function(event) { // Communication to the injected script to grab gamepad event
// We only accept messages from ourselves
if (event.source != window)
return;
if (event.data.type && (event.data.type == "FROM_PAGE")) {
port.postMessage({}) // Ask fullscreen.js (background script) to go fullscreen
}
}, false);
}
main();