Last active
November 21, 2021 16:29
-
-
Save mhoran/8bb51edd39e79478b57629614d9fc2b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name noVNC Paste | |
// @include https://portal.arpnetworks.com/noVNC/console?* | |
// @version 1.0 | |
// ==/UserScript== | |
function sendString () { | |
var str = prompt("Please enter a string to paste"); | |
if (!str) | |
return; | |
f(str.split("")); | |
function f(t) { | |
const XK_Shift_L = 65505; | |
var character = t.shift(); | |
var i=[]; | |
var code = character.charCodeAt(); | |
var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/); | |
if (needs_shift) { | |
unsafeWindow.rfb.sendKey(XK_Shift_L,1); | |
} | |
unsafeWindow.rfb.sendKey(code,1); | |
unsafeWindow.rfb.sendKey(code,0); | |
if (needs_shift) { | |
unsafeWindow.rfb.sendKey(XK_Shift_L,0); | |
} | |
if (t.length > 0) { | |
setTimeout(function() {f(t);}, 10); | |
} | |
} | |
} | |
unsafeWindow.sendString = exportFunction(sendString, unsafeWindow); | |
var btn = document.createElement( 'input' ); | |
with( btn ) { | |
setAttribute( 'onclick', 'sendString()' ); | |
setAttribute( 'value', 'Paste' ); | |
setAttribute( 'type', 'button' ); | |
} | |
document.getElementById( 'noVNC_buttons' ).prepend( btn ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment