DeepSeek快捷键

为DeepSeek提供快捷键支持(Mac & Windows)

当前为 2025-04-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DeepSeek ShortCuts
  3. // @name:zh-CN DeepSeek快捷键
  4. // @name:zh-TW DeepSeek快捷鍵
  5. // @description Keyboard Shortcuts For DeepSeek (Mac & Windows)
  6. // @description:zh-CN 为DeepSeek提供快捷键支持(Mac & Windows)
  7. // @description:zh-TW 為DeepSeek提供快捷鍵支持(Mac & Windows)
  8. // @version 1.2.0
  9. // @icon https://raw.githubusercontent.com/MiPoNianYou/UserScripts/refs/heads/main/Icons/DeepSeekShortcutIcon.svg
  10. // @author 念柚
  11. // @namespace https://github.com/MiPoNianYou/UserScripts
  12. // @supportURL https://github.com/MiPoNianYou/UserScripts/issues
  13. // @license GPL-3.0
  14. // @match https://chat.deepseek.com/*
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. "use strict";
  20.  
  21. const CreateButtonFinder = (selector, text) => () =>
  22. Array.from(document.querySelectorAll(selector)).find(
  23. (btn) => btn.textContent?.includes(text) || btn.querySelector(text)
  24. );
  25.  
  26. const FindRegenBtn = CreateButtonFinder(".ds-icon-button", "#重新生成");
  27. const FindContinueBtn = CreateButtonFinder(".ds-button", "继续生成");
  28. const FindDeepThinkBtn = CreateButtonFinder(".ds-button span", "深度思考");
  29. const FindSearchBtn = CreateButtonFinder(".ds-button span", "联网搜索");
  30. const FindUploadBtn = () => document.querySelector(".f02f0e25");
  31. const FindNewChatBtn = () => document.querySelector("._217e214");
  32. const FindToggleSidebarBtn = () =>
  33. document
  34. .querySelector(
  35. ".ds-icon-button svg #打开边栏0730, .ds-icon-button svg #折叠边栏0730"
  36. )
  37. ?.closest(".ds-icon-button");
  38. const FindChatMenuBtn = () => {
  39. const SelectedChat = document.querySelector("._83421f9.b64fb9ae");
  40. return SelectedChat?.querySelector("._2090548");
  41. };
  42.  
  43. const GetModifierKey = () => {
  44. const UA = navigator.userAgent;
  45. const IsMac = /Macintosh|Mac OS X/i.test(UA);
  46. return {
  47. Character: IsMac ? "Control" : "Alt",
  48. Property: IsMac ? "ctrlKey" : "altKey",
  49. IsMac,
  50. };
  51. };
  52.  
  53. const ModifierKey = GetModifierKey();
  54. const HelpItems = [
  55. [`${ModifierKey.Character} + R`, "重新生成回答"],
  56. [`${ModifierKey.Character} + C`, "继续生成回答"],
  57. [`${ModifierKey.Character} + D`, "深度思考模式"],
  58. [`${ModifierKey.Character} + S`, "联网搜索模式"],
  59. [`${ModifierKey.Character} + U`, "上传文件文件"],
  60. [`${ModifierKey.Character} + N`, "新建对话窗口"],
  61. [`${ModifierKey.Character} + T`, "切换开关边栏"],
  62. [`${ModifierKey.Character} + I`, "当前对话菜单"],
  63. [`${ModifierKey.Character} + H`, "快捷按键帮助"],
  64. ];
  65.  
  66. const CreateHelpOverlay = () => {
  67. const Overlay = document.createElement("div");
  68. Overlay.style.cssText = `
  69. position: fixed;
  70. top: 50%;
  71. left: 50%;
  72. transform: translate(-50%, -50%) scale(0.95);
  73. z-index: 9999;
  74. pointer-events: none;
  75.  
  76. min-width: 280px;
  77. padding: 24px;
  78. border: 0.5px solid rgba(255, 255, 255, 0.15);
  79. border-radius: 12px;
  80.  
  81. background: rgba(28, 28, 30, 0.9);
  82. box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.1);
  83. backdrop-filter: blur(20px) saturate(180%);
  84.  
  85. color: rgba(255, 255, 255, 0.95);
  86. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  87. font-size: 14px;
  88. font-weight: 500;
  89. line-height: 1.5;
  90.  
  91. opacity: 0;
  92. transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  93. `;
  94.  
  95. const Title = document.createElement("h3");
  96. Title.textContent = "快捷按键指北";
  97. Title.style.cssText = `
  98. margin: 0 0 20px 0;
  99. width: 100%;
  100.  
  101. color: rgba(255, 255, 255, 0.9);
  102. font-size: 16px;
  103. font-weight: 600;
  104. text-align: center;
  105. `;
  106.  
  107. const List = document.createElement("div");
  108. HelpItems.forEach(([key, desc]) => {
  109. const Row = document.createElement("div");
  110. Row.style.cssText = `
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. margin-bottom: 10px;
  115. padding: 5px 0;
  116.  
  117. border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
  118. `;
  119. if (HelpItems.indexOf([key, desc]) === HelpItems.length - 1) {
  120. Row.style.borderBottom = "none";
  121. Row.style.marginBottom = "0";
  122. }
  123.  
  124. const KeyEl = document.createElement("span");
  125. KeyEl.textContent = key;
  126. KeyEl.style.cssText = `
  127. min-width: 90px;
  128. padding: 4px 8px;
  129. margin-left: 16px;
  130.  
  131. background: rgba(255, 255, 255, 0.1);
  132. border: 0.5px solid rgba(255, 255, 255, 0.15);
  133. border-radius: 5px;
  134. box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
  135.  
  136. color: rgba(255, 255, 255, 0.95);
  137. font-family: inherit;
  138. font-size: 13px;
  139. text-align: center;
  140.  
  141. flex-shrink: 0;
  142. `;
  143.  
  144. const DescEl = document.createElement("span");
  145. DescEl.textContent = desc;
  146. DescEl.style.cssText = `
  147. flex-grow: 1;
  148. padding-right: 10px;
  149. color: rgba(255, 255, 255, 0.8);
  150. `;
  151.  
  152. Row.append(DescEl, KeyEl);
  153. List.append(Row);
  154. });
  155.  
  156. const Warning = document.createElement("div");
  157. Warning.textContent = "⚠️ 脚本依UA自动适配快捷键 篡改UA或致功能异常";
  158. Warning.style.cssText = `
  159. margin-top: 24px;
  160. padding: 12px;
  161.  
  162. background: rgba(255, 119, 119, 0.1);
  163. border: 0.5px solid rgba(255, 119, 119, 0.2);
  164. border-radius: 8px;
  165.  
  166. color: rgba(255, 119, 119, 0.9);
  167. font-size: 12px;
  168. line-height: 1.5;
  169. text-align: center;
  170. `;
  171.  
  172. Overlay.append(Title, List, Warning);
  173. document.body.append(Overlay);
  174. return Overlay;
  175. };
  176.  
  177. const ToggleHelpOverlay = (Overlay) => {
  178. const IsVisible = parseFloat(Overlay.style.opacity || 0) > 0;
  179. Overlay.style.opacity = IsVisible ? "0" : "1";
  180. Overlay.style.transform = `translate(-50%, -50%) scale(${
  181. IsVisible ? 0.95 : 1
  182. })`;
  183. Overlay.style.pointerEvents = IsVisible ? "none" : "auto";
  184. };
  185.  
  186. let HelpOverlay = null;
  187. const InitHelpOverlay = () => {
  188. if (!HelpOverlay) {
  189. HelpOverlay = CreateHelpOverlay();
  190. }
  191. };
  192.  
  193. const SafeClick = (FinderFunc) => {
  194. FinderFunc()?.click();
  195. };
  196.  
  197. const KeyActions = {
  198. r: () => SafeClick(FindRegenBtn),
  199. c: () => SafeClick(FindContinueBtn),
  200. d: () => SafeClick(FindDeepThinkBtn),
  201. s: () => SafeClick(FindSearchBtn),
  202. u: () => SafeClick(FindUploadBtn),
  203. n: () => SafeClick(FindNewChatBtn),
  204. t: () => SafeClick(FindToggleSidebarBtn),
  205. i: () => SafeClick(FindChatMenuBtn),
  206. h: () => {
  207. InitHelpOverlay();
  208. ToggleHelpOverlay(HelpOverlay);
  209. },
  210. };
  211.  
  212. const CreateKeyHandler = () => {
  213. const IsModifierPressed = (Event) => Event[ModifierKey.Property];
  214.  
  215. return (Event) => {
  216. if (Event.key === "Escape" && HelpOverlay?.style.opacity === "1") {
  217. ToggleHelpOverlay(HelpOverlay);
  218. return;
  219. }
  220.  
  221. if (!IsModifierPressed(Event)) return;
  222. const Key = Event.key.toLowerCase();
  223. const Action = KeyActions[Key];
  224. Action?.(Event) && Event.preventDefault();
  225. };
  226. };
  227.  
  228. const KeyHandler = CreateKeyHandler();
  229. window.addEventListener("keydown", KeyHandler, true);
  230. })();