-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
132 lines (113 loc) · 4.01 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// when the dom is loaded it will check if it's width is less than 620px then call support.html
window.addEventListener("DOMContentLoaded", function (e) {
if (window.innerWidth < 620) {
location.href = "support.html";
}
});
// cursor blinking code
let cursor = true;
let speed = 300;
setInterval(() => {
if (cursor) {
document.getElementById('cursor').style.opacity = 0;
cursor = false;
} else {
document.getElementById('cursor').style.opacity = 1;
cursor = true;
}
}, speed);
// handles the click
const evaluateClick = (e) => {
let btnclicked = e.target.classList[0]
if (btnclicked != "board" && btnclicked != "rows") {
let btnText = e.target.innerText
action(btnText)
}
}
// use as backspace
function backspace() {
let textBoard = document.getElementsByClassName("text")[0]
textBoard.innerText = textBoard.innerText.slice(0, textBoard.innerText.length - 1)
}
// use to add space
function spacebar(isTab) {
let textBoard = document.getElementsByClassName("text")[0]
isTab ? textBoard.innerHTML += " " : textBoard.innerHTML += " ";
}
// handles the enter button
function enter() {
let textBoard = document.getElementsByClassName("text")[0]
textBoard.innerHTML += "<br>"
}
let changesht = ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "{", "}", "|",
"A", "S", "D", "F", "G", "H", "J", "K", "L", ":", '"', "Z", "X", "C", "V", "B", "N", "M", "<", ">", "?"]
let originalsht = ["`", 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, "-", "=", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", '"\"', "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"]
// handling the shift if turn on or off
function shift() {
let shiftbtn = document.getElementById("shifter")
if (shiftbtn.classList.contains("noshift")) {
shifton(changesht)
} else {
shifton(originalsht)
}
}
// turns on or off the shift
function shifton(change) {
let shiftbtn = document.getElementById("shifter")
shiftbtn.classList.toggle("noshift")
let btnchng = document.querySelectorAll(".cng")
Array.from(btnchng).forEach((value, index) => {
value.innerText = change[index]
})
}
// takes the action according to clicked keyboard button
const action = (btnText) => {
switch (btnText) {
case "␈": backspace()
break
case "space_bar": spacebar(false)
break
case "enter": enter()
break
case "tab": spacebar(true)
break
case "shift": shift()
break
case "caps": shift()
break
default:
setText(btnText)
}
}
// sets the text in the text field
const setText = (text) => {
let textBoard = document.getElementsByClassName("text")[0]
textBoard.innerText += text
}
// applying click listener when any button of keyboard is pressed the evaluate click function will work
let board = document.querySelector(".board")
board.addEventListener("click", evaluateClick)
// copies the text written in the text field into to the clipboard
const copy = (e) => {
let textBoard = document.getElementsByClassName("text")[0].textContent
async function copytoclip() {
try {
await navigator.clipboard.writeText(textBoard)
// used to call the copied text toast
const toastTrigger = document.getElementById('liveToastBtn')
const toastLiveExample = document.getElementById('liveToast')
if (toastTrigger) {
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
toastTrigger.addEventListener('click', () => {
toastBootstrap.show()
})
}
}
catch (e) {
console.error(e)
}
}
copytoclip()
}
let copybtn = document.getElementsByClassName("clip")[0]
copybtn.addEventListener("click", copy)