Deepseek输入框隐藏

使用底部的小切换按钮切换聊天输入框的可见性

  1. // ==UserScript==
  2. // @name Deepseek输入框隐藏
  3. // @namespace none
  4. // @version 3.6
  5. // @description 使用底部的小切换按钮切换聊天输入框的可见性
  6. // @author 留白ฅ
  7. // @match https://chat.deepseek.com/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // 目标元素的选择器(包含所有部分)
  16. const targetElementSelectors = [
  17. '.b699646e.dd442025',
  18. '.fad49dec',
  19. '.cefa5c26',
  20. '.aaff8b8f', // 新增的选择器
  21. '.cbcaa82c' // 新增的选择器
  22. ];
  23.  
  24. // 全局变量
  25. let targetElements = []; // 目标元素
  26. let toggleButton = null; // 切换按钮
  27. let observer = null; // MutationObserver 实例
  28. let styleElement = null; // 动态添加的样式元素
  29.  
  30. // 初始化脚本
  31. function initScript() {
  32. // 清理之前的资源
  33. cleanupScript();
  34.  
  35. // 清空 targetElements
  36. targetElements = [];
  37.  
  38. // 尝试查找目标元素
  39. for (const selector of targetElementSelectors) {
  40. const elements = document.querySelectorAll(selector);
  41. if (elements.length > 0) {
  42. targetElements.push(...elements);
  43. console.log(`Target elements found with selector: ${selector}`);
  44. }
  45. }
  46.  
  47. // 如果目标元素不存在,尝试动态查找
  48. if (targetElements.length === 0) {
  49. console.log('Target elements not found, waiting for dynamic load...');
  50.  
  51. // 使用 MutationObserver 监听 DOM 变化
  52. observer = new MutationObserver((mutationsList) => {
  53. for (const mutation of mutationsList) {
  54. if (mutation.type === 'childList') {
  55. // 检查新增的节点中是否包含目标元素
  56. for (const selector of targetElementSelectors) {
  57. const elements = document.querySelectorAll(selector);
  58. if (elements.length > 0) {
  59. targetElements.push(...elements);
  60. console.log(`Target elements found with selector: ${selector}`);
  61. observer.disconnect(); // 停止监听
  62. initToggleButton(); // 初始化收起按钮
  63. break;
  64. }
  65. }
  66. }
  67. }
  68. });
  69.  
  70. // 监听整个文档的变化
  71. observer.observe(document.body, { childList: true, subtree: true });
  72. } else {
  73. initToggleButton(); // 初始化收起按钮
  74. }
  75. }
  76.  
  77. // 初始化收起按钮
  78. function initToggleButton() {
  79. console.log('Initializing toggle button...');
  80.  
  81. // 创建收起按钮
  82. toggleButton = document.createElement('button');
  83. toggleButton.textContent = '▼'; // 初始状态为展开图标
  84. toggleButton.style.position = 'fixed';
  85. toggleButton.style.bottom = '112px'; // 展开状态下的初始位置
  86. toggleButton.style.left = '50%'; // 展开状态下的初始位置
  87. toggleButton.style.transform = 'translateX(-50%)'; // 水平居中
  88. toggleButton.style.zIndex = '1000';
  89. toggleButton.style.padding = '5px 10px';
  90. toggleButton.style.backgroundColor = 'rgba(255, 255, 255, 0.3)'; // 浅色半透明背景,透明度为 0.3
  91. toggleButton.style.color = '#000'; // 文字颜色为黑色
  92. toggleButton.style.border = 'none';
  93. toggleButton.style.borderRadius = '5px 5px 0 0';
  94. toggleButton.style.cursor = 'pointer';
  95. toggleButton.style.backdropFilter = 'blur(12px)'; // 模糊强度为 12px
  96. toggleButton.style.webkitBackdropFilter = 'blur(12px)'; // 兼容 Safari
  97.  
  98. // 添加点击事件
  99. toggleButton.addEventListener('click', function () {
  100. targetElements.forEach(element => {
  101. if (element.style.transform === 'translateY(100%)') {
  102. // 展开状态:恢复默认样式
  103. element.style.transform = ''; // 清空 transform
  104. toggleButton.style.bottom = '112px'; // 展开状态下的位置
  105. toggleButton.textContent = '▼'; // 展开图标
  106. console.log('Showing elements (no modification)');
  107. } else {
  108. // 收起状态:隐藏元素
  109. element.style.transform = 'translateY(100%)';
  110. toggleButton.style.bottom = '0px'; // 收起状态下的位置
  111. toggleButton.textContent = '▲'; // 收起图标
  112. console.log('Hiding elements');
  113. }
  114. });
  115. });
  116.  
  117. // 将收起按钮添加到页面
  118. document.body.appendChild(toggleButton);
  119. console.log('Toggle button added to page');
  120.  
  121. // 添加 CSS 样式以实现平滑过渡
  122. styleElement = document.createElement('style');
  123. styleElement.textContent = `
  124. ${targetElementSelectors.join(', ')} {
  125. transition: transform 0.3s ease-in-out;
  126. position: fixed;
  127. bottom: 0;
  128. left: 0;
  129. right: 0;
  130. z-index: 1000; /* 确保元素在最上层 */
  131. }
  132. button {
  133. transition: bottom 0.3s ease-in-out;
  134. }
  135. `;
  136. document.head.appendChild(styleElement);
  137. console.log('CSS styles added');
  138. }
  139.  
  140. // 清理脚本资源
  141. function cleanupScript() {
  142. console.log('Cleaning up script resources...');
  143.  
  144. // 移除切换按钮
  145. if (toggleButton && toggleButton.parentNode) {
  146. toggleButton.parentNode.removeChild(toggleButton);
  147. toggleButton = null;
  148. }
  149.  
  150. // 移除动态添加的样式
  151. if (styleElement && styleElement.parentNode) {
  152. styleElement.parentNode.removeChild(styleElement);
  153. styleElement = null;
  154. }
  155.  
  156. // 停止 MutationObserver
  157. if (observer) {
  158. observer.disconnect();
  159. observer = null;
  160. }
  161.  
  162. // 恢复目标元素的样式
  163. targetElements.forEach(element => {
  164. element.style.transform = '';
  165. });
  166. targetElements = [];
  167. }
  168.  
  169. // 监听路由变化
  170. let lastUrl = location.href;
  171. const checkUrlChange = () => {
  172. const currentUrl = location.href;
  173. if (currentUrl !== lastUrl) {
  174. lastUrl = currentUrl;
  175.  
  176. if (currentUrl.includes('https://chat.deepseek.com/a/chat/')) {
  177. console.log('URL changed to chat page, initializing script...');
  178. initScript(); // 初始化脚本
  179. } else if (currentUrl === 'https://chat.deepseek.com/') {
  180. console.log('URL changed to homepage, cleaning up script...');
  181. cleanupScript(); // 清理脚本资源
  182. }
  183. }
  184. };
  185.  
  186. // 使用 setInterval 定期检查 URL 变化
  187. setInterval(checkUrlChange, 500); // 每 500ms 检查一次 URL 变化
  188.  
  189. // 页面加载时初始化脚本
  190. if (location.href.includes('https://chat.deepseek.com/a/chat/')) {
  191. initScript();
  192. } else if (location.href === 'https://chat.deepseek.com/') {
  193. cleanupScript(); // 如果当前是主页,清理脚本资源
  194. }
  195. })();

QingJ © 2025

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