Advertisement
Guest User

Untitled

a guest
Apr 18th, 2024
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. // ==UserScript==
  2. // @name UNIT3D Chatbox QoL
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description QoL features for UNIT3D chatbox brought to you by none other than GPT. This script is 100% written by GPT with no manual input whatsoever.
  6. // @match theldu.net
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. const chatboxID = '#chatbox__messages-create';
  14. const EMOJI_TRIGGER_HTML = `<div style="cursor: pointer; font-size: 24px;">😊</div>`;
  15. const EMOJI_PANEL_HTML = `<div style="position: absolute; display: flex; background: transparent; border: none;
  16. padding: 5px; z-index: 10000; left: 35px; top: 0px; align-items: center;">
  17. <span style="cursor: pointer;">😀</span> <span style="cursor: pointer;">🙁</span>
  18. <span style="cursor: pointer;">😆</span> <span style="cursor: pointer;">😅</span>
  19. <span style="cursor: pointer;">😂</span> <span style="cursor: pointer;">🤣</span>
  20. <span style="cursor: pointer;">😍</span> <span style="cursor: pointer;">😝</span>
  21. <span style="cursor: pointer;">😴</span> <span style="cursor: pointer;">🤮</span>
  22. <span style="cursor: pointer;">🤦‍♂️</span> <span style="cursor: pointer;">❤️</span>
  23. <span style="cursor: pointer;">🖤</span></div>`;
  24. const BBCODES_PANEL_HTML = `<div id="bbCodesPanel" style="position: absolute; display: flex; background: transparent; border: none;
  25. padding: 5px; z-index: 9998; left: 35px; top: 0px; align-items: center;">
  26. <span style="cursor: pointer; margin-right: 10px;" data-bbcode="[b][/b]">[B]</span>
  27. <span style="cursor: pointer; margin-right: 10px;" data-bbcode="[i][/i]">[I]</span>
  28. <span style="cursor: pointer; margin-right: 10px;" data-bbcode="[u][/u]">[U]</span>
  29. <span style="cursor: pointer; margin-right: 10px;" data-bbcode="[url][/url]">[URL]</span>
  30. <span style="cursor: pointer; margin-right: 10px;" data-bbcode="[img][/img]">[IMG]</span></div>`;
  31.  
  32. function setupChatFeatures(chatbox) {
  33. const container = document.createElement('div');
  34. container.style.position = 'relative';
  35. container.style.display = 'inline-block';
  36. chatbox.parentNode.insertBefore(container, chatbox.nextSibling);
  37.  
  38. const emojiTrigger = document.createElement('div');
  39. emojiTrigger.innerHTML = EMOJI_TRIGGER_HTML;
  40. container.appendChild(emojiTrigger);
  41.  
  42. const emojiPanel = document.createElement('div');
  43. emojiPanel.innerHTML = EMOJI_PANEL_HTML;
  44. emojiPanel.style.display = 'none';
  45. container.appendChild(emojiPanel);
  46.  
  47. const bbCodesPanel = document.createElement('div');
  48. bbCodesPanel.innerHTML = BBCODES_PANEL_HTML;
  49. container.appendChild(bbCodesPanel);
  50.  
  51. emojiTrigger.addEventListener('click', function() {
  52. const isEmojiVisible = emojiPanel.style.display === 'none';
  53. emojiPanel.style.display = isEmojiVisible ? 'flex' : 'none';
  54. bbCodesPanel.style.display = isEmojiVisible ? 'none' : 'flex';
  55. });
  56.  
  57. document.addEventListener('click', function(event) {
  58. if (!emojiPanel.contains(event.target) && !emojiTrigger.contains(event.target)) {
  59. emojiPanel.style.display = 'none';
  60. bbCodesPanel.style.display = 'flex';
  61. }
  62. });
  63.  
  64. emojiPanel.querySelectorAll('span').forEach(function(span) {
  65. span.addEventListener('click', function() {
  66. const emoji = span.textContent;
  67. chatbox.value += emoji + ' ';
  68. chatbox.focus();
  69. emojiPanel.style.display = 'none';
  70. });
  71. });
  72.  
  73. bbCodesPanel.querySelectorAll('span').forEach(function(span) {
  74. span.addEventListener('click', function() {
  75. const bbCode = span.getAttribute('data-bbcode');
  76. if (bbCode === "[img][/img]" || bbCode === "[url][/url]") {
  77. autoCompleteAndPaste(bbCode, chatbox);
  78. } else {
  79. insertBBCode(chatbox, bbCode);
  80. }
  81. });
  82. });
  83. }
  84.  
  85. function autoCompleteAndPaste(tag, chatbox) {
  86. navigator.clipboard.readText().then(clipText => {
  87. let newContent = clipText.trim().length > 0 ?
  88. (tag.includes("[img]") ? `[img]${clipText}[/img]` : `[url=${clipText}]${clipText}[/url]`) :
  89. tag;
  90. chatbox.value += newContent;
  91. // Adjust cursor position to be between the tags
  92. if (clipText.trim().length > 0) {
  93. const pos = newContent.indexOf(']') + 1;
  94. chatbox.setSelectionRange(chatbox.value.length - pos, chatbox.value.length - pos);
  95. } else {
  96. const startPos = chatbox.value.length - (newContent.length - newContent.indexOf(']') - 1);
  97. const endPos = startPos + (newContent.lastIndexOf('[') - newContent.indexOf(']') - 1);
  98. chatbox.setSelectionRange(startPos, endPos);
  99. }
  100. chatbox.focus();
  101. }).catch(err => {
  102. console.error('Failed to read clipboard contents:', err);
  103. chatbox.value += tag;
  104. const startPos = chatbox.value.length - (tag.length - tag.indexOf(']') - 1);
  105. const endPos = startPos + (tag.lastIndexOf('[') - tag.indexOf(']') - 1);
  106. chatbox.setSelectionRange(startPos, endPos);
  107. chatbox.focus();
  108. });
  109. }
  110.  
  111. function insertBBCode(chatbox, bbCode) {
  112. const textSelected = chatbox.value.substring(chatbox.selectionStart, chatbox.selectionEnd);
  113. const startTag = bbCode.substring(0, bbCode.indexOf(']') + 1);
  114. const endTag = bbCode.substring(bbCode.lastIndexOf('['));
  115. if (textSelected.length > 0) {
  116. const newText = startTag + textSelected + endTag;
  117. chatbox.value = chatbox.value.substring(0, chatbox.selectionStart) + newText + chatbox.value.substring(chatbox.selectionEnd);
  118. const newPos = chatbox.selectionStart + newText.length - endTag.length;
  119. chatbox.setSelectionRange(newPos, newPos);
  120. } else {
  121. chatbox.value += startTag + endTag;
  122. const newPos = chatbox.value.length - endTag.length;
  123. chatbox.setSelectionRange(newPos, newPos);
  124. }
  125. chatbox.focus();
  126. }
  127.  
  128. function checkAndSetup() {
  129. const chatbox = document.querySelector(chatboxID);
  130. if (chatbox) {
  131. setupChatFeatures(chatbox);
  132. } else {
  133. console.error('Chatbox not found: Ensure the chatbox ID is correct.');
  134. setTimeout(checkAndSetup, 100); // Check again in 100ms
  135. }
  136. }
  137.  
  138. checkAndSetup(); // Start the setup process
  139. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement