Last active
June 25, 2024 21:04
-
-
Save amunchet/4cfaf0274f3d238946f9f8f94fa9ee02 to your computer and use it in GitHub Desktop.
Copy/Paste for noVNC Proxmox
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 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 | |
navigator.clipboard.readText().then(text =>{ | |
window.sendString(text) | |
}) | |
} | |
}) | |
}, 1000); | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello all,
![macfr](https://private-user-images.githubusercontent.com/11626108/337932575-04ffecdc-8344-4c1e-aa6d-7ead053e7a3d.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk0MTc2MjYsIm5iZiI6MTcxOTQxNzMyNiwicGF0aCI6Ii8xMTYyNjEwOC8zMzc5MzI1NzUtMDRmZmVjZGMtODM0NC00YzFlLWFhNmQtN2VhZDA1M2U3YTNkLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI2VDE1NTUyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBkZDU5N2E5MThmNzg0Y2M3NjBmMmU2MGM0MTAwYTAzYzhlNjUwYzk2ZmI1MDNmNzFhNjI4NzQ4NWE1MzgyN2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.mlph7s--sA9d_1ilti5mazQgqsaQiIMRWcuHkc48G_0)
Thank you for this excellent script !
I forked your script to adapt french mac keyboard like this one :
I have to work more to be able to add all the keys but it's a good start.
Working key in french mac keyboard :
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890*=-_+&"(;/
Not working for now :
:)[]{}!\'
.....Thank you too @flightless22, I used your code too.