summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-09-09 20:13:03 +0300
committerDevaev Maxim <[email protected]>2018-09-09 20:13:03 +0300
commit6e9a3222ce566f6430caad541c2695255cb06d7c (patch)
treeec8c973827c3d3c39c338f00a828be5726f94c89 /kvmd
parent4dfbf5aa17ef3c55417923748f4bbcf93be638fe (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/web/js/hid.js96
1 files changed, 49 insertions, 47 deletions
diff --git a/kvmd/web/js/hid.js b/kvmd/web/js/hid.js
index 520c4552..ca535157 100644
--- a/kvmd/web/js/hid.js
+++ b/kvmd/web/js/hid.js
@@ -43,7 +43,7 @@ function Hid() {
if (window.navigator.clipboard && window.navigator.clipboard.readText) {
__chars_to_codes = __buildCharsToCodes();
- tools.setOnClick($("pak-button"), __pasteAsKeys);
+ tools.setOnClick($("pak-button"), __pasteAsKeysFromClipboard);
} else {
$("pak-button").title = $("pak-led").title = "Your browser does not support the Clipboard API.\nUse Google Chrome or Chromium.";
}
@@ -131,53 +131,55 @@ function Hid() {
return chars_to_codes;
};
- var __pasteAsKeys = function() {
- window.navigator.clipboard.readText().then(function(clipboard_text) {
- clipboard_text = clipboard_text.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
- if (clipboard_text) {
- var clipboard_codes = [];
- var codes_count = 0;
- [...clipboard_text].forEach(function(ch) {
- var codes = __chars_to_codes[ch];
- if (codes) {
- codes_count += codes.length;
- clipboard_codes.push(codes);
- }
- });
+ var __pasteAsKeysFromClipboard = function() {
+ window.navigator.clipboard.readText().then(__pasteAsKeys);
+ };
- var confirm_msg = (
- "You are going to automatically type " + codes_count
- + " characters from the system clipboard."
- + " It will take " + (__codes_delay * codes_count * 2 / 1000) + " seconds.<br>"
- + "<br>Are you sure you want to continue?<br>"
- );
-
- ui.confirm(confirm_msg).then(function(ok) {
- if (ok) {
- $("pak-button").disabled = true;
- $("pak-led").className = "led-pak-typing";
- $("pak-led").title = "Autotyping...";
-
- tools.debug("Paste-as-keys:", clipboard_text);
-
- var index = 0;
- var iterate = function() {
- __emitShortcut(clipboard_codes[index]).then(function() {
- ++index;
- if (index < clipboard_codes.length && __ws) {
- iterate();
- } else {
- $("pak-button").disabled = false;
- $("pak-led").className = "led-off";
- $("pak-led").title = "";
- }
- });
- };
- iterate();
- }
- });
- }
- });
+ var __pasteAsKeys = function(text) {
+ text = text.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
+ if (text) {
+ var clipboard_codes = [];
+ var codes_count = 0;
+ [...text].forEach(function(ch) {
+ var codes = __chars_to_codes[ch];
+ if (codes) {
+ codes_count += codes.length;
+ clipboard_codes.push(codes);
+ }
+ });
+
+ var confirm_msg = (
+ "You are going to automatically type " + codes_count
+ + " characters from the system clipboard."
+ + " It will take " + (__codes_delay * codes_count * 2 / 1000) + " seconds.<br>"
+ + "<br>Are you sure you want to continue?<br>"
+ );
+
+ ui.confirm(confirm_msg).then(function(ok) {
+ if (ok) {
+ $("pak-button").disabled = true;
+ $("pak-led").className = "led-pak-typing";
+ $("pak-led").title = "Autotyping...";
+
+ tools.debug("Paste-as-keys:", text);
+
+ var index = 0;
+ var iterate = function() {
+ __emitShortcut(clipboard_codes[index]).then(function() {
+ ++index;
+ if (index < clipboard_codes.length && __ws) {
+ iterate();
+ } else {
+ $("pak-button").disabled = false;
+ $("pak-led").className = "led-off";
+ $("pak-led").title = "";
+ }
+ });
+ };
+ iterate();
+ }
+ });
+ }
};
__init__();