Claude Content Max-Width

adjust Claude Content Max-Width

当前为 2024-01-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Claude Content Max-Width
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8
  5. // @description adjust Claude Content Max-Width
  6. // @author shawn-wxn
  7. // @match https://claude.ai/*
  8. // @match https://poe.com/*
  9. // @match https://*.geeksmonkey.com/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=claude.ai
  11. // @grant GM_addStyle
  12. // @grant GM_log
  13. // @license GPL-2.0-only
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. // 获取当前的 URL
  18. var currentURL = window.location.href;
  19.  
  20. // 根据当前 URL 进行 if-else 逻辑判断
  21. if (currentURL.includes("poe.com")) {
  22. var mainColumnDiv = document.querySelector("div[class^='MainColumn_column__']");
  23. var mainColumnDivClass = null;
  24. for (var className of mainColumnDiv.classList){
  25. if (className.indexOf('MainColumn_column__') !== -1) {
  26. mainColumnDivClass = className;
  27. break;
  28. }
  29. }
  30. if (!mainColumnDivClass) {
  31. GM_log("ERROR: not found mainColumnDivClass.");
  32. }
  33.  
  34. var chatPageMainDiv = document.querySelector("div[class^='InfiniteScroll_container__']");
  35. var chatPageMainDivClass = null;
  36. for (className of chatPageMainDiv.classList){
  37. if (className.indexOf('InfiniteScroll_container__') !== -1) {
  38. chatPageMainDivClass = className;
  39. break;
  40. }
  41. }
  42. if (!chatPageMainDivClass) {
  43. GM_log("ERROR: not found chatPageMainDivClass.");
  44. }
  45.  
  46. var humanMessageDiv = document.querySelector("div[class^='Message_humanMessageBubble__']");
  47. var humanMessageDivClass = null;
  48. for (className of humanMessageDiv.classList){
  49. if (className.indexOf('Message_humanMessageBubble__') !== -1) {
  50. humanMessageDivClass = className;
  51. break;
  52. }
  53. }
  54. if (!humanMessageDivClass) {
  55. GM_log("ERROR: not found humanMessageDivClass.");
  56. }
  57.  
  58. var botMessageDiv = document.querySelector("div[class^='Message_botMessageBubble__']");
  59. var botMessageDivClass = null;
  60. for (className of botMessageDiv.classList){
  61. if (className.indexOf('Message_botMessageBubble__') !== -1) {
  62. botMessageDivClass = className;
  63. break;
  64. }
  65. }
  66. if (!botMessageDivClass) {
  67. GM_log("ERROR: not found botMessageDivClass.");
  68. }
  69.  
  70. GM_addStyle(`
  71. .${mainColumnDivClass} {
  72. width: 100%;
  73. }
  74. .${chatPageMainDivClass} {
  75. --desktop-reading-column-max-width: ${Math.floor(window.innerWidth * 0.78)}px;
  76. }
  77. .${humanMessageDivClass} {
  78. max-width: ${Math.floor(window.innerWidth * 0.078)}ch;
  79. }
  80. .${botMessageDivClass} {
  81. max-width: ${Math.floor(window.innerWidth * 0.078)}ch;
  82. }`
  83. )
  84. } else if (currentURL.includes("claude.ai")) {
  85. // 创建一个<style>标签
  86. var styleTag = document.createElement('style');
  87.  
  88. // 将 CSS 样式添加到<style>标签中
  89. var cssStyles = `
  90. /* 在这里添加您的 CSS 样式 */
  91. .max-w-3xl {
  92. max-width: ${Math.floor(window.innerWidth * 0.05)}rem;
  93. }
  94. .max-w-\\[75ch\\] {
  95. max-width: ${Math.floor(window.innerWidth * 0.1)}ch;
  96. }
  97. `;
  98.  
  99. // 设置<style>标签的内容为 CSS 样式
  100. styleTag.innerHTML = cssStyles;
  101.  
  102. // 将<style>标签添加到<head>标签中
  103. document.head.appendChild(styleTag);
  104. } else if (currentURL.includes("geeksmonkey.com")){
  105. // 选择目标节点
  106. const targetNode = document.getElementById('app');
  107.  
  108. // 创建一个观察器实例并传入回调函数
  109. const observer = new MutationObserver(function(mutations) {
  110. // 遍历所有的变动记录
  111. mutations.forEach(function(mutation) {
  112. // 检查是否有子节点被移除
  113. if (mutation.type === 'childList' && mutation.removedNodes.length > 0) {
  114. // 遍历所有被移除的节点
  115. for (let i = 0; i < mutation.removedNodes.length; i++) {
  116. // 检查这个节点是否是我们关注的节点(具有class=load-wrapper)
  117. const node = mutation.removedNodes[i];
  118. if (node.nodeType === Node.ELEMENT_NODE){
  119. if (node.classList.contains('loading-wrap')) {
  120. // 动画结束,load-wrapper元素被移除
  121. // 在这里执行你想要进行的操作
  122. var imageWraperDiv = document.getElementById("image-wrapper");
  123. var imageWraperDivClass = null;
  124. for (className of imageWraperDiv.classList) {
  125. if (className.indexOf('max-w-screen-xl') !== -1) {
  126. imageWraperDivClass = className;
  127. break;
  128. }
  129. }
  130. if (!imageWraperDivClass) {
  131. GM_log("ERROR: not found imageWraperDivClass.");
  132. }
  133.  
  134. GM_addStyle(`
  135. .${imageWraperDivClass} {
  136. max-width: ${Math.floor(window.innerWidth * 0.83)}px;
  137. }`
  138. )
  139.  
  140. // 一旦检测到load-wrapper元素被移除,就断开观察器
  141. observer.disconnect();
  142. return; // 退出循环和回调函数
  143. }
  144. }
  145. }
  146. }
  147. });
  148. });
  149.  
  150. // 配置观察选项:
  151. const config = { attributes: false, childList: true, subtree: true };
  152.  
  153. // 传入目标节点和观察选项开始观察
  154. observer.observe(targetNode, config);
  155.  
  156.  
  157. }else {
  158. // 如果以上条件都不满足
  159. console.log("当前 URL 不符合预期");
  160. }
  161. })();

QingJ © 2025

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