-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbookmarklet.js
More file actions
1 lines (1 loc) · 3.24 KB
/
bookmarklet.js
File metadata and controls
1 lines (1 loc) · 3.24 KB
1
javascript:(function() { var input = ''; var delay = '100'; var index = -1; var mainDivId = '00novnccustompastetool0947-maindiv'; var textId = '00novnccustompastetool0947-textinput'; var numId = '00novnccustompastetool0947-numinput'; function updateUserInput(event) { event.preventDefault(); } function paste(event) { event.preventDefault(); var userInput = document.getElementById(textId); input = userInput.value; var userNumInput = document.getElementById(numId); delay = Number(userNumInput.value); if (!delay) { alert('Cannot proceed: delay number is invalid.'); return close(); } close(event); setTimeout(tick, 500); } function close(event) { event.preventDefault(); var mainDiv = document.getElementById(mainDivId); document.body.removeChild(mainDiv); } function showGui() { var div = document.createElement('div'); div.id = mainDivId; div.style.position = 'fixed'; div.style.zIndex = '9999999999'; div.style.backgroundColor = 'rgb(221 221 221 / 90%)'; div.style.top = '0'; div.style.left = '0'; div.style.right = '0'; div.style.padding = '8px'; div.style.height = '168px'; div.innerHTML = '<b>Paste your text</b><br>' + 'Note: Use your mouse for copying and pasting because the KVM console ' + 'snatches all input and this is the only sane work-around.' + '<br>'; var textInput = document.createElement('textarea'); textInput.id = textId; textInput.onkeydown = updateUserInput; textInput.style.display = 'block'; textInput.style.width = '100%'; textInput.style.marginBottom = '8px'; var inputDesc = document.createElement('label'); inputDesc.innerHTML = 'Per-key delay in ms: '; inputDesc.title = 'Sending keys too fast can cause issues (such as ' + 'skipped keys); the delay helps alleviate this.'; var numInput = document.createElement('input'); numInput.title = inputDesc.title; numInput.setAttribute('type', 'number'); numInput.setAttribute('min', '1'); numInput.setAttribute('max', '100000'); numInput.value = delay; numInput.id = numId; var ok = document.createElement('button'); ok.innerText = 'Paste'; ok.onclick = paste; ok.style.margin = '8px'; var cancel = document.createElement('button'); cancel.innerText = 'Cancel'; cancel.onclick = close; div.append(textInput); div.append(inputDesc); div.append(numInput); div.append(document.createElement('br')); div.append(cancel); div.append(ok); document.body.append(div); } function encodeAndSendKey(character) { var code = character.charCodeAt(); if (code === '\r'.charCodeAt()) { return; } if (code === '\n'.charCodeAt()) { rfb.sendKey(XK_Return, 1); rfb.sendKey(XK_Return, 0); return; } var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/); if (needs_shift) { rfb.sendKey(XK_Shift_L, 1); } rfb.sendKey(code, 1); rfb.sendKey(code, 0); if (needs_shift) { rfb.sendKey(XK_Shift_L, 0); } } function tick() { if (++index >= input.length) { return; } encodeAndSendKey(input[index]); setTimeout(tick, delay); } showGui(); })();