DeepSeek回答转图片

将DeepSeek回答内容转为图片并复制到剪贴板

目前為 2025-02-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         DeepSeek回答转图片
// @namespace    https://gf.qytechs.cn/users/1312316
// @version      1.0
// @description  将DeepSeek回答内容转为图片并复制到剪贴板
// @author       星小韵
// @match        https://chat.deepseek.com/*
// @grant        GM_addStyle
// @grant        GM_setClipboard
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  // 创建截图按钮(替换为SVG图标)
  function createScreenshotButton(container) {
    const btn = document.createElement("div");
    btn.className = "ds-screenshot-btn";
    btn.setAttribute("tabindex", "0");
    btn.style.cssText = `
        --ds-icon-button-text-color: #CDD4DF;
        --ds-icon-button-size: 20px;
        --ds-icon-button-hover-color: #44444D;
        padding: 4px;
        background: transparent;
        color: var(--ds-icon-button-text-color);
        border: none;
        border-radius: 4px;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: var(--ds-icon-button-size);
        height: var(--ds-icon-button-size);
        transition: background-color 0.2s ease;
      `;
    btn.innerHTML = `
        <div class="ds-icon" style="font-size: var(--ds-icon-button-size); width: var(--ds-icon-button-size); height: var(--ds-icon-button-size);">
          <svg t="1739641914991" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7840" width="200" height="200"><path d="M853.333333 219.428571a73.142857 73.142857 0 0 1 73.142857 73.142858v487.619047a73.142857 73.142857 0 0 1-73.142857 73.142857H170.666667a73.142857 73.142857 0 0 1-73.142857-73.142857V292.571429a73.142857 73.142857 0 0 1 73.142857-73.142858h682.666666z m0 73.142858H170.666667v487.619047h682.666666V292.571429z m-341.333333 73.142857a170.666667 170.666667 0 1 1 0 341.333333 170.666667 170.666667 0 0 1 0-341.333333z m0 73.142857a97.52381 97.52381 0 1 0 0 195.047619 97.52381 97.52381 0 0 0 0-195.047619zM853.333333 97.52381v73.142857H512V97.52381h341.333333z" p-id="7841" fill="currentColor" ></path></svg>
        </div>
      `;

    btn.onclick = async () => {
      try {
        const contentBox = container.querySelector(".ds-markdown");
        if (!contentBox) return;

        // 使用html2canvas生成图片
        const canvas = await html2canvas(contentBox, {
          useCORS: true,
          logging: false,
          backgroundColor: "#1A1B25",
          scale: 2, // 高清截图
        });

        // 转为Blob
        canvas.toBlob(async (blob) => {
          try {
            // 写入剪贴板
            await navigator.clipboard.write([
              new ClipboardItem({
                [blob.type]: blob,
              }),
            ]);
            alert("图片已复制到剪贴板!");
          } catch (err) {
            console.error("复制失败:", err);
          }
        }, "image/png");
      } catch (error) {
        console.error("生成图片失败:", error);
      }
    };

    return btn;
  }

  // 处理每个回答块
  function processAnswers() {
    document.querySelectorAll(".f9bf7997.c05b5566").forEach((container) => {
      const buttonBar = container.querySelector(".ds-flex.abe97156"); // 找到消息按钮栏
      if (!buttonBar) return;

      if (!buttonBar.querySelector(".ds-screenshot-btn")) {
        const btn = createScreenshotButton(container);
        buttonBar.appendChild(btn); // 将按钮添加到消息按钮栏中
      }
    });
  }

  // 初始运行
  processAnswers();

  // 监听动态加载
  new MutationObserver(processAnswers).observe(document.body, {
    childList: true,
    subtree: true,
  });
})();

QingJ © 2025

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