Universal Draggable Live Chat Overlay

Adds a draggable overlay for live chat from any URL

  1. // ==UserScript==
  2. // @name Universal Draggable Live Chat Overlay
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Adds a draggable overlay for live chat from any URL
  6. // @grant GM_addStyle
  7. // @grant GM_setValue
  8. // @grant GM_getValue
  9. // @match *://*/*
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Inject CSS for the draggable chat
  16. GM_addStyle(`
  17. #draggable-chat {
  18. position: fixed;
  19. bottom: 10px;
  20. right: 10px;
  21. width: 300px;
  22. height: 400px;
  23. background: rgba(0, 0, 0, 0.8);
  24. color: #fff;
  25. border-radius: 8px;
  26. overflow: auto;
  27. z-index: 9999;
  28. box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  29. }
  30. #draggable-chat-header {
  31. background: #333;
  32. padding: 5px;
  33. cursor: move;
  34. text-align: center;
  35. color: #fff;
  36. font-weight: bold;
  37. }
  38. #draggable-chat-content {
  39. padding: 10px;
  40. height: calc(100% - 40px);
  41. overflow: auto;
  42. }
  43. #draggable-chat iframe {
  44. width: 100%;
  45. height: 100%;
  46. border: none;
  47. }
  48. #draggable-chat input {
  49. width: calc(100% - 22px);
  50. padding: 5px;
  51. margin: 5px;
  52. border: none;
  53. border-radius: 5px;
  54. }
  55. #draggable-chat button {
  56. padding: 5px;
  57. border: none;
  58. border-radius: 5px;
  59. background: #007bff;
  60. color: #fff;
  61. cursor: pointer;
  62. }
  63. #draggable-chat button:hover {
  64. background: #0056b3;
  65. }
  66. `);
  67.  
  68. // Create the draggable chat container
  69. const chatContainer = document.createElement('div');
  70. chatContainer.id = 'draggable-chat';
  71. chatContainer.innerHTML = `
  72. <div id="draggable-chat-header">Live Chat
  73. <button id="chat-submit">Submit</button>
  74. <input type="text" id="chat-url" placeholder="Enter chat URL" />
  75. </div>
  76. <div id="draggable-chat-content">
  77. <iframe id="chat-iframe" src="" frameborder="0"></iframe>
  78. </div>
  79. `;
  80. document.body.appendChild(chatContainer);
  81.  
  82. // Make the chat container draggable
  83. const header = document.getElementById('draggable-chat-header');
  84. let isDragging = false;
  85. let offsetX, offsetY;
  86.  
  87. header.addEventListener('mousedown', (e) => {
  88. isDragging = true;
  89. offsetX = e.clientX - chatContainer.getBoundingClientRect().left;
  90. offsetY = e.clientY - chatContainer.getBoundingClientRect().top;
  91. });
  92.  
  93. document.addEventListener('mousemove', (e) => {
  94. if (isDragging) {
  95. chatContainer.style.left = (e.clientX - offsetX) + 'px';
  96. chatContainer.style.top = (e.clientY - offsetY) + 'px';
  97. }
  98. });
  99.  
  100. document.addEventListener('mouseup', () => {
  101. isDragging = false;
  102. });
  103.  
  104. // Handle chat URL submission
  105. const submitButton = document.getElementById('chat-submit');
  106. const chatUrlInput = document.getElementById('chat-url');
  107. const chatIframe = document.getElementById('chat-iframe');
  108.  
  109. submitButton.addEventListener('click', () => {
  110. const url = chatUrlInput.value;
  111. if (url) {
  112. chatIframe.src = url;
  113. }
  114. });
  115. })();

QingJ © 2025

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