Chat Box Section

Creates a separated section for the chat box

目前为 2024-12-04 提交的版本。查看 最新版本

// ==UserScript==
// @name        Chat Box Section
// @namespace   Violentmonkey Scripts
// @match       https://web.simple-mmo.com/*
// @grant       none
// @license     GPL-v3
// @version     1.3.1
// @author      Freaky Fingers
// @description Creates a separated section for the chat box
// ==/UserScript==
//Config Variables
let chatWidth = 20
let chatHeight = 94

//Script Variables
let newHTML = document.createElement("chatArea")
let allxinits = document.querySelectorAll("[x-init]")
let smmoChat = null
let chatBox = document.getElementById("chatBox")
let chatButton = document.getElementById("show_hide_chat_btn")

function clamp (input, min, max) {
  return Math.min(Math.max(input, min), max)
}

allxinits.forEach(xinit => {
  if (xinit.outerHTML.includes("chat:false,chatSrc:'about:blank;'")){
    smmoChat = xinit
  }
})

if (smmoChat !== null){

  newHTML.innerHTML = `
  <div id="chatParent">
    <section id="chatHeader"></section>
    <section id="chatSection"></section>
  </div>
  `;  //create new div

  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
  smmoChat.style = "position: fixed; height: 100%";
  chatBox.style = `position: relative; height: ${chatHeight}%; width: ${chatWidth}vw; padding: 0rem`;
  newHTML.style = `background-color: #0000; height: ${chatHeight}vh; width: ${chatWidth}vw; float: right; position: sticky; z-index: 1`; //Style new div
  chatButton.style = `margin-bottom: ${Math.min(chatHeight + 1, 95)}vh; margin-right: 11vw; z-index: 0`;

  document.getElementById("app").insertBefore(newHTML, document.getElementsByClassName("h-screen flex overflow-hidden bg-gray-100")[0]); //Insert new div into page at correct position
  document.getElementById("chatHeader").style = `background-color: rgb(17 17 17 / var(--tw-bg-opacity)); height: ${clamp((100 - chatHeight), 0, 101)}vh`;
  document.getElementById("chatSection").appendChild(smmoChat); //Add the chat to new div

}