Chat Box Section

Creates a separated section for the chat box

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

  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.3
  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. smmoChat = xinit
  17. }
  18. })
  19.  
  20. if (!smmoChat) return;
  21. smmoChat.style = "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("chatArea")
  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 show_hide_chat() {
  36. newHTML.style.display = newHTML.style.display === "none" ? "block" : "none";
  37. chatButton.click();
  38. }
  39. //Main Script
  40. newButton.id = "newChatButton";
  41. newButton.innerHTML = "Show/Hide Chat";
  42. 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";
  43. newButton.onmousedown = show_hide_chat;
  44. newHTML.id = "chatSection";
  45. 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`;
  46.  
  47. document.onkeydown = function (event) {
  48. if (event.code === 'NumpadEnter') {
  49. show_hide_chat()
  50. }
  51. }
  52.  
  53. if(docCookies.getItem('show_chat') === 'true') {
  54. newHTML.style.display = "block"
  55. }
  56.  
  57. gameParent.style.cssText = `z-index: 2; position: relative`;
  58.  
  59. document.getElementById("app").insertAdjacentElement(`afterbegin`, newHTML);
  60. document.querySelector(".web-app-container").insertAdjacentElement(`afterbegin`, newButton);
  61. newHTML.appendChild(smmoChat);