-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathonload.js
More file actions
63 lines (47 loc) · 1.68 KB
/
onload.js
File metadata and controls
63 lines (47 loc) · 1.68 KB
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
'use strict';
const ipcRenderer = require('electron').ipcRenderer;
onload = function() {
const webview = document.querySelector('webview');
ipcRenderer.on('nextSong', function() {
webview.executeJavaScript('doubanfm$.nextSong()');
});
ipcRenderer.on('playPause', function() {
webview.executeJavaScript('doubanfm$.playPause()');
});
ipcRenderer.on('like', function() {
webview.executeJavaScript('doubanfm$.like()');
});
ipcRenderer.on('trash', function() {
webview.executeJavaScript('doubanfm$.trash()');
});
doLayout();
};
function doLayout() {
var container = document.querySelector('#webview-container');
var webview = document.querySelector('webview');
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var webviewWidth = windowWidth;
var webviewHeight = windowHeight;
var scrollbarWidth = getScrollbarWidth();
container.style.width = webview.style.width = webviewWidth - scrollbarWidth + 'px';
container.style.height = webview.style.height = webviewHeight + 'px';
}
function getScrollbarWidth() {
var outer = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.width = "100px";
outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
document.body.appendChild(outer);
var widthNoScroll = outer.offsetWidth;
// force scrollbars
outer.style.overflow = "scroll";
// add innerdiv
var inner = document.createElement("div");
inner.style.width = "100%";
outer.appendChild(inner);
var widthWithScroll = inner.offsetWidth;
// remove divs
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;
}