Greasy Fork

Greasy Fork is available in English.

Coze工具

Coze修改界面结构

目前为 2024-05-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         Coze工具
// @namespace    http://tampermonkey.net/
// @version      1.2
// @license      GPL-3.0
// @description  Coze修改界面结构
// @author       wzshjm
// @match        *://www.coze.com/*
// @match        *://www.coze.cn/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function () {
    'use strict';
    console.log("Coze工具已加载");
    let main = async () => {
        console.log("main已加载");
        let set_style = () => {
            let win_l = document.getElementsByClassName("arQAab07X2IRwAe6dqHV")
            let win_r = document.getElementsByClassName("sidesheet-container")
            // 打开
            if (is_win) {
                win_l[0].style.gridTemplateColumns = "13fr 13fr"
                win_r[0].style.gridTemplateColumns = "26fr 14fr"
            } else {
                win_l[0].style.gridTemplateColumns = "0 13fr"
                win_r[0].style.gridTemplateColumns = "2fr 3fr"
            }
            GM_setValue("is_win", is_win.toString())
        }
        var is_win = GM_getValue("is_win") == "true";
        var winButton = document.createElement('button');
        winButton.style.marginLeft = '10px';
        winButton.className = "semi-button semi-button-primary"
        winButton.innerText = is_win ? '恢复' : '展开';
        winButton.onclick = () => {
            is_win = !is_win
            winButton.innerText = is_win ? '恢复' : '展开';
            set_style()
        }
        const parent = document.querySelector(".semi-spin-children");
        const firstChild = parent.children[0];
        // 处理重复创建问题
        if (firstChild.children.length != 6) {
            return
        }
        firstChild.appendChild(winButton);
        setTimeout(set_style, 1000);
    }

    let task = () => {
        const timer = setInterval(() => {
            const parent = document.querySelector(".semi-spin-children");
            if (parent) {
                const firstChild = parent.children[0];
                if (firstChild) {
                    clearInterval(timer);
                    main()
                }
            }
        });
    }
    let registerEventHandler = (target) => {
        return function registerTargetEventHandler(methodName) {
            const originMethod = target[methodName];
            return function eventHandler(...args) {
                const event = new Event(methodName.toLowerCase());
                originMethod.apply(target, args);
                window.dispatchEvent(event);
                return originMethod;
            };
        };
    }
    const registerHistoryEventHandler = registerEventHandler(window.history);
    window.history.pushState = registerHistoryEventHandler("pushState");
    let init = () => {
        console.log("Coze工具init");
        const url = window.location.href;
        const botReg = /^https:\/\/www\.coze\.(?:com|cn)\/.*\/bot\/.*$/;
        if (botReg.test(url)) {
            if (!url.includes("analysis")) {
                task();
            }
        }
        const exploreReg = /^https:\/\/www\.coze\.(?:com|cn)\/explore\/.*$/;
        if (exploreReg.test(url)) {
            task();
        }
    }
    window.addEventListener("pushstate", init, false);
    init();
})();