-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
88 lines (71 loc) · 2.28 KB
/
index.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
87
88
const electron = require('electron');
const fpCode = require('flowerpassword.js');
// const remote = electron.remote;
const shell = electron.shell;
const ipc = electron.ipcRenderer;
const clipboard = electron.clipboard;
const btnClose = document.getElementById('close');
const iptPassword = document.getElementById('password');
const iptKey = document.getElementById('key');
const iptPrefix = document.getElementById('prefix');
const iptSuffix = document.getElementById('suffix');
const btnCode = document.getElementById('code');
const selLength = document.getElementById('length');
iptPassword.addEventListener('input', showCode, false);
iptKey.addEventListener('input', showCode, false);
iptPrefix.addEventListener('input', showCode, false);
iptSuffix.addEventListener('input', showCode, false);
selLength.addEventListener('change', showCode, false);
iptKey.addEventListener('keypress', function(e) {
if (e.keyCode === 13) {
let code = showCode();
if (code !== false) {
clipboard.writeText(code, 'text');
e.preventDefault();
hide();
}
}
}, false);
ipc.on('key-from-clipboard', function(event, message) {
iptKey.value = message;
showCode();
});
function hide() {
ipc.send('hide', 'hide');
}
function showCode(e) {
let password = iptPassword.value;
let key = iptKey.value;
let prefix = iptPrefix.value;
let suffix = iptSuffix.value;
let length = selLength.value;
let code = '生成密码(点击复制)';
if ((password.length < 1) || (key.length < 1)) {
btnCode.textContent = code;
return false;
}
key = prefix + key + suffix;
code = fpCode(password, key, length);
btnCode.textContent = code;
return code;
}
btnClose.addEventListener('click', function(e) {
hide();
}, false);
btnCode.addEventListener('click', function(e) {
let code = showCode();
if (code !== false) {
clipboard.writeText(code);
hide();
}
}, false);
const links = document.querySelectorAll('a[href]');
Array.prototype.forEach.call(links, function(link) {
const url = link.getAttribute('href');
if (url.indexOf('https') === 0) {
link.addEventListener('click', function(e) {
e.preventDefault();
shell.openExternal(url);
})
}
})