Chat Box Section

Creates a separated section for the chat box

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

  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.1
  8. // @author Freaky Fingers
  9. // @description Creates a separated section for the chat box
  10. // ==/UserScript==
  11. //Startup Sequence Variables
  12. let allxinits = document.querySelectorAll("[x-init]")
  13. let smmoChat = null
  14.  
  15. allxinits.forEach(xinit => {
  16. if (xinit.outerHTML.includes("chat:false,chatSrc:'about:blank;'")){
  17. smmoChat = xinit
  18. }
  19. })
  20.  
  21. if (smmoChat == null) return;
  22. smmoChat.style = "position: fixed; height: 100%";
  23.  
  24. //Config Variables
  25. let chatWidth = 20
  26. let chatHeight = 94
  27.  
  28. //Script Variables
  29. let newButton = document.createElement("div")
  30. let newHTML = document.createElement("chatArea")
  31. let show_hide_chat_btns = document.getElementsByClassName("mr-1")
  32. let chatBox = document.getElementById("chatBox")
  33. let chatButton = document.getElementById("show_hide_chat_btn")
  34. let buttonAttrib = null
  35.  
  36. chatBox.style = `position: relative; height: ${chatHeight}%; width: ${chatWidth}vw; padding: 0rem`;
  37. chatButton.style.visibility = 'hidden';
  38.  
  39. //Functions
  40.  
  41. function findButtonAttrib() {
  42. for (let i = 0; i < show_hide_chat_btns.length; i++) {
  43. if (show_hide_chat_btns[i].outerHTML.includes("!chat") == false) return;
  44. buttonAttrib = show_hide_chat_btns[i].outerHTML
  45. }
  46. }
  47.  
  48. function show_hide_chat (){
  49. findButtonAttrib();
  50. if (buttonAttrib.includes("display: none")) {
  51. newHTML.style.display = "none";
  52. chatButton.click()
  53. } else {
  54. newHTML.style.display = "block";
  55. chatButton.click()
  56. }
  57. }
  58.  
  59. //Main Script
  60. newButton.innerHTML = `<button id="newChatButton" style="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">Show/Hide Chat</button>`;
  61. newButton.onmousedown = show_hide_chat;
  62. newHTML.innerHTML = `
  63. <div id="chatParent">
  64. <section id="chatHeader"></section>
  65. <section id="chatSection"></section>
  66. </div>
  67. `; //create new div
  68. newHTML.style = `background-color: #0000; height: ${chatHeight}vh; width: ${chatWidth}vw; float: right; position: sticky; z-index: 1; display: none`; //Style new div
  69.  
  70. document.addEventListener('keydown', function (event) {
  71. if (event.code === 'NumpadEnter') {
  72. show_hide_chat()
  73. }
  74. })
  75.  
  76. window.addEventListener('load', function () {
  77. findButtonAttrib();
  78. if (buttonAttrib.includes("display: none")) {
  79. newHTML.style.display = "block"
  80. }
  81. });
  82.  
  83. document.getElementsByClassName("h-screen flex overflow-hidden bg-gray-100")[0].style = `z-index: 2; position: relative`; //Increases the z-index of the main game, thereby fixing a bug of being unable interact with the Buy Item popout
  84. document.getElementById("app").insertBefore(newHTML, document.getElementsByClassName("h-screen flex overflow-hidden bg-gray-100")[0]); //Insert new div into page at correct position
  85. document.getElementsByClassName("web-app-container")[0].insertAdjacentElement(`afterbegin`, newButton);
  86. document.getElementById("chatHeader").style = `background-color: rgb(17 17 17 / var(--tw-bg-opacity)); height: 4rem`;
  87. document.getElementById("chatSection").appendChild(smmoChat); //Add the chat to new div