Skip to content

Instantly share code, notes, and snippets.

@sgharms
Forked from croepha/DigitalOcean_NoVNC_Paste.js
Created November 13, 2017 02:17
Show Gist options
  • Save sgharms/3fb3ffd1b4d83877d989ec13d851ab14 to your computer and use it in GitHub Desktop.
Save sgharms/3fb3ffd1b4d83877d989ec13d851ab14 to your computer and use it in GitHub Desktop.
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
function f() {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1
var shift = XK_Shift_L; // To help with minification
function key(keycode, down) {
i=i.concat(RFB.messages.keyEvent(keycode, down));
}
if (needs_shift) {
key(shift,1);
}
key(code,1);
key(code,0);
if (needs_shift) {
key(shift,0);
}
rfb._sock.send(i);
if (t.length > 0) {
setTimeout(f, 10);
}
}
f();
})();
// Minified version:
!function(){function t(){function n(t,e){s=s.concat(RFB.messages.keyEvent(t,e))}var o=e.shift(),s=[],i=o.charCodeAt(),c=-1!=='!@#$%^&*()_+{}:"<>?~|'.indexOf(o),r=XK_Shift_L;c&&n(r,1),n(i,1),n(i,0),c&&n(r,0),rfb._sock.send(s),e.length>0&&setTimeout(t,10)}var e=prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");t()}();
// This is an alternate version that will open a box on ctrl+shift+v or command+shift+v
// this version might work better on browsers that block prompt from console
(function(){
var shift_down = false;
var ctrl_down = false;
var super_down = false;
var v_down = false;
$(document).keydown(function(e) {
if (e.which == 17) { ctrl_down = true; }
else if (e.which == 16) { shift_down = true; }
else if (e.which == 91) { super_down = true; }
else if (e.which == 86) { v_down = true; }
if (v_down && shift_down && (super_down || ctrl_down) ) {
ctrl_down = false;
shift_down = false;
super_down = false;
var t = prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split("");
function f() {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = "!@#$%^&*()_+{}:\"<>?~|".indexOf(character) !== -1
var shift = XK_Shift_L; // To help with minification
function key(keycode, down) {
i=i.concat(RFB.messages.keyEvent(keycode, down));
}
if (needs_shift) {
key(shift,1);
}
key(code,1);
key(code,0);
if (needs_shift) {
key(shift,0);
}
rfb._sock.send(i);
if (t.length > 0) {
setTimeout(f, 10);
}
}
setTimeout(f, 10);
}
});
$(document).keyup(function(e) {
if (e.which == 17) { ctrl_down = false; }
else if (e.which == 16) { shift_down = false; }
else if (e.which == 91) { super_down = false; }
else if (e.which == 86) { v_down = false; }
});
})();
// Minified version:
(function(){var d=!1,b=!1,c=!1,f=!1;$(document).keydown(function(a){17==a.which?b=!0:16==a.which?d=!0:91==a.which?c=!0:86==a.which&&(f=!0);if(f&&d&&(c||b)){c=d=b=!1;var g=prompt("Enter text to be sent to console, (This wont send the enter keystroke)").split(""),h=function(){function a(b,c){d=d.concat(RFB.messages.keyEvent(b,c))}var e=g.shift(),d=[],b=e.charCodeAt(),e=-1!=='!@#$%^&*()_+{}:"<>?~|'.indexOf(e),c=XK_Shift_L;e&&a(c,1);a(b,1);a(b,0);e&&a(c,0);rfb._sock.send(d);0<g.length&&setTimeout(h,10)};
setTimeout(h,10)}});$(document).keyup(function(a){17==a.which?b=!1:16==a.which?d=!1:91==a.which?c=!1:86==a.which&&(f=!1)})})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment