Skip to content

Instantly share code, notes, and snippets.

@ergoz
Forked from amunchet/noVNCCopyPasteProxmox.user.js
Last active April 12, 2025 10:09
Show Gist options
  • Save ergoz/8a1dd8d45796f45cf3a24d888198e90f to your computer and use it in GitHub Desktop.
Save ergoz/8a1dd8d45796f45cf3a24d888198e90f to your computer and use it in GitHub Desktop.
Copy/Paste for noVNC Proxmox
  1. Install Tampermonkey for your browser (https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en)
  2. Open up this script in "Raw" (or go to this url: https://gist.github.com/amunchet/4cfaf0274f3d238946f9f8f94fa9ee02/raw/0b84970f89e1f282f09b86d46227eda71178c040/noVNCCopyPasteProxmox.user.js)
  3. Click install
  4. [Optional] if you have a non-US keyboard layout, you may need to modify the script.
  5. Copy some text to your clipboard (highlight some text and Ctrl + C)
  6. Open up your Promox console
  7. Right click to paste the text into the console (you may need to restart your browser, depending on your tampermonkey installation)

Note: if you use LXC containers, you do not need this script, as you can just copy and paste normally from that terminal.

// ==UserScript==
// @name noVNC Paste for Proxmox
// @namespace http://tampermonkey.net/
// @version 0.2a
// @description Pastes text into a noVNC window (for use with Proxmox specifically)
// @author Chester Enright
// @match https://*
// @include /^.*novnc.*/
// @require http://code.jquery.com/jquery-3.3.1.min.js
// @grant none
// ==/UserScript==
const delay = 1
;(function () {
'use strict'
window.sendString = function(text) {
var el = document.getElementById("canvas-id")
text.split("").forEach(x=>{
setTimeout(()=>{
var needs_shift = x.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/)
let evt
if (needs_shift) {
evt = new KeyboardEvent("keydown", {keyCode: 16})
el.dispatchEvent(evt)
evt = new KeyboardEvent("keydown", {key: x, shiftKey: true})
el.dispatchEvent(evt)
evt = new KeyboardEvent("keyup", {keyCode: 16})
el.dispatchEvent(evt)
}else{
evt = new KeyboardEvent("keydown", {key: x})
}
el.dispatchEvent(evt)
}, delay)
})
}
$(document).ready(function() {
setTimeout(()=>{
console.log("Starting up noVNC Copy/Paste (for Proxmox)")
$("canvas").attr("id", "canvas-id")
$("canvas").on("mousedown", (e)=>{
if(e.button == 2){ // Right Click
// clipboard version
//
// navigator.clipboard.readText().then(text =>{
// window.sendString(text)
//})
// Native js promt version
//
let text = prompt("Enter text to paste:");
if (text != null) window.sendString(text);
}
})
}, 1000);
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment