Vultr console paste

Add a Paste button to Vultr console

  1. // ==UserScript==
  2. // @name Vultr console paste
  3. // @name:zh Vultr 控制台 粘贴功能
  4. // @version 0.3
  5. // @description Add a Paste button to Vultr console
  6. // @description:zh 给Vultr的控制台添加一个粘贴按钮
  7. // @author Sam0230
  8. // @match *://my.vultr.com/*/novnc/*
  9. // @grant none
  10. // @run-at document-start
  11. // @namespace https://gf.qytechs.cn/users/305841
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. let ASCIIString = function ASCIIChar(str) {
  17. return (str == str.match(/[\t-~]*/)[0]);
  18. }
  19. let clearNonASCIIChar = function clearNonASCIIChar(str) {
  20. let result = str.match(/[\t-~]/g);
  21. if (!result) {
  22. result = [];
  23. }
  24. return result.join("");
  25. }
  26. let sendString = (function () {
  27. if (window.sendString) {
  28. return window.sendString;
  29. }
  30. window.sendStringWorking = false;
  31. let sendStringTimeoutId = -1;
  32. window.sendString = function sendString(str, onfinish, noWorkingAuth) {
  33. if (noWorkingAuth != "___noWorkingAuth___noWorkingAuth___noWorkingAuth___noWorkingAuth___noWorkingAuth___") {
  34. if (window.sendStringWorking) {
  35. return false;
  36. }
  37. rfb._keyboard.ungrab();
  38. rfb._mouse.ungrab();
  39. }
  40. window.sendStringWorking = true;
  41. rfb._keyboard._allKeysUp();
  42. let KeyCode = str.charCodeAt(), needShift = ('~!@#$%^&*()_+{}|:"<>?'.indexOf(str[0]) != -1);
  43. if (KeyCode == "\n".charCodeAt()) {
  44. KeyCode = XK_Return;
  45. }
  46. if (KeyCode == "\t".charCodeAt()) {
  47. KeyCode = XK_Tab;
  48. }
  49. if (needShift) {
  50. rfb.sendKey(XK_Shift_L, true);
  51. }
  52. rfb.sendKey(KeyCode);
  53. if (needShift) {
  54. rfb.sendKey(XK_Shift_L, false);
  55. }
  56. if (str.length != 1) {
  57. for (let i = 0; i <= 27; i++) {
  58. setTimeout(function () {
  59. rfb._keyboard._allKeysUp();
  60. }, i);
  61. }
  62. sendStringTimeoutId = setTimeout(sendString.bind(this, str.slice(1), onfinish, "___noWorkingAuth___noWorkingAuth___noWorkingAuth___noWorkingAuth___noWorkingAuth___"), 30);
  63. } else {
  64. window.sendStringWorking = false;
  65. rfb._keyboard.grab();
  66. rfb._mouse.grab();
  67. if (onfinish && onfinish.constructor == Function.prototype.constructor) {
  68. onfinish();
  69. }
  70. }
  71. return function stop () {
  72. clearTimeout(sendStringTimeoutId);
  73. window.sendStringWorking = false;
  74. rfb._keyboard.grab();
  75. rfb._mouse.grab();
  76. if (onfinish && onfinish.constructor == Function.prototype.constructor) {
  77. onfinish();
  78. }
  79. };
  80. }
  81. return window.sendString;
  82. })();
  83. let pasteButton = document.createElement("input"), textarea = document.createElement("textarea"), CapsLockButton = document.createElement("input");
  84. pasteButton.type = "button";
  85. pasteButton.value = "Paste";
  86. pasteButton.id = "pasteButton";
  87. pasteButton.style.display = "inline";
  88. pasteButton.disabled = true;
  89. textarea.placeholder = "Paste";
  90. textarea.id = "pasteTextarea";
  91. textarea.style.display = "inline";
  92. textarea.style.position = "relative";
  93. textarea.style.top = "4px";
  94. textarea.style.height = "13px";
  95. textarea.cols = "6";
  96. textarea.style.border = "none";
  97. textarea.style.resize = "none";
  98. textarea.onfocus = function () {
  99. rfb._keyboard.ungrab();
  100. rfb._mouse.ungrab();
  101. }
  102. textarea.onblur = function () {
  103. rfb._keyboard.grab();
  104. rfb._mouse.grab();
  105. }
  106. textarea.oninput = function () {
  107. textarea.value = clearNonASCIIChar(textarea.value);
  108. }
  109. CapsLockButton.type = "button";
  110. CapsLockButton.value = "CapsLock";
  111. CapsLockButton.id = "CapsLockButton";
  112. CapsLockButton.style.display = "inline";
  113. CapsLockButton.disabled = true;
  114. let addButton = function addButton() {
  115. if (!document.getElementById("noVNC_buttons")) {
  116. setTimeout(addButton, 25);
  117. return;
  118. }
  119. document.getElementById("noVNC_buttons").appendChild(textarea);
  120. document.getElementById("noVNC_buttons").appendChild(pasteButton);
  121. document.getElementById("noVNC_buttons").appendChild(CapsLockButton);
  122. let enableButton = function enableButton() {
  123. if (!document.getElementById("noVNC_canvas") || document.getElementById("noVNC_canvas").height == 20) {
  124. setTimeout(enableButton, 25);
  125. return;
  126. }
  127. pasteButton.disabled = false;
  128. pasteButton.onclick = function () {
  129. let self = pasteButton.onclick;
  130. textarea.value = clearNonASCIIChar(textarea.value);
  131. let text = textarea.value;
  132. textarea.value = "";
  133. textarea.disabled = true;
  134. textarea.placeholder = "Busy";
  135. pasteButton.value = "Stop";
  136. let stop = sendString(text, function () {
  137. pasteButton.onclick = self;
  138. pasteButton.value = "Paste";
  139. textarea.disabled = false;
  140. textarea.placeholder = "Paste";
  141. });
  142. pasteButton.onclick = function () {
  143. stop();
  144. }
  145. }
  146. CapsLockButton.disabled = false;
  147. CapsLockButton.onclick = function () {
  148. rfb.sendKey(XK_Caps_Lock, 1);
  149. }
  150. }
  151. setTimeout(enableButton, 0);
  152. }
  153. setTimeout(addButton, 0);
  154. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址