js_lis 2.0.3 → 2.0.4

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.
Files changed (2) hide show
  1. package/VirtualKeyboard.js +54 -1
  2. package/package.json +1 -1
@@ -13,6 +13,7 @@ export class VirtualKeyboard {
13
13
  this.shiftActive = false;
14
14
  this.capsLockActive = false;
15
15
  this.isScrambled = false;
16
+ this.isVirtualKeyboardActive = false; // Flag to track VK operations
16
17
 
17
18
  // Maintain plaintext buffers per input (not stored in DOM). DOM will store only encrypted text.
18
19
  this.inputPlaintextBuffers = new WeakMap();
@@ -191,6 +192,30 @@ export class VirtualKeyboard {
191
192
  true
192
193
  );
193
194
 
195
+ // Add real keyboard input listeners to handle encryption
196
+ document.addEventListener("input", (e) => {
197
+ const target = e.target;
198
+ if ((target.tagName === "INPUT" || target.tagName === "TEXTAREA") && target === this.currentInput) {
199
+ // Only handle real keyboard input if it's not coming from virtual keyboard operations
200
+ if (!this.isVirtualKeyboardActive) {
201
+ this.handleRealKeyboardInput(target);
202
+ }
203
+ }
204
+ });
205
+
206
+ document.addEventListener("keydown", (e) => {
207
+ const target = e.target;
208
+ if ((target.tagName === "INPUT" || target.tagName === "TEXTAREA") && target === this.currentInput) {
209
+ // Handle special keys that might not trigger input event
210
+ if ((e.key === "Backspace" || e.key === "Delete") && !this.isVirtualKeyboardActive) {
211
+ // Wait for the input event to handle the updated value
212
+ setTimeout(() => {
213
+ this.handleRealKeyboardInput(target);
214
+ }, 0);
215
+ }
216
+ }
217
+ });
218
+
194
219
  const toggle = document.getElementById("toggle");
195
220
  if (toggle) {
196
221
  toggle.addEventListener("click", this.toggle.bind(this));
@@ -307,6 +332,10 @@ export class VirtualKeyboard {
307
332
  // [2]
308
333
  async handleKeyPress(keyPressed) {
309
334
  if (!this.currentInput) return;
335
+
336
+ // Set flag to indicate virtual keyboard is active
337
+ this.isVirtualKeyboardActive = true;
338
+
310
339
  const start = this.currentInput.selectionStart;
311
340
  const end = this.currentInput.selectionEnd;
312
341
  const buffer = this.getCurrentBuffer();
@@ -321,7 +350,10 @@ export class VirtualKeyboard {
321
350
  return char.toLowerCase();
322
351
  };
323
352
 
324
- if (!keyPressed) return console.error("Invalid key pressed.");
353
+ if (!keyPressed) {
354
+ this.isVirtualKeyboardActive = false;
355
+ return console.error("Invalid key pressed.");
356
+ }
325
357
 
326
358
  if (keyPressed === "scr" || keyPressed === "scrambled") {
327
359
  if (this.currentLayout === "en") {
@@ -375,6 +407,7 @@ export class VirtualKeyboard {
375
407
  key.classList.toggle("active", this.isScrambled);
376
408
  });
377
409
  }
410
+ this.isVirtualKeyboardActive = false;
378
411
  return;
379
412
  }
380
413
 
@@ -570,6 +603,9 @@ export class VirtualKeyboard {
570
603
  this.currentInput.focus();
571
604
  const event = new Event("input", { bubbles: true });
572
605
  this.currentInput.dispatchEvent(event);
606
+
607
+ // Reset flag after virtual keyboard operation is complete
608
+ this.isVirtualKeyboardActive = false;
573
609
  }
574
610
 
575
611
  // [3]
@@ -607,6 +643,23 @@ export class VirtualKeyboard {
607
643
  this.currentInput.value = isPassword ? maskChar.repeat(buffer.length) : buffer;
608
644
  }
609
645
 
646
+ // Handle real keyboard input and encrypt it
647
+ handleRealKeyboardInput(input) {
648
+ if (!input) return;
649
+
650
+ // Get the current value from the input
651
+ const currentValue = input.value;
652
+
653
+ // Update the plaintext buffer with the real keyboard input
654
+ this.inputPlaintextBuffers.set(input, currentValue);
655
+
656
+ // Encrypt and store in data-encrypted attribute
657
+ this.updateDomEncrypted(input, currentValue);
658
+
659
+ // console.log("Real keyboard input captured and encrypted for:", input.id || input.name || "unnamed input");
660
+ // console.log("Input type:", input.type, "Value length:", currentValue.length);
661
+ }
662
+
610
663
  // Helper: encrypt and store ciphertext in DOM attribute
611
664
  updateDomEncrypted(input, plaintext) {
612
665
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_lis",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"