-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
86 lines (75 loc) · 2.72 KB
/
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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var webview = document.getElementById('main');
var bullet = document.getElementById('drag');
var extID = 'ppibnbapebejhnmplokgfhijhfdchhhc'; // catcher links extension
var appID = 'gkcknpgdmiigoagkcoglklgaagnpojed'; // this app
var insert_style = '.window-overlay::-webkit-scrollbar{height:33px;width:33px}.window-overlay::-webkit-scrollbar-thumb{min-height:50px;background:rgba(255,255,255,1);border-radius:17px;border:10px solid transparent;background-clip:padding-box}.window-overlay::-webkit-scrollbar-track-piece{background:rgba(0,0,0,.5);border:10px solid transparent;background-clip:padding-box}.window-overlay::-webkit-scrollbar-track-piece:vertical:start{border-radius:17px 17px 0 0}.window-overlay::-webkit-scrollbar-track-piece:vertical:end{border-radius:0 0 17px 17px}';
// hide bullet if window is framed
chrome.storage.sync.get(function(items) {
if (items.showFrame !== undefined) {
frame = items.showFrame;
}
if (frame == 'chrome') {
bullet.style.display = 'none';
} else {
insert_style += '.header-logo+div{margin-left:36px!important}';
}
});
// set some css on trello.com
webview.addEventListener('loadcommit', function(e) {
if (e.isTopLevel) {
webview.insertCSS({
code: insert_style,
runAt: 'document_start'
});
}
});
// send new-window-links to bronser
webview.addEventListener('newwindow', function(e) {
e.stopImmediatePropagation();
window.open(e.targetUrl);
});
// hotkeys
window.addEventListener('keydown', function(e) {
// Ctrl+R or F5
if (e.ctrlKey && e.keyCode == 82 || e.keyCode == 115) {
webview.reload();
}
// F11
if (e.keyCode == 122) {
if (chrome.app.window.current().isFullscreen()) {
chrome.app.window.current().restore();
} else {
chrome.app.window.current().fullscreen();
}
}
// Show/hide frame
if (e.ctrlKey && e.shiftKey && e.keyCode == 70) {
chrome.storage.sync.get(function(items) {
if (items.showFrame === undefined || items.showFrame === 'none') {
frame = 'chrome';
} else {
frame = 'none';
}
chrome.storage.sync.set({ showFrame: frame });
});
setTimeout(function(){
chrome.runtime.reload();
}, 500);
}
});
// fix webview lose focus
window.addEventListener('focus', function(e) {
webview.focus();
});
// allow download
webview.addEventListener('permissionrequest', function(e) {
if (e.permission === 'download') {
e.request.allow();
}
});
// open cached links
chrome.runtime.onMessage.addListener(function(request, sender) {
if (sender.id == appID) {
webview.src = request;
}
});