Claude Content Max-Width

adjust Claude Content Max-Width

目前為 2023-08-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Claude Content Max-Width
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  adjust Claude Content Max-Width
// @author       shawn-wxn
// @match        https://claude.ai/*
// @match        https://poe.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=claude.ai
// @grant        none
// @license      GPL-2.0-only
// ==/UserScript==

(function () {
    // 获取当前的 URL
    var currentURL = window.location.href;

    // 根据当前 URL 进行 if-else 逻辑判断
    if (currentURL.includes("poe.com")) {
        function mainSectionAndChatPageMain() {
            const mainSection = document.querySelector('div[class^="PageWithSidebarLayout_mainSection__"]');
            mainSection.style.setProperty('max-width', Math.floor(window.innerWidth * 0.78) + 'px', 'important');
            const chatPageMain = document.querySelector('div[class^="ChatPageMain_container__"]');
            chatPageMain.style.setProperty('--desktop-reading-column-max-width', Math.floor(window.innerWidth * 0.78) + 'px', 'important');
        }

        function changeMessageBox() {
            const messageBoxs = document.querySelectorAll('div[class^="Message_humanMessageBubble__"]');
            messageBoxs.forEach(messageBox => {
                messageBox.style.setProperty('max-width', Math.floor(window.innerWidth * 0.078) + 'ch', 'important');
            }
            );
        }

        // 选择需要观察变动的节点
        const targetNode = document.querySelector('div[class^="InfiniteScroll_container__"]');

        // 创建一个观察器实例
        const observer = new MutationObserver(mutations => {
            var mutation = mutations[0];
            if (mutation.type === 'childList' && mutation.removedNodes.length > 0) {
                changeMessageBox();
            }
        }
        );

        // 开始观察
        observer.observe(targetNode, {
            // attributes: true,
            // 观察属性变动
            childList: true,
            // 观察子节点变动
            // subtree: true
            // 同时观察后代节点
        });
        mainSectionAndChatPageMain();
        changeMessageBox();
    } else if (currentURL.includes("claude.ai")) {
        // 创建一个<style>标签
        var styleTag = document.createElement('style');

        // 将 CSS 样式添加到<style>标签中
        var cssStyles = `
            /* 在这里添加您的 CSS 样式 */
            .max-w-3xl {
              max-width: ${Math.floor(window.innerWidth * 0.05)}rem;
            }
            .max-w-\\[75ch\\] {
              max-width: ${Math.floor(window.innerWidth * 0.1)}ch;
            }
        `;

        // 设置<style>标签的内容为 CSS 样式
        styleTag.innerHTML = cssStyles;

        // 将<style>标签添加到<head>标签中
        document.head.appendChild(styleTag);
    } else {
        // 如果以上条件都不满足
        console.log("当前 URL 不符合预期");
    }
})();