59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
// ==UserScript==
|
|
// @name noVNC:Paste-For-Proxmox
|
|
// @namespace http://tampermonkey.net/
|
|
// @version 0.3a
|
|
// @description Pastes text into a noVNC window (for use with Proxmox specifically)
|
|
// @author LukasEndigo
|
|
// @match https://*.mynetname.net/*
|
|
// @require http://code.jquery.com/jquery-3.3.1.min.js
|
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=proxmox.com
|
|
// @grant none
|
|
// ==/UserScript==
|
|
const delay = 500;
|
|
(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);
|
|
})
|
|
|
|
|
|
})()
|