Claude Content Max-Width

adjust Claude Content Max-Width

Versione datata 13/07/2023. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Claude Content Max-Width
// @namespace    http://tampermonkey.net/
// @version      0.1
// @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")) {
        var mainSectionDiv = document.querySelector("div[class*='PageWithSidebarLayout_mainSection']");
        var classNames = mainSectionDiv.classList;
        var mainSectionDivClass = null;
        for (var i = 0; i < classNames.length; i++) {
            var className = classNames[i];
            if (className.indexOf('PageWithSidebarLayout_mainSection') !== -1) {
                mainSectionDivClass = className;
                break;
            }
        }
        if (!mainSectionDivClass) {
            throw new Error("not found mainSectionDivClass");
        }


        var botMessageBubble = document.querySelector("div[class*='Message_botMessageBubble']");
        var classNames1 = botMessageBubble.classList;
        var botMessageBubbleClass = null;
        for (var i = 0; i < classNames1.length; i++) {
            var className = classNames1[i];
            if (className.indexOf('Message_botMessageBubble') !== -1) {
                botMessageBubbleClass = className;
                break;
            }
        }
        if (!botMessageBubbleClass) {
            throw new Error("not found botMessageBubbleClass");
        }


        var humanMessageBubble = document.querySelector("div[class*='Message_humanMessageBubble']");
        var classNames2 = humanMessageBubble.classList;
        var humanMessageBubbleClass = null;
        for (var i = 0; i < classNames2.length; i++) {
            var className = classNames2[i];
            if (className.indexOf('Message_humanMessageBubble') !== -1) {
                humanMessageBubbleClass = className;
                break;
            }
        }
        if (!humanMessageBubbleClass) {
            throw new Error("not found humanMessageBubbleClass");
        }


        var styleTag = document.createElement('style');

        // 将 CSS 样式添加到<style>标签中
        var cssStyles = `
            /* 在这里添加您的 CSS 样式 */
            .${mainSectionDivClass} {
              max-width: ${Math.floor(window.innerWidth * 0.75)}px;
            }
            .${botMessageBubbleClass},.${humanMessageBubbleClass} {
              max-width: ${Math.floor(window.innerWidth * 0.66)}ch;
            }
            `;

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

        // 将<style>标签添加到<head>标签中
        document.head.appendChild(styleTag);
    } 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 不符合预期");
    }
})();