MENU

为SolusVM的noVNC增加粘贴功能

• July 8, 2019 • Read: 406 • 瞎折腾

在SolusVM的主控目录的:

/usr/local/solusvm/www/admincp/include/util.js
/usr/local/solusvm/www/include/util.js

增加以下内容:

function paste() {
    return !(function() {
        var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
        var o = [];
        for (let letter of t) {
            o.push(letter);
            console.log(letter);
        }

        function f() {
            var character = o.shift();
            var i = [];
            var code = character.charCodeAt();
            var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1
            var shift = XK_Shift_L; // To help with minification             
            if (needs_shift) {
                rfb.sendKey(shift, 1);
            }
            rfb.sendKey(code, 1);
            rfb.sendKey(code, 0);
            if (needs_shift) {
                rfb.sendKey(shift, 0);
            }
            if (o.length > 0) {
                setTimeout(f, 10);
            }
        }
        f();
    })();
}
window.onload = function() {
    addbutton = document.getElementById('noVNC_buttons');
    addbutton.innerHTML += ('<input type="button" value="粘贴" id="sendpasteButton" onclick="paste()" style="display: inline;">');
};

参考:
https://gist.github.com/croepha/7b53f211ae4be3c526c3
https://gist.github.com/byjg/a6378edb420a1c654c5f27bb494ca1c8

Last Modified: July 12, 2019
Archives QR Code
QR Code for this page
Tipping QR Code
Leave a Comment

已有 1 条评论
  1. 感谢分享