Chat Box Section

Creates a separated section for the chat box

当前为 2025-01-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Chat Box Section
  3. // @namespace Violentmonkey Scripts
  4. // @match https://web.simple-mmo.com/*
  5. // @grant none
  6. // @license GPL-v3
  7. // @version 1.4.5
  8. // @author Freaky Fingers
  9. // @description Creates a separated section for the chat box
  10. // ==/UserScript==
  11. //Startup Sequence Variables
  12. let smmoChat = null
  13.  
  14. document.querySelectorAll("[x-init]").forEach(xinit => {
  15. if (xinit.outerHTML.includes("chat:false,chatSrc:'about:blank;'")){
  16. return smmoChat = xinit
  17. }
  18. })
  19.  
  20. if (!smmoChat) return;
  21. smmoChat.style.cssText = "position: fixed; height: 100%; margin-top: 4rem";
  22.  
  23. //Script Variables
  24. const chatWidth = 20
  25. const gameParent = document.body.querySelector('.h-screen.flex.overflow-hidden.bg-gray-100')
  26. const newButton = document.createElement("button")
  27. const newHTML = document.createElement("div")
  28. const chatBox = document.getElementById("chatBox")
  29. const chatButton = document.getElementById("show_hide_chat_btn")
  30.  
  31. chatBox.style.cssText = `position: relative; height: calc(100% - 4rem); width: ${chatWidth}vw; padding: 0rem`;
  32. chatButton.style.display = 'none';
  33.  
  34. //Functions
  35. function ButtonPos() {
  36. if (window.innerWidth > 1740) {
  37. try {newButton.style.removeProperty('left');
  38. newButton.style.removeProperty('bottom');}
  39. finally{newButton.style.right = "5rem";
  40. newButton.style.top = "0.6rem"; return}
  41. }
  42. newButton.style.removeProperty('top');
  43. newButton.style.removeProperty('right');
  44. newButton.style.left = "17rem";
  45. newButton.style.bottom = "1rem"
  46. }
  47. window.addEventListener('resize',ButtonPos);
  48. const observer = new MutationObserver(() => {
  49. if (!newButton) return;
  50. ButtonPos();
  51. observer.disconnect()
  52. });
  53.  
  54. observer.observe(document.body, {
  55. childList: true,
  56. });
  57.  
  58. newButton.onmousedown = () => {
  59. newHTML.style.display = newHTML.style.display === "none" ? "block" : "none";
  60. chatButton.click();
  61. };
  62.  
  63. //Main Script
  64. newButton.innerHTML = "Show/Hide Chat";
  65. newButton.style.cssText = "position: fixed; padding: 0.5rem; background-color: #000; border: 2px solid #C0C0C0; right: 5rem; top: 0.6rem; border-radius: 0.5rem; color: #C0C0C0; z-index: 30; font-size: 0.8rem";
  66. newHTML.style.cssText = `background-color: rgb(17 17 17 / var(--tw-bg-opacity)); height: 94vh; width: ${chatWidth}vw; float: right; position: sticky; z-index: 1; display: none`;
  67.  
  68. document.onkeydown = event => {
  69. if (event.code === 'NumpadEnter') {
  70. newButton.onmousedown()
  71. }
  72. }
  73.  
  74. if(docCookies.getItem('show_chat') === 'true') {
  75. newHTML.style.display = "block"
  76. }
  77.  
  78. gameParent.style.cssText = `z-index: 2; position: relative`;
  79.  
  80. document.getElementById("app").insertAdjacentElement(`afterbegin`, newHTML);
  81. document.querySelector(".web-app-container").insertAdjacentElement(`afterbegin`, newButton);
  82. newHTML.appendChild(smmoChat);