Skip to content

Instantly share code, notes, and snippets.

@sdrapha
Forked from amunchet/noVNCCopyPasteProxmox.user.js
Last active November 15, 2023 06:11
Show Gist options
  • Save sdrapha/a45b0f56eee84c780073329e73bafa26 to your computer and use it in GitHub Desktop.
Save sdrapha/a45b0f56eee84c780073329e73bafa26 to your computer and use it in GitHub Desktop.

Revisions

  1. sdrapha revised this gist Nov 15, 2023. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions noVNCCopyPasteProxmox.user.js
    Original file line number Diff line number Diff line change
    @@ -46,9 +46,11 @@ const delay = 1

    $("canvas").on("mousedown", (e)=>{
    if(e.button == 2){ // Right Click
    navigator.clipboard.readText().then(text =>{
    window.sendString(text)
    })
    let text = prompt("Enter text to paste:");
    if (text != null) window.sendString(text);
    // navigator.clipboard.readText().then(text =>{
    // window.sendString(text)
    // })
    }
    })
    }, 1000);
  2. @amunchet amunchet renamed this gist Oct 10, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @amunchet amunchet created this gist Oct 10, 2022.
    58 changes: 58 additions & 0 deletions noVNCCopyPasteProxmox.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    // ==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);
    })


    })()