js_lis 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/keyboard.js +514 -0
- package/layouts.js +352 -0
- package/package.json +1 -1
- package/index.js +0 -312
- package/layout.js +0 -398
package/keyboard.js
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
let activeInput = null;
|
|
2
|
+
let isDragging = false;
|
|
3
|
+
let offsetX = 0,
|
|
4
|
+
offsetY = 0;
|
|
5
|
+
let isCapsLock = false;
|
|
6
|
+
let isShift = false;
|
|
7
|
+
let currentLanguage = "english";
|
|
8
|
+
const encryptionKey = "1234567890123456";
|
|
9
|
+
|
|
10
|
+
// เพิ่ม event listener
|
|
11
|
+
document.querySelectorAll("input, textarea, form").forEach((element) => {
|
|
12
|
+
element.addEventListener("focus", (event) => {
|
|
13
|
+
event.stopImmediatePropagation();
|
|
14
|
+
activeInput = element;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// แสดง-ซ่อนคีย์บอร์ด
|
|
19
|
+
function toggleKeyboard() {
|
|
20
|
+
const keyboard = document.getElementById("keyboard");
|
|
21
|
+
keyboard.style.display = keyboard.style.display === "flex" ? "none" : "flex";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function encryptText(text) {
|
|
25
|
+
return CryptoJS.AES.encrypt(text, encryptionKey).toString();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function handleKeyPress(keyElement) {
|
|
29
|
+
if (activeInput) {
|
|
30
|
+
let keyToAdd;
|
|
31
|
+
if (isShift) {
|
|
32
|
+
keyToAdd =
|
|
33
|
+
keyElement.getAttribute("data-shifted") ||
|
|
34
|
+
keyElement.innerText.toUpperCase();
|
|
35
|
+
} else if (isCapsLock) {
|
|
36
|
+
keyToAdd =
|
|
37
|
+
keyElement.getAttribute("data-shifted") ||
|
|
38
|
+
keyElement.innerText.toUpperCase();
|
|
39
|
+
} else {
|
|
40
|
+
keyToAdd = keyElement.getAttribute("data-normal") || keyElement.innerText;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// เข้ารหัสข้อความที่กด
|
|
44
|
+
const encryptedKey = encryptText(keyToAdd);
|
|
45
|
+
|
|
46
|
+
// เพิ่มข้อความที่เข้ารหัสลงใน input
|
|
47
|
+
activeInput.value += keyToAdd;
|
|
48
|
+
|
|
49
|
+
activeInput.setAttribute("data-encrypted-value", encryptedKey);
|
|
50
|
+
|
|
51
|
+
if (isShift && !isCapsLock) {
|
|
52
|
+
toggleShift();
|
|
53
|
+
}
|
|
54
|
+
// console.log("Encrypted input: ", activeInput.getAttribute("data-encrypted-value"));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function toggleCapsLock() {
|
|
59
|
+
isCapsLock = !isCapsLock;
|
|
60
|
+
const capsLockKeys = document.querySelectorAll(".capslock");
|
|
61
|
+
capsLockKeys.forEach((key) => key.classList.toggle("caps-active"));
|
|
62
|
+
|
|
63
|
+
document.querySelectorAll(".key").forEach((key) => {
|
|
64
|
+
const normalText = key.getAttribute("data-normal");
|
|
65
|
+
const shiftedText = key.getAttribute("data-shifted");
|
|
66
|
+
|
|
67
|
+
if (isCapsLock) {
|
|
68
|
+
if (shiftedText) {
|
|
69
|
+
key.innerText = shiftedText;
|
|
70
|
+
} else if (normalText && normalText.match(/[a-zA-Z]/)) {
|
|
71
|
+
key.innerText = normalText.toUpperCase();
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
if (normalText) {
|
|
75
|
+
key.innerText = normalText;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function toggleShift() {
|
|
82
|
+
isShift = !isShift;
|
|
83
|
+
const shiftKeys = document.querySelectorAll(".shift");
|
|
84
|
+
shiftKeys.forEach((key) => key.classList.toggle("shift-active"));
|
|
85
|
+
|
|
86
|
+
document.querySelectorAll(".key").forEach((key) => {
|
|
87
|
+
const normalText = key.getAttribute("data-normal");
|
|
88
|
+
const shiftedText = key.getAttribute("data-shifted");
|
|
89
|
+
|
|
90
|
+
if (isShift) {
|
|
91
|
+
if (shiftedText) {
|
|
92
|
+
key.innerText = shiftedText;
|
|
93
|
+
} else if (normalText && normalText.match(/[a-zA-Z]/)) {
|
|
94
|
+
key.innerText = normalText.toUpperCase();
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (normalText) {
|
|
98
|
+
key.innerText = normalText;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function backspace() {
|
|
105
|
+
if (activeInput && activeInput.value.length > 0) {
|
|
106
|
+
activeInput.value = activeInput.value.slice(0, -1);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function Tab() {
|
|
111
|
+
if (activeInput) {
|
|
112
|
+
let start = activeInput.selectionStart;
|
|
113
|
+
let end = activeInput.selectionEnd;
|
|
114
|
+
|
|
115
|
+
activeInput.value = activeInput.value.substring(0, start) + " " + activeInput.value.substring(end);
|
|
116
|
+
|
|
117
|
+
activeInput.selectionStart = activeInput.selectionEnd = start + 4;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// จัดการการลากคีย์บอร์ด
|
|
122
|
+
function startDrag(event) {
|
|
123
|
+
isDragging = true;
|
|
124
|
+
offsetX = event.clientX - document.getElementById("keyboard").offsetLeft;
|
|
125
|
+
offsetY = event.clientY - document.getElementById("keyboard").offsetTop;
|
|
126
|
+
|
|
127
|
+
document.addEventListener("mousemove", drag);
|
|
128
|
+
document.addEventListener("mouseup", () => {
|
|
129
|
+
isDragging = false;
|
|
130
|
+
document.removeEventListener("mousemove", drag);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function drag(event) {
|
|
135
|
+
if (isDragging) {
|
|
136
|
+
const keyboard = document.getElementById("keyboard");
|
|
137
|
+
keyboard.style.left = `${event.clientX - offsetX}px`;
|
|
138
|
+
keyboard.style.top = `${event.clientY - offsetY}px`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function switchLanguage() {
|
|
143
|
+
const numpadKeyboard = document.getElementById("numpad-keyboard");
|
|
144
|
+
const scrambledKeyboard = document.getElementById("scrambled-keyboard");
|
|
145
|
+
const engScramble = document.getElementById("english-Scramble");
|
|
146
|
+
const thaiScramble = document.getElementById("thai-Scramble");
|
|
147
|
+
|
|
148
|
+
// สลับค่า currentLanguage
|
|
149
|
+
currentLanguage = currentLanguage === "english" ? "thai" : "english";
|
|
150
|
+
|
|
151
|
+
// แสดงคีย์บอร์ดตามภาษา
|
|
152
|
+
document.getElementById("english-keyboard").style.display =
|
|
153
|
+
currentLanguage === "english" ? "block" : "none";
|
|
154
|
+
document.getElementById("thai-keyboard").style.display =
|
|
155
|
+
currentLanguage === "thai" ? "block" : "none";
|
|
156
|
+
|
|
157
|
+
// ซ่อนคีย์บอร์ดอื่นๆ
|
|
158
|
+
numpadKeyboard.style.display = "none";
|
|
159
|
+
scrambledKeyboard.style.display = "none";
|
|
160
|
+
thaiScramble.style.display = "none";
|
|
161
|
+
engScramble.style.display = "none";
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function login(event) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
|
|
167
|
+
// ดึงค่าที่เข้ารหัสจากฟอร์ม
|
|
168
|
+
const Username = document.getElementById("u___n___").value;
|
|
169
|
+
const Password = document.getElementById("p___w___").value;
|
|
170
|
+
|
|
171
|
+
// เข้ารหัสข้อมูลก่อนส่งไปยังเซิร์ฟเวอร์
|
|
172
|
+
// const encryptedu___n___ = encryptText(encryptedUsername);
|
|
173
|
+
const encryptedp___w___ = encryptText(Password);
|
|
174
|
+
|
|
175
|
+
const loginData = {
|
|
176
|
+
u___n___: Username,
|
|
177
|
+
p___w___: encryptedp___w___,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// ส่งข้อมูลที่เข้ารหัสไปยังเซิร์ฟเวอร์
|
|
181
|
+
const response = await fetch("https://login-gxrh.onrender.com/login", {
|
|
182
|
+
method: 'POST',
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': 'application/json',
|
|
185
|
+
},
|
|
186
|
+
body: JSON.stringify(loginData),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const data = await response.json();
|
|
190
|
+
|
|
191
|
+
if (data.token) {
|
|
192
|
+
alert("เข้าสู่ระบบสำเร็จ");
|
|
193
|
+
localStorage.setItem("token", data.token);
|
|
194
|
+
location.reload();
|
|
195
|
+
} else {
|
|
196
|
+
alert(data.message || "เกิดข้อผิดพลาด");
|
|
197
|
+
location.reload();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ปลี่ยนสีพื้นหลัง
|
|
202
|
+
function toggletap(event) {
|
|
203
|
+
const key = event.target;
|
|
204
|
+
key.style.backgroundColor = "#45a049";
|
|
205
|
+
|
|
206
|
+
setTimeout(() => {
|
|
207
|
+
key.style.backgroundColor = "#d3d3d3";
|
|
208
|
+
}, 100);
|
|
209
|
+
// console.log("Tap function");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function toggleEnter(event) {
|
|
213
|
+
// ตรวจสอบว่าเป็นการกดปุ่ม Enter
|
|
214
|
+
if (activeInput.value === "Enter") {
|
|
215
|
+
// ป้องกันการส่งฟอร์มที่เกิดจากการกด Enter
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
|
|
218
|
+
// เช็คว่า activeInput มีค่าและเป็นประเภท INPUT
|
|
219
|
+
if (activeInput && activeInput.tagName === "INPUT") {
|
|
220
|
+
// ส่งฟอร์มเมื่อกด Enter
|
|
221
|
+
activeInput.form.submit();
|
|
222
|
+
// console.log("Form submitted using Enter.");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function Numpad() {
|
|
228
|
+
const englishKeyboard = document.getElementById("english-keyboard");
|
|
229
|
+
const thaiKeyboard = document.getElementById("thai-keyboard");
|
|
230
|
+
const scrambledKeyboard = document.getElementById("scrambled-keyboard");
|
|
231
|
+
const numpadKeyboard = document.getElementById("numpad-keyboard");
|
|
232
|
+
const engScramble = document.getElementById("english-Scramble");
|
|
233
|
+
const thaiScramble = document.getElementById("thai-Scramble");
|
|
234
|
+
|
|
235
|
+
englishKeyboard.style.display = "none";
|
|
236
|
+
thaiKeyboard.style.display = "none";
|
|
237
|
+
scrambledKeyboard.style.display = "none";
|
|
238
|
+
thaiScramble.style.display = "none";
|
|
239
|
+
engScramble.style.display = "none";
|
|
240
|
+
|
|
241
|
+
if (numpadKeyboard) {
|
|
242
|
+
numpadKeyboard.style.display = "block";
|
|
243
|
+
} else {
|
|
244
|
+
alert("Numpad layout is not available");
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function Scramble() {
|
|
249
|
+
const englishKeyboard = document.getElementById("english-keyboard");
|
|
250
|
+
const thaiKeyboard = document.getElementById("thai-keyboard");
|
|
251
|
+
const scrambledKeyboard = document.getElementById("scrambled-keyboard");
|
|
252
|
+
const numpadKeyboard = document.getElementById("numpad-keyboard");
|
|
253
|
+
const engScramble = document.getElementById("english-Scramble");
|
|
254
|
+
const thaiScramble = document.getElementById("thai-Scramble");
|
|
255
|
+
|
|
256
|
+
// ซ่อนคีย์บอร์ดทุกตัวที่ไม่ใช่ Scrambled
|
|
257
|
+
englishKeyboard.style.display = "none";
|
|
258
|
+
thaiKeyboard.style.display = "none";
|
|
259
|
+
numpadKeyboard.style.display = "none";
|
|
260
|
+
thaiScramble.style.display = "none";
|
|
261
|
+
engScramble.style.display = "none";
|
|
262
|
+
|
|
263
|
+
if (scrambledKeyboard) {
|
|
264
|
+
scrambledKeyboard.style.display = "block";
|
|
265
|
+
scrambleKeys(); // เรียกฟังก์ชันเพื่อสุ่มตัวเลขบนคีย์บอร์ด
|
|
266
|
+
} else {
|
|
267
|
+
alert("Scramble layout is not available");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function scrambleKeys() {
|
|
272
|
+
// เลือกปุ่มทั้งหมดในคีย์บอร์ด "Scrambled" ยกเว้นปุ่ม backspace
|
|
273
|
+
const keys = document.querySelectorAll(
|
|
274
|
+
"#scrambled-keyboard .key:not(.backspace):not(.plus):not(.minus):not(.multiply):not(.divide):not(.modulo):not(.double-zero):not(.decimal):not(.equals)"
|
|
275
|
+
);
|
|
276
|
+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
|
|
277
|
+
shuffleArray(numbers); // เรียงลำดับตัวเลขแบบสุ่ม
|
|
278
|
+
|
|
279
|
+
keys.forEach((key, index) => {
|
|
280
|
+
key.textContent = numbers[index];
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ฟังก์ชัน scramble สำหรับภาษาไทยและภาษาอังกฤษ
|
|
285
|
+
function scrambleLanguage(language) {
|
|
286
|
+
const englishKeyboard = document.getElementById("english-keyboard");
|
|
287
|
+
const thaiKeyboard = document.getElementById("thai-keyboard");
|
|
288
|
+
const scrambledKeyboard = document.getElementById("scrambled-keyboard");
|
|
289
|
+
const numpadKeyboard = document.getElementById("numpad-keyboard");
|
|
290
|
+
const engScramble = document.getElementById("english-Scramble");
|
|
291
|
+
const thaiScramble = document.getElementById("thai-Scramble");
|
|
292
|
+
|
|
293
|
+
if (language === "thai") {
|
|
294
|
+
englishKeyboard.style.display = "none";
|
|
295
|
+
thaiKeyboard.style.display = "none";
|
|
296
|
+
engScramble.style.display = "none";
|
|
297
|
+
numpadKeyboard.style.display = "none";
|
|
298
|
+
scrambledKeyboard.style.display = "none";
|
|
299
|
+
thaiScramble.style.display = "block";
|
|
300
|
+
scrambleThaiKeys(); // ฟังก์ชันสำหรับภาษาไทย
|
|
301
|
+
} else if (language === "english") {
|
|
302
|
+
englishKeyboard.style.display = "none";
|
|
303
|
+
thaiKeyboard.style.display = "none";
|
|
304
|
+
engScramble.style.display = "block";
|
|
305
|
+
numpadKeyboard.style.display = "none";
|
|
306
|
+
scrambledKeyboard.style.display = "none";
|
|
307
|
+
thaiScramble.style.display = "none";
|
|
308
|
+
scrambleEnglishKeys(); // ฟังก์ชันสำหรับภาษาอังกฤษ
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// ฟังก์ชัน scramble สำหรับคีย์บอร์ดภาษาอังกฤษ
|
|
313
|
+
function scrambleEnglishKeys() {
|
|
314
|
+
const keys = document.querySelectorAll(
|
|
315
|
+
"#english-Scramble .key:not(.backspace):not(.capslock):not(.enter):not(.shift):not(.space-bar)"
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const englishAlphabet = "abcdefghijklmnopqrstuvwxyz".split("");
|
|
319
|
+
shuffleArray(englishAlphabet);
|
|
320
|
+
|
|
321
|
+
keys.forEach((key, index) => {
|
|
322
|
+
if (index < englishAlphabet.length) {
|
|
323
|
+
key.textContent = englishAlphabet[index];
|
|
324
|
+
key.setAttribute("data-normal", englishAlphabet[index]);
|
|
325
|
+
key.setAttribute("data-shifted", englishAlphabet[index].toUpperCase());
|
|
326
|
+
} else {
|
|
327
|
+
key.textContent = "";
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ฟังก์ชัน scramble สำหรับคีย์บอร์ดภาษาไทย
|
|
333
|
+
function scrambleThaiKeys() {
|
|
334
|
+
const keys = document.querySelectorAll(
|
|
335
|
+
"#thai-Scramble .key:not(.backspace):not(.capslock):not(.enter):not(.shift):not(.space-bar)"
|
|
336
|
+
);
|
|
337
|
+
const thaiAlphabet = "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮ".split(
|
|
338
|
+
""
|
|
339
|
+
);
|
|
340
|
+
shuffleArray(thaiAlphabet);
|
|
341
|
+
|
|
342
|
+
keys.forEach((key, index) => {
|
|
343
|
+
if (index < thaiAlphabet.length) {
|
|
344
|
+
key.textContent = thaiAlphabet[index];
|
|
345
|
+
key.setAttribute("data-normal", thaiAlphabet[index]);
|
|
346
|
+
key.setAttribute("data-shifted", thaiAlphabet[index]);
|
|
347
|
+
} else {
|
|
348
|
+
key.textContent = "";
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// ฟังก์ชันเพื่อสับเปลี่ยนตัวอักษร
|
|
354
|
+
function shuffleArray(array) {
|
|
355
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
356
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
357
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function changeDropdownName(name) {
|
|
362
|
+
const dropdownButton = document.getElementById("dropdownButton");
|
|
363
|
+
dropdownButton.textContent = name;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
367
|
+
document.querySelectorAll(".key").forEach((key) => {
|
|
368
|
+
key.addEventListener("click", (event) => {
|
|
369
|
+
if (key.classList.contains("capslock")) {
|
|
370
|
+
toggleCapsLock();
|
|
371
|
+
} else if (key.classList.contains("tab")) {
|
|
372
|
+
Tab();
|
|
373
|
+
} else if (key.classList.contains("backspace")) {
|
|
374
|
+
backspace();
|
|
375
|
+
} else if (key.classList.contains("shift")) {
|
|
376
|
+
toggleShift();
|
|
377
|
+
} else if (key.classList.contains("enter")) {
|
|
378
|
+
toggleEnter();
|
|
379
|
+
} else if (key.classList.contains("toggle-lang")) {
|
|
380
|
+
switchLanguage();
|
|
381
|
+
} else {
|
|
382
|
+
handleKeyPress(key);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const loginButton = document.getElementById("login-button");
|
|
388
|
+
const toggleKeyboards = document.getElementById("toggleKeyboard");
|
|
389
|
+
|
|
390
|
+
loginButton.addEventListener("click", login);
|
|
391
|
+
toggleKeyboards.addEventListener("click", toggleKeyboard);
|
|
392
|
+
|
|
393
|
+
document
|
|
394
|
+
.getElementById("switch-toggle")
|
|
395
|
+
.addEventListener("click", switchLanguage);
|
|
396
|
+
document.getElementById("numpad-toggle").addEventListener("click", Numpad);
|
|
397
|
+
document
|
|
398
|
+
.getElementById("scramble-toggle")
|
|
399
|
+
.addEventListener("click", Scramble);
|
|
400
|
+
document
|
|
401
|
+
.getElementById("scramble-toggle-thai")
|
|
402
|
+
.addEventListener("click", () => scrambleLanguage("thai"));
|
|
403
|
+
document
|
|
404
|
+
.getElementById("scramble-toggle-eng")
|
|
405
|
+
.addEventListener("click", () => scrambleLanguage("english"));
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
/*
|
|
409
|
+
// ฟังก์ชันหลักในการป้องกันการจับภาพหน้าจอในเบราว์เซอร์
|
|
410
|
+
function preventScreenCapture() {
|
|
411
|
+
const overrideFunction = (target, method, handler) => {
|
|
412
|
+
if (target && target[method]) {
|
|
413
|
+
const original = target[method];
|
|
414
|
+
target[method] = function (...args) {
|
|
415
|
+
handler();
|
|
416
|
+
return Promise.reject("Screen capture blocked.");
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// ตรวจสอบความพร้อมใช้งานของ navigator.mediaDevices และ getDisplayMedia
|
|
422
|
+
if (navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia) {
|
|
423
|
+
// ป้องกันการใช้งาน getDisplayMedia
|
|
424
|
+
overrideFunction(navigator.mediaDevices, 'getDisplayMedia', () => {
|
|
425
|
+
console.log('Screen capture attempt detected via getDisplayMedia!');
|
|
426
|
+
showBlackScreen(true);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ตรวจสอบความพร้อมใช้งานของ navigator.mediaDevices และ getUserMedia
|
|
431
|
+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
|
432
|
+
// ป้องกันการใช้งาน getUserMedia
|
|
433
|
+
overrideFunction(navigator.mediaDevices, 'getUserMedia', () => {
|
|
434
|
+
console.log('Screen capture attempt detected via getUserMedia!');
|
|
435
|
+
showBlackScreen(true);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ป้องกันคีย์ลัด PrintScreen, Win+Shift+S และอื่นๆ
|
|
440
|
+
document.addEventListener('keyup', (event) => {
|
|
441
|
+
const encryptedText = CryptoJS.AES.encrypt(event.key, encryptionKey).toString();
|
|
442
|
+
console.log("ข้อความที่เข้ารหัส:", encryptedText);
|
|
443
|
+
|
|
444
|
+
// ถอดรหัสข้อความ
|
|
445
|
+
const bytes = CryptoJS.AES.decrypt(encryptedText, encryptionKey);
|
|
446
|
+
const decryptedText = bytes.toString(CryptoJS.enc.Utf8);
|
|
447
|
+
console.log("ข้อความที่ถอดรหัส:", decryptedText);
|
|
448
|
+
// console.log('Key pressed:', event.key);
|
|
449
|
+
if (event.key === 'PrintScreen' || (event.key === 'S' && event.shiftKey && event.metaKey)) {
|
|
450
|
+
console.log('Blocked PrintScreen or Win+Shift+S key.');
|
|
451
|
+
event.preventDefault();
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// ตรวจจับการใช้งาน screen capture ของ third-party logger
|
|
456
|
+
if (navigator.mediaDevices) {
|
|
457
|
+
const originalGetUserMedia = navigator.mediaDevices.getUserMedia;
|
|
458
|
+
navigator.mediaDevices.getUserMedia = (constraints) => {
|
|
459
|
+
if (constraints && constraints.video && constraints.video.mediaSource === 'screen') {
|
|
460
|
+
console.warn('Screen capture attempt detected!');
|
|
461
|
+
return Promise.reject("Screen capture blocked.");
|
|
462
|
+
}
|
|
463
|
+
return originalGetUserMedia.call(navigator.mediaDevices, constraints);
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// ฟังก์ชันเพื่อแสดงหน้าจอสีดำ
|
|
469
|
+
function showBlackScreen(autoClose = false) {
|
|
470
|
+
const blackScreen = document.createElement('div');
|
|
471
|
+
blackScreen.style.position = 'fixed';
|
|
472
|
+
blackScreen.style.top = 0;
|
|
473
|
+
blackScreen.style.left = 0;
|
|
474
|
+
blackScreen.style.width = '100%';
|
|
475
|
+
blackScreen.style.height = '100%';
|
|
476
|
+
blackScreen.style.backgroundColor = '#000';
|
|
477
|
+
blackScreen.style.zIndex = '9999';
|
|
478
|
+
blackScreen.style.display = 'flex';
|
|
479
|
+
blackScreen.style.alignItems = 'center';
|
|
480
|
+
blackScreen.style.justifyContent = 'center';
|
|
481
|
+
blackScreen.style.color = '#FFF';
|
|
482
|
+
blackScreen.style.fontSize = '24px';
|
|
483
|
+
blackScreen.textContent = 'Screen capture blocked!';
|
|
484
|
+
|
|
485
|
+
document.body.appendChild(blackScreen);
|
|
486
|
+
|
|
487
|
+
if (autoClose) {
|
|
488
|
+
setTimeout(() => {
|
|
489
|
+
blackScreen.remove();
|
|
490
|
+
}, 3000);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// เรียกใช้งานฟังก์ชัน
|
|
495
|
+
preventScreenCapture();
|
|
496
|
+
// preventKeyLogger();
|
|
497
|
+
|
|
498
|
+
// สร้าง Timer เพื่อตรวจสอบการทำงานเป็นระยะ
|
|
499
|
+
function createTimer(interval, callback) {
|
|
500
|
+
return setInterval(callback, interval);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function clearTimer(timerId) {
|
|
504
|
+
clearInterval(timerId);
|
|
505
|
+
} // ตัวอย่างการใช้งาน Timer
|
|
506
|
+
|
|
507
|
+
const screenCaptureTimer = createTimer(1000, () => {
|
|
508
|
+
console.log('Timer ticked - Checking screen capture status');
|
|
509
|
+
// เพิ่มฟังก์ชันการตรวจจับหรือจัดการเหตุการณ์ที่ต้องการ
|
|
510
|
+
preventScreenCapture(); // เรียกใช้งานฟังก์ชันการป้องกันการจับภาพหน้าจอ
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// ยกเลิก Timer หลังจาก 10 วินาที
|
|
514
|
+
setTimeout(() => clearTimer(screenCaptureTimer), 10000);*/
|