ChatGPT Codeblock Word Wrap

Applies custom CSS to fix word wrapping on ChatGPT

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         ChatGPT Codeblock Word Wrap
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Applies custom CSS to fix word wrapping on ChatGPT
// @author       r00tz
// @match        https://chatgpt.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Define the CSS rules you want to apply
    const css = `
        .ͼ1 .cm-content[contenteditable=true] {
            -webkit-user-modify: read-write-plaintext-only;
        }
        .ͼ1 .cm-content {
            margin: -3px;
            flex-grow: 2;
            flex-shrink: 1; /* Changed from 0 to 1 to allow shrinking */
            min-width: 0;   /* Added to allow flex item to shrink below content size */
            display: block;
            white-space: pre-wrap; /* Allows wrapping while preserving whitespace */
            word-wrap: break-word; /* Ensures long words break to prevent overflow */
            overflow-wrap: break-word; /* Ensures long words break to prevent overflow */
            box-sizing: border-box;
            min-height: 100%;
            padding: 4px 0;
            outline: none;
        }
        .ͼ1 .cm-lineWrapping {
            white-space: pre-wrap;
            white-space: break-spaces;
            word-break: break-word;
            overflow-wrap: anywhere;
            flex-shrink: 1;
        }
        .ͼ2 .cm-content {
            caret-color: black;
        }
        .ͼ3 .cm-content {
            caret-color: white;
        }
        .ͼ1 .cm-line {
            display: block;
            padding: 0 2px 0 6px;
        }
    `;

    try {
        // Create a Blob from the CSS string (method to circumvent site protection) 
        const blob = new Blob([css], { type: 'text/css' });

        // Create a URL for the Blob
        const blobUrl = URL.createObjectURL(blob);

        // Create a link element for the stylesheet
        const link = document.createElement('link');
        link.rel = 'stylesheet';
        link.href = blobUrl;

        // Append the link element to the document's head
        document.head.appendChild(link);

        // Revoke the object URL after a short delay to clean up memory
        setTimeout(() => URL.revokeObjectURL(blobUrl), 100);

        console.log('Violentmonkey script: CSS for word-wrap applied via Blob.');
    } catch (e) {
        console.error('Violentmonkey script: Failed to apply CSS.', e);
    }

})();