smoothretro82

Chat toggle button for tw.2s4.me

Jan 13th, 2026
83
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. // ==================================
  2. // Floating Chat HUD
  3. // ==================================
  4.  
  5. let chatHudElement = null;
  6.  
  7. function createChatHUD() {
  8. if (chatHudElement) return chatHudElement;
  9.  
  10. // Create HUD container
  11. const hud = document.createElement('div');
  12. hud.id = 'chat-hud';
  13. Object.assign(hud.style, {
  14. position: 'fixed',
  15. bottom: '20px',
  16. right: '20px',
  17. width: '300px',
  18. backgroundColor: '#222',
  19. color: '#fff',
  20. border: '1px solid #444',
  21. borderRadius: '8px',
  22. boxShadow: '2px 2px 5px rgba(0,0,0,0.3)',
  23. fontFamily: 'monospace',
  24. zIndex: '9999',
  25. userSelect: 'none'
  26. });
  27.  
  28. // Header
  29. const header = document.createElement('div');
  30. header.id = 'chat-hud-header';
  31. header.textContent = 'Chat HUD';
  32. Object.assign(header.style, {
  33. padding: '5px 10px',
  34. backgroundColor: '#111',
  35. cursor: 'grab',
  36. borderRadius: '8px 8px 0 0',
  37. display: 'flex',
  38. justifyContent: 'space-between',
  39. alignItems: 'center'
  40. });
  41.  
  42. // Close button
  43. const closeBtn = document.createElement('span');
  44. closeBtn.textContent = 'X';
  45. Object.assign(closeBtn.style, { cursor: 'pointer', fontWeight: 'bold' });
  46. closeBtn.addEventListener('click', () => {
  47. hud.remove();
  48. chatHudElement = null;
  49. });
  50. header.appendChild(closeBtn);
  51. hud.appendChild(header);
  52.  
  53. // Content
  54. const content = document.createElement('div');
  55. content.style.padding = '10px';
  56. content.style.display = 'flex';
  57. content.style.flexDirection = 'column';
  58. content.style.gap = '5px';
  59.  
  60. // Toggle button
  61. const toggleBtn = document.createElement('button');
  62. toggleBtn.textContent = 'Toggle Chat';
  63. toggleBtn.style.padding = '4px 6px';
  64. toggleBtn.style.cursor = 'pointer';
  65.  
  66. toggleBtn.addEventListener('click', () => {
  67. const msgContainer = document.querySelector('.msgcontainer');
  68. if (msgContainer) {
  69. msgContainer.classList.toggle('hidden');
  70. }
  71. });
  72.  
  73. content.appendChild(toggleBtn);
  74. hud.appendChild(content);
  75.  
  76. document.body.appendChild(hud);
  77. chatHudElement = hud;
  78.  
  79. // Dragging logic
  80. let isDragging = false;
  81. let offsetX, offsetY;
  82.  
  83. header.addEventListener('mousedown', (e) => {
  84. if (e.target === closeBtn) return;
  85. isDragging = true;
  86. offsetX = e.clientX - hud.getBoundingClientRect().left;
  87. offsetY = e.clientY - hud.getBoundingClientRect().top;
  88. header.style.cursor = 'grabbing';
  89. });
  90.  
  91. document.addEventListener('mousemove', (e) => {
  92. if (!isDragging) return;
  93. hud.style.left = e.clientX - offsetX + 'px';
  94. hud.style.top = e.clientY - offsetY + 'px';
  95. hud.style.bottom = 'auto';
  96. hud.style.right = 'auto';
  97. hud.style.position = 'fixed';
  98. });
  99.  
  100. document.addEventListener('mouseup', () => {
  101. isDragging = false;
  102. header.style.cursor = 'grab';
  103. });
  104.  
  105. return hud;
  106. }
  107.  
  108. // Initialize the chat HUD
  109. createChatHUD();
  110.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment