mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
refactoring
This commit is contained in:
parent
4dfbf5aa17
commit
6e9a3222ce
@ -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,13 +131,16 @@ 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 __pasteAsKeysFromClipboard = function() {
|
||||
window.navigator.clipboard.readText().then(__pasteAsKeys);
|
||||
};
|
||||
|
||||
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;
|
||||
[...clipboard_text].forEach(function(ch) {
|
||||
[...text].forEach(function(ch) {
|
||||
var codes = __chars_to_codes[ch];
|
||||
if (codes) {
|
||||
codes_count += codes.length;
|
||||
@ -158,7 +161,7 @@ function Hid() {
|
||||
$("pak-led").className = "led-pak-typing";
|
||||
$("pak-led").title = "Autotyping...";
|
||||
|
||||
tools.debug("Paste-as-keys:", clipboard_text);
|
||||
tools.debug("Paste-as-keys:", text);
|
||||
|
||||
var index = 0;
|
||||
var iterate = function() {
|
||||
@ -177,7 +180,6 @@ function Hid() {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
__init__();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user