forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyCreds.js
More file actions
31 lines (26 loc) · 887 Bytes
/
copyCreds.js
File metadata and controls
31 lines (26 loc) · 887 Bytes
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
import { debounce } from './helpers';
// Monitor "Account" and "Password" inputs on "Add/Edit Mail Account"
// page and update the sidebar "Account" and "Password" inputs
export default function handleCopyCreds() {
monitorAndUpdate('.js-account-input', '.js-account-output');
monitorAndUpdate('.js-password-input', '.js-password-output');
}
function monitorAndUpdate(inputSelector, outputSelector) {
const inputElement = document.querySelector(inputSelector);
const outputElement = document.querySelector(outputSelector);
if (!inputElement || !outputElement) {
return;
}
function updateOutput(value) {
const postfix = outputElement.dataset.postfix;
if (value && postfix) {
value += postfix;
}
outputElement.value = value;
}
inputElement.addEventListener(
'input',
debounce((evt) => updateOutput(evt.target.value)),
);
updateOutput(inputElement.value);
}