ChatGPT撑开页面宽度

将页面宽度展开

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

// ==UserScript==
// @name         ChatGPT撑开页面宽度
// @namespace    https://gf.qytechs.cn/
// @version      1.1.0
// @description  将页面宽度展开
// @author       OpenAI - ChatGPT
// @match        https://chat.openai.com/
// @match        https://chat.openai.com/c/*
// @match        https://chat.openai.com/?*
// @license      copyright await
// ==/UserScript==

(function () {
  "use strict";
  const newMaxWidth = "90rem";
  const targetClassName = ".xl\\:max-w-3xl";
  const targetClass = "flex flex-col text-sm dark:bg-gray-800";
  const desiredMinWidth = 1280;
  function btnClick() {
    const toggleButton = document.querySelector("nav");
    if (!toggleButton) {
      setTimeout(function () {
        btnClick();
      }, 1000);
      return;
    }
    toggleButton.insertAdjacentHTML(
      "beforeend",
      '<div id="btnClick" style="position:fixed;top:3rem;left:15rem;z-index:9999;background-color:rgba(0,0,0,0.5);color:#fff;padding:10px;border-radius:5px;">如果页面宽度未展开,请重新点击此树结构导航栏<br>或者直接<span style="color:red">点击我</span><br>提示内容十秒后自动消失</div>'
    );
    const btn = document.getElementById("btnClick");
    btn.addEventListener("click", function () {
      run();
    });
    setTimeout(function () {
      btn.remove();
    }, 10000);
    if (toggleButton) {
      toggleButton.addEventListener("click", function () {
        setTimeout(function () {
          run();
        }, 1000);
      });
    }
  }

  function checkForm() {
    var elementForm = document.querySelectorAll("form");
    if (!elementForm || elementForm.length === 0) {
      setTimeout(function () {
        checkObserver();
      }, 1000);
      return;
    }
    elementForm.forEach(function (element) {
      if (element.className.indexOf("xl:max-w-3xl") > -1) {
        editStyle(element);
      }
    });
  }

  function checkObserver() {
    var parentElement = document.getElementsByClassName(targetClass)[0];
    if (!parentElement) {
      setTimeout(function () {
        checkObserver();
      }, 1000);
      return;
    }
    parentElement.querySelectorAll(targetClassName).forEach(function (flexDiv) {
      editStyle(flexDiv);
    });
    var observer = new MutationObserver(function (mutations) {
      mutations.forEach(function (mutation) {
        mutation.addedNodes.forEach(function (addedNode) {
          var flexDivs = addedNode.querySelectorAll(targetClassName);
          flexDivs.forEach(function (flexDiv) {
            editStyle(flexDiv);
          });
        });
      });
    });
    var config = { childList: true, subtree: true };
    observer.observe(parentElement, config);
  }

  function editStyle(el) {
    el.style.transition = "max-width 1s";
    setTimeout(function () {
      el.style.transition = "";
    }, 1000);
    el.style.maxWidth = newMaxWidth;
  }

  function run() {
    checkForm();
    checkObserver();
  }
  window.addEventListener("resize", run);
  window.onload = function () {
    if (window.innerWidth < desiredMinWidth) {
      return;
    }
    btnClick();
    setTimeout(function () {
      run();
    }, 2000);
  };
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址