This repository has been archived by the owner on Feb 4, 2018. It is now read-only.
forked from zsxsoft/danmu-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel.js
62 lines (51 loc) · 1.63 KB
/
panel.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
/// <reference path="typings/node/node.d.ts"/>
(function () {
const electron = require('electron');
const windows = electron.remote.getGlobal('windows');
const coordinator = electron.remote.getGlobal('coordinator');
let controlButtons = Array.from(window.document.querySelectorAll(".btn-control")); // I think querySelectorAll's api is terrible.
let countQuitValue = 0;
let isShow = true;
function controlButtonClick() {
coordinator.emit(this.getAttribute("data-top"), this.getAttribute("data-param"));
}
coordinator.on("fps", fps => {
if (!isShow) return;
document.title = "FPS: " + fps;
});
window.addEventListener('beforeunload', e => {
// Hide but not exit
// We cannot call a function that in a unregistered window.
e.returnValue = 'false';
windows.panelWindow.hide();
isShow = false;
});
window.addEventListener("keydown", e => {
if (e.keyCode === 123) { // F12
windows.panelWindow.webContents.openDevTools({
detach: true,
});
}
}, true);
document.querySelector("#btn-quit").addEventListener("click", () => {
if (countQuitValue === 1) {
coordinator.emit("exit");
} else {
setTimeout(() => {
document.querySelector("#btn-quit").innerText = "退出程序";
countQuitValue = 0;
}, 5000);
this.innerText = "再按一次";
countQuitValue = 1;
}
return false;
});
controlButtons.forEach(item => {
item.addEventListener("click", controlButtonClick);
});
require('windows-caption-color').get((err, ret) => {
if (!err) {
window.document.body.style.background = "rgba(" + ret.reg.r + ", " + ret.reg.g + ", " + ret.reg.b + ", " + ret.reg.a + ")";
}
});
})();