-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
executable file
·46 lines (42 loc) · 1.79 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
/**
* Listens for the app launching then creates the window
*
* @see http://developer.chrome.com/apps/app.runtime.html
* @see http://developer.chrome.com/apps/app.window.html
*/
chrome.app.runtime.onLaunched.addListener(function () {
var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;
var width = 1100;
var height = 700;
var mainWindow = chrome.app.window.create('index.html', {
id: "mainWindowID",
bounds: {
width: width,
height: height,
left: Math.round((screenWidth - width) / 2),
top: Math.round((screenHeight - height) / 2)
}
},
function(window) {
window.contentWindow.onload = function () {
// Retrieve the webview element
var webview = window.contentWindow.document.querySelector('#yt');
webview.addEventListener('newwindow', function (e) {
// Event handler for when external links are clicked because of
// the Chrome packaged app security restriction on opening links in the regular browser
e.preventDefault();
window.open(e.targetUrl);
});
chrome.commands.onCommand.addListener(function(command) {
//console.log('Command:', command);
if(command == "pause")
webview.executeScript({ code: "document.getElementsByClassName('ytp-play-button')[0].click();" });
if(command == "next")
webview.executeScript({ code: "document.getElementsByClassName('ytp-next-button')[0].click();" });
if(command == "previous")
webview.executeScript({ code: "document.getElementsByClassName('ytp-prev-button')[0].click();" });
});
};
});
});