Coze Bot Style for App

Let Coze Bot Style of App better!

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

// ==UserScript==
// @name         Coze Bot Style for App
// @namespace    https://www.velhlkj.com/
// @version      20240604.002
// @description  Let Coze Bot Style of App better!
// @author       Velade
// @match        https://www.coze.com/store/bot/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-body
// @license      Apache 2.0
// ==/UserScript==

(function() {
    'use strict';

    const style = document.createElement('style');
    style.textContent = `
                    /*官方阴影*/
                    .ULoOs2TMkJkb2BgT_MKa {
                        display: none !important;
                    }
                    /*新对话按钮*/
                    .NyvVfPwFXFYvQFyXUtTl {
                        padding-left: 0 !important;
                    }
                    /*标题列*/
                    .nZxnu8KzOis7qKnDx66E {
                        position: fixed !important;
                        top: 5px !important;
                        right: 5px !important;
                        width: 80px !important;
                        height: 40px !important;
                        filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.5)) !important;
                    }

                    .nZxnu8KzOis7qKnDx66E > div:first-child {
                        display: none !important;
                    }

                    .nZxnu8KzOis7qKnDx66E > div:nth-child(2) > div:nth-child(2){
                        display: none !important;
                    }
                    /*对话区域主体*/
                    .O4fwdEnt3QgzBjrYtohO {
                        -webkit-mask: linear-gradient(180deg,hsla(0,0%,100%,0) 5px, #fff calc(8.11% + 5px), #fff 91.89%, hsla(0,0%,100%,0)) !important;
                        mask: linear-gradient(180deg,hsla(0,0%,100%,0) 5px, #fff calc(8.11% + 5px), #fff 91.89%, hsla(0,0%,100%,0)) !important;
                    }
                    /*底部声明:改为导航栏占位*/
                    .pStAbHgTdAlDVUlpMOGP {
                        opacity: 0 !important;
                        height: 5px !important;
                    }
                    /*斜体样式*/
                    .flow-markdown-body em.vel-em-action {
                        display: block !important;
                        clear: both !important;
                        color: #FF69B4 !important;
                        font-style: normal !important;
                    }
                    .flow-markdown-body em.vel-em-other {
                        display: inline-block !important;
                        clear: none !important;
                        color: #FF69B4 !important;
                        font-style: normal !important;
                    }
    `;
    document.head.appendChild(style);

    let observer = new MutationObserver(mutations=>{
        mutations.forEach(mutation=>{
            if(mutation.type === 'childList' || mutation.type === "characterData"){
                mutation.addedNodes.forEach(node=>{
                    if(!node.querySelectorAll) return;
                    if(node.matches(".paragraph-element") && node.innerHTML.match(/\*[\((].+?[\))]\*/)){
                        node.innerHTML = node.innerHTML.replaceAll(/\*[\((]/g,"<em>(").replaceAll(/[\))]\*/g, ")</em>");
                    }else {
                        node.querySelectorAll(".paragraph-element").forEach(n=>{
                            if(n.innerHTML.match(/\*[\((].+?[\))]\*/)) n.innerHTML = n.innerHTML.replaceAll(/\*[\((]/g,"<em>(").replaceAll(/[\))]\*/g, ")</em>");
                        })
                    }
                    console.log(node);
                    if(node.tagName.toLowerCase() == "em") {
                            if(node.textContent.match(/^[\((].+?[\))]$/)) { node.textContent = node.textContent.replaceAll(/[\(\)()]/g,""); node.classList.add("vel-em-action"); }
                            else node.classList.add("vel-em-other");
                    }else if(node.matches(".math-inline")){
                        node.parentElement.textContent = node.textContent;
                    }else{
                        node.querySelectorAll(`em:not(.vel-em-action, .vel-em-other)`).forEach(n=>{
                            if(n.textContent.match(/^[\((].+?[\))]$/)) { n.textContent = n.textContent.replaceAll(/[\(\)()]/g,""); n.classList.add("vel-em-action"); }
                            else n.classList.add("vel-em-other");
                        })
                    }
                })
            }
        })
    });
    const config = { childList: true, subtree: true,characterData: true };
    const targetNode = document.body;
    observer.observe(targetNode, config);
})();