-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
55 lines (44 loc) · 1.12 KB
/
script.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
//global variables
const inputField = document.getElementById('input');
const outputField = document.getElementById('output');
//decoding
function decode() {
const inputFieldValue = document.getElementById('input').value;
outputField.innerHTML = inputFieldValue;
}
//copy text
function copyText() {
const getOutput = document.getElementById('output');
getOutput.select();
getOutput.setSelectionRange(0, 99999);
document.execCommand('copy');
}
/**********/
function changeBtnVal() {
if (btn.value == "Copy Result") {
btn.setAttribute('value', 'Copied!');
}
}
//event listeners
const btn = document.getElementById('btn'); //global variable
const btnClear = document.getElementById('btn-clear'); //global variable
window.onload = function () {
decode();
}
inputField.onkeyup = function () {
decode();
}
inputField.onkeydown = function () {
decode();
}
inputField.onfocus = function () {
btn.setAttribute('value', 'Copy Result');
}
//clear input field
btnClear.onclick = function () {
inputField.value = '';
}
btn.onclick = function () {
copyText();
changeBtnVal();
};