refactoring

This commit is contained in:
Devaev Maxim 2018-09-09 20:13:03 +03:00
parent 4dfbf5aa17
commit 6e9a3222ce

View File

@ -43,7 +43,7 @@ function Hid() {
if (window.navigator.clipboard && window.navigator.clipboard.readText) { if (window.navigator.clipboard && window.navigator.clipboard.readText) {
__chars_to_codes = __buildCharsToCodes(); __chars_to_codes = __buildCharsToCodes();
tools.setOnClick($("pak-button"), __pasteAsKeys); tools.setOnClick($("pak-button"), __pasteAsKeysFromClipboard);
} else { } else {
$("pak-button").title = $("pak-led").title = "Your browser does not support the Clipboard API.\nUse Google Chrome or Chromium."; $("pak-button").title = $("pak-led").title = "Your browser does not support the Clipboard API.\nUse Google Chrome or Chromium.";
} }
@ -131,13 +131,16 @@ function Hid() {
return chars_to_codes; return chars_to_codes;
}; };
var __pasteAsKeys = function() { var __pasteAsKeysFromClipboard = function() {
window.navigator.clipboard.readText().then(function(clipboard_text) { window.navigator.clipboard.readText().then(__pasteAsKeys);
clipboard_text = clipboard_text.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex };
if (clipboard_text) {
var __pasteAsKeys = function(text) {
text = text.replace(/[^\x00-\x7F]/g, ""); // eslint-disable-line no-control-regex
if (text) {
var clipboard_codes = []; var clipboard_codes = [];
var codes_count = 0; var codes_count = 0;
[...clipboard_text].forEach(function(ch) { [...text].forEach(function(ch) {
var codes = __chars_to_codes[ch]; var codes = __chars_to_codes[ch];
if (codes) { if (codes) {
codes_count += codes.length; codes_count += codes.length;
@ -158,7 +161,7 @@ function Hid() {
$("pak-led").className = "led-pak-typing"; $("pak-led").className = "led-pak-typing";
$("pak-led").title = "Autotyping..."; $("pak-led").title = "Autotyping...";
tools.debug("Paste-as-keys:", clipboard_text); tools.debug("Paste-as-keys:", text);
var index = 0; var index = 0;
var iterate = function() { var iterate = function() {
@ -177,7 +180,6 @@ function Hid() {
} }
}); });
} }
});
}; };
__init__(); __init__();