smoothretro1982

color message sender 1.0 (V.3 Update)

Mar 11th, 2026 (edited)
63
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. (function() {
  2. if (document.getElementById('colorHUD')) return;
  3.  
  4. // --- HUD Container ---
  5. const hud = document.createElement('div');
  6. hud.id = 'colorHUD';
  7. hud.style.cssText = `
  8. position: fixed;
  9. top: 20px;
  10. right: 20px;
  11. width: 380px;
  12. background: #111;
  13. color: #fff;
  14. border-radius: 6px;
  15. padding: 10px;
  16. font-family: monospace;
  17. z-index: 999999;
  18. box-shadow: 0 0 15px #000;
  19. user-select: none;
  20. font-size: 12px;
  21. `;
  22.  
  23. hud.innerHTML = `
  24. <input type="text" id="colorMsg" placeholder="Type message..." maxlength="1000" style="
  25. width: 100%; padding: 6px; margin-bottom: 8px; background:#222; border:1px solid #444; color:#fff; border-radius:3px;">
  26.  
  27. <div style="margin-bottom:8px; display:flex; align-items:center; gap:10px;">
  28. <div style="display:flex; align-items:center; gap:5px;">
  29. Pick Color: <input type="color" id="spectrumPicker" value="#ff0000" style="width:30px; height:24px; border:none; background:none; cursor:pointer;">
  30. </div>
  31. <div style="flex-grow:1;">
  32. Font size: <input type="number" id="fontSize" min="10" max="50" value="14" style="width:45px; background:#222; color:#fff; border:1px solid #444;">
  33. </div>
  34. </div>
  35.  
  36. <div style="margin-bottom:8px; display:flex; gap:4px;">
  37. <button id="sendColorBtn" style="flex:1; padding:5px; background:#0b7; color:#000; font-weight:bold; border:none; border-radius:3px; cursor:pointer;">Send</button>
  38. <button id="copyColorBtn" style="flex:1; padding:5px; background:#77f; color:#fff; font-weight:bold; border:none; border-radius:3px; cursor:pointer;">Copy</button>
  39. <button id="resetPaletteBtn" style="flex:1; padding:5px; background:#f70; color:#000; font-weight:bold; border:none; border-radius:3px; cursor:pointer;">Reset</button>
  40. <button id="randomColorsBtn" style="flex:1; padding:5px; background:#f0f; color:#fff; font-weight:bold; border:none; border-radius:3px; cursor:pointer;">Random</button>
  41. </div>
  42.  
  43. <div id="spectrumGrid" style="display:flex; height:12px; margin-bottom:10px; border-radius:2px; overflow:hidden; cursor:crosshair; border:1px solid #444;"></div>
  44. <div id="letterColorGrid" style="display:flex; flex-wrap:wrap; gap:3px; margin-bottom:8px; min-height:30px;"></div>
  45. <div id="colorPreview" style="margin-top:5px; min-height:25px; word-break:break-word; border-top:1px solid #333; padding-top:8px;"></div>
  46. `;
  47.  
  48. const closeBtn = document.createElement('button');
  49. closeBtn.textContent = '×';
  50. closeBtn.style.cssText = `position: absolute; top: 5px; right: 5px; background: #900; color: #fff; border: none; border-radius: 3px; width: 22px; height: 22px; cursor: pointer; font-weight: bold;`;
  51. closeBtn.onclick = () => hud.remove();
  52. hud.appendChild(closeBtn);
  53. document.body.appendChild(hud);
  54.  
  55. const input = document.getElementById('colorMsg');
  56. const spectrumPicker = document.getElementById('spectrumPicker');
  57. const spectrumGrid = document.getElementById('spectrumGrid');
  58. const letterColorGrid = document.getElementById('letterColorGrid');
  59. const preview = document.getElementById('colorPreview');
  60. const fontSizeInput = document.getElementById('fontSize');
  61.  
  62. let letterColors = [];
  63.  
  64. for (let i = 0; i <= 360; i += 10) {
  65. const color = `hsl(${i}, 100%, 50%)`;
  66. const div = document.createElement('div');
  67. div.style.flex = "1";
  68. div.style.backgroundColor = color;
  69. div.draggable = true;
  70. div.addEventListener('dragstart', e => e.dataTransfer.setData('text/plain', rgbToHex(div.style.backgroundColor)));
  71. spectrumGrid.appendChild(div);
  72. }
  73.  
  74. function rgbToHex(rgb) {
  75. const res = rgb.match(/\d+/g);
  76. return "#" + res.map(x => parseInt(x).toString(16).padStart(2, '0')).join('');
  77. }
  78.  
  79. function renderLetterSelectors() {
  80. letterColorGrid.innerHTML = '';
  81. letterColors = letterColors.slice(0, input.value.length);
  82. while (letterColors.length < input.value.length) letterColors.push(spectrumPicker.value);
  83.  
  84. for (let i = 0; i < input.value.length; i++) {
  85. const letter = document.createElement('div');
  86. letter.textContent = input.value[i] === ' ' ? '\u00A0' : input.value[i];
  87. letter.style.cssText = `width:22px; height:22px; text-align:center; border:1px solid #555; border-radius:3px; background:${letterColors[i]}; color:#fff; cursor:pointer; text-shadow: 1px 1px 2px #000; font-weight:bold;`;
  88.  
  89. letter.addEventListener('dragover', e => e.preventDefault());
  90. letter.addEventListener('drop', e => {
  91. const color = e.dataTransfer.getData('text/plain');
  92. letterColors[i] = color;
  93. letter.style.background = color;
  94. updatePreview();
  95. });
  96.  
  97. letter.onclick = () => {
  98. letterColors[i] = spectrumPicker.value;
  99. letter.style.background = spectrumPicker.value;
  100. updatePreview();
  101. };
  102.  
  103. letterColorGrid.appendChild(letter);
  104. }
  105. }
  106.  
  107. function updatePreview() {
  108. preview.innerHTML = '';
  109. const size = fontSizeInput.value + 'px';
  110. for (let i = 0; i < input.value.length; i++) {
  111. const span = document.createElement('span');
  112. span.style.color = letterColors[i];
  113. span.style.fontSize = size;
  114. span.textContent = input.value[i];
  115. preview.appendChild(span);
  116. }
  117. }
  118.  
  119. // --- OPTIMIZED MESSAGE GENERATOR ---
  120. function generateMessage() {
  121. let msg = '';
  122. let lastColor = '';
  123.  
  124. for (let i = 0; i < input.value.length; i++) {
  125. let currentColor = letterColors[i];
  126. // Only start a new tag if the color changes
  127. if (currentColor !== lastColor) {
  128. if (lastColor !== '') msg += `<end>`;
  129. msg += `<start ${currentColor}>`;
  130. lastColor = currentColor;
  131. }
  132. msg += input.value[i];
  133. }
  134. if (msg !== '') msg += `<end>`;
  135. return msg;
  136. }
  137.  
  138. function sendToChatInput() {
  139. const msg = generateMessage();
  140. const chatInput = document.getElementById('chatmsg');
  141. const sendBtn = document.getElementById('sendmsg');
  142.  
  143. if (chatInput && sendBtn) {
  144. // Forcefully remove site character limits for the current session
  145. chatInput.removeAttribute('maxlength');
  146. chatInput.value = msg;
  147.  
  148. // Trigger site event so it recognizes the text change
  149. chatInput.dispatchEvent(new Event('input', { bubbles: true }));
  150. sendBtn.click();
  151. } else {
  152. console.warn("Chat elements not found!");
  153. }
  154. }
  155.  
  156. input.addEventListener('input', () => { renderLetterSelectors(); updatePreview(); });
  157. fontSizeInput.addEventListener('input', updatePreview);
  158.  
  159. document.getElementById('sendColorBtn').onclick = sendToChatInput;
  160. document.getElementById('copyColorBtn').onclick = () => navigator.clipboard.writeText(generateMessage());
  161.  
  162. document.getElementById('randomColorsBtn').onclick = () => {
  163. for (let i = 0; i < letterColors.length; i++) {
  164. const randHue = Math.floor(Math.random() * 360);
  165. const tempDiv = document.createElement('div');
  166. tempDiv.style.color = `hsl(${randHue}, 100%, 50%)`;
  167. document.body.appendChild(tempDiv);
  168. letterColors[i] = rgbToHex(getComputedStyle(tempDiv).color);
  169. document.body.removeChild(tempDiv);
  170. }
  171. renderLetterSelectors();
  172. updatePreview();
  173. };
  174.  
  175. document.getElementById('resetPaletteBtn').onclick = () => {
  176. letterColors = letterColors.map(() => "#ffffff");
  177. renderLetterSelectors();
  178. updatePreview();
  179. };
  180.  
  181. let isDragging = false, offsetX, offsetY;
  182. hud.onmousedown = (e) => { if(e.target === hud) { isDragging = true; offsetX = e.clientX - hud.offsetLeft; offsetY = e.clientY - hud.offsetTop; } };
  183. window.onmousemove = (e) => { if(isDragging) { hud.style.left = (e.clientX - offsetX) + 'px'; hud.style.top = (e.clientY - offsetY) + 'px'; } };
  184. window.onmouseup = () => isDragging = false;
  185.  
  186. renderLetterSelectors();
  187. })();
Advertisement
Comments
Add Comment
Please, Sign In to add comment