-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
134 lines (122 loc) · 3.19 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
130
131
132
133
134
const en2bn = {
a: `া`,
b: `ব`,
c: `চ`,
d: `ড`,
e: `ী`,
f: `ত`,
g: `গ`,
h: `হ`,
i: `ি`,
j: `জ`,
k: `ক`,
l: `ল`,
m: `ম`,
n: `ন`,
o: `ও`,
p: `প`,
q: `দ`,
r: `র`,
s: `স`,
t: `ট`,
u: `ু`,
v: `আ`,
w: `ূ`,
x: `শ`,
y: `এ`,
z: `য়`,
A: `অ`,
B: `ভ`,
C: `ছ`,
D: `ঢ`,
E: `ঈ`,
F: `থ`,
G: `ঘ`,
H: `ঃ`,
I: `ই`,
J: `ঝ`,
K: `খ`,
L: `ং`,
M: `ঙ`,
N: `ণ`,
O: `ঔ`,
P: `ফ`,
Q: `ধ`,
R: `ড়`,
S: `ষ`,
T: `ঠ`,
U: `উ`,
V: `ঋ`,
W: `ঊ`,
X: `ঢ়`,
Y: `ঐ`,
Z: `য`,
"[": `ে`,
"{": `ৈ`,
"}": `ৌ`,
"]": `ো`,
"&": `ঞ`,
"*": `ৎ`,
"<": ` ৃ`,
">": `ঁ`,
".": `।`,
"/": `্`,
"`": ``,
1: `১`,
2: `২`,
3: `৩`,
4: `৪`,
5: `৫`,
6: `৬`,
7: `৭`,
8: `৮`,
9: `৯`,
0: `০`,
};
let writeInEnglish = false;
const __save_key = "__last_input_data__";
const __input = document.getElementById('input');
window.onload = () => {
const data = localStorage.getItem(__save_key);
if (data) {
__input.value = data;
__input.focus()
}
}
const checkIsSelection = (key, event) => {
const pressedFunctionalKey = event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || event.key === 'Control' || event.key === 'Meta' || event.key === 'Alt' || event.key === 'Shift' || event.key === 'Backspace' || event.key === 'Delete';
if ( pressedFunctionalKey ) return false;
if (key === 'ArrowLeft' || key === 'ArrowRight' || key === 'ArrowUp' || key === 'ArrowDown') {
return false;
}
return true;
};
const keyupEventListener = event => {
const value = event.target.value;
const convertedValue = `${value}`.split('').map(item => en2bn[item] ?? item).join('');
const pressedFunctionalKey = event.ctrlKey || event.metaKey || event.altKey || event.key === 'Control' || event.key === 'Meta' || event.key === 'Alt' || event.key === 'Backspace' || event.key === 'Delete';
if (pressedFunctionalKey ) {
if(event.key === 'Backspace'){
localStorage.setItem(__save_key, convertedValue);
}
return;
}
const currentPosition = __input.selectionStart;
__input.value = convertedValue.slice(0, currentPosition) + convertedValue.slice(currentPosition);
__input.selectionStart = currentPosition;
__input.selectionEnd = currentPosition;
localStorage.setItem(__save_key, convertedValue);
};
// document.addEventListener('keydown', (event) => {
// const pressedCtrl = event.ctrlKey || event.metaKey;
// if (pressedCtrl && event.key === '.') {
// console.log(`Change to ${writeInEnglish ? 'bangla' : 'english'}`);
// writeInEnglish = !writeInEnglish;
// if (writeInEnglish === true) {
// __input.removeEventListener('keyup', keyupEventListener);
// } else {
// __input.addEventListener('keyup', keyupEventListener);
// }
// }
// });
__input.addEventListener('keyup', keyupEventListener);