// ==UserScript== // @name DeepSeek问答图片下载 // @namespace https://space.bilibili.com/1208812226 // @version 1.0.0 // @description 我是DeepSeek问答图片下载,很高兴见到你! // @author 大王鹅鹅鹅 // @match https://chat.deepseek.com/a/chat/s/* // @match https://chat.deepseek.com/a/chat/* // @match https://chat.deepseek.com/a/* // @match https://chat.deepseek.com/* // @icon https://chat.deepseek.com/deepseek-chat.jpeg // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/527829/DeepSeek%E9%97%AE%E7%AD%94%E5%9B%BE%E7%89%87%E4%B8%8B%E8%BD%BD.user.js // @updateURL https://update.greasyfork.icu/scripts/527829/DeepSeek%E9%97%AE%E7%AD%94%E5%9B%BE%E7%89%87%E4%B8%8B%E8%BD%BD.meta.js // ==/UserScript== (function () { "use strict"; document.addEventListener("keydown", function (event) { if (event.altKey && event.keyCode == 83) {//下载为markdown格式——快捷键:Ctrl+Alt+S if (event.ctrlKey) { downloadMD(); } } }); })(); function generateTextImage(titleText, bodyText, { titleFontSize = 72, titleColor = '#000', titleLineHeight = 1.2, titleMargin = 40, bodyFontSize = 42, bodyColor = '#333', bodyLineHeight = 1.6, width = 1080, minHeight = 1920, padding = 60, blurRadius = 20 } = {}) { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); // 固定尺寸系统 canvas.width = width; canvas.height = minHeight; // 初始高度 canvas.style.width = `${width}px`; // 内容处理 const safeTitle = titleText.trim() || '默认标题'; const safeBody = bodyText.trim() || '默认内容'; // 计算文本尺寸 ctx.font = `bold ${titleFontSize}px Arial`; const titleMaxWidth = width - padding * 2; const wrappedDawangTitleeee = wrapText(ctx, safeTitle, titleMaxWidth, titleFontSize, titleLineHeight); ctx.font = `${bodyFontSize}px Arial`; const bodyMaxWidth = width - padding * 2; const wrappedBody = wrapText(ctx, safeBody, bodyMaxWidth, bodyFontSize, bodyLineHeight); // 计算最终高度 const contentHeight = wrappedDawangTitleeee.textHeight + titleMargin + wrappedBody.textHeight; const finalHeight = Math.max(contentHeight + padding * 2, minHeight); canvas.height = finalHeight; // 生成不透明背景 const bgdaCwangeeeanvas = createOpaqueBackground(width, finalHeight, blurRadius); // 绘制背景 ctx.drawImage(bgdaCwangeeeanvas, 0, 0); // 添加毛玻璃效果 ctx.filter = `blur(${blurRadius}px)`; ctx.fillStyle = 'rgba(255, 255, 255, 0.5)'; ctx.fillRect(0, 0, width, finalHeight); // 绘制文本 ctx.filter = 'none'; // 清除模糊效果 ctx.fillStyle = titleColor; ctx.font = `bold ${titleFontSize}px Arial`; ctx.textBaseline = 'top'; let titleY = Math.max((finalHeight - contentHeight) / 2, padding); wrappedDawangTitleeee.lines.forEach(line => { ctx.fillText(line, padding, titleY); titleY += titleFontSize * titleLineHeight; }); ctx.fillStyle = bodyColor; ctx.font = `${bodyFontSize}px Arial`; let bodyY = titleY + titleMargin; wrappedBody.lines.forEach(line => { ctx.fillText(line, padding, bodyY); bodyY += bodyFontSize * bodyLineHeight; }); downloadImage(canvas, safeTitle); // 传递标题用于命名 } function createOpaqueBackground(width, height, blurRadius) { const mainCanvas = document.createElement('canvas'); mainCanvas.width = width; mainCanvas.height = height; const ctx = mainCanvas.getContext('2d'); // 生成基础渐变 const angle = Math.random() * Math.PI * 2; const gradient = ctx.createLinearGradient( Math.cos(angle) * width * 1.2, // 扩展渐变区域 Math.sin(angle) * height * 1.2, width * 0.5, height * 0.5 ); // 使用完全不透明颜色 const hue1 = Math.random() * 360; const hue2 = (hue1 + 120) % 360; gradient.addColorStop(0, `hsl(${hue1}, 70%, 60%)`); gradient.addColorStop(1, `hsl(${hue2}, 70%, 60%)`); // 填充基础颜色 ctx.fillStyle = gradient; ctx.fillRect(0, 0, width, height); // 模糊处理 const blurCanvas = document.createElement('canvas'); blurCanvas.width = width; blurCanvas.height = height; const blurCtx = blurCanvas.getContext('2d'); // 扩展模糊区域 blurCtx.filter = `blur(${blurRadius}px)`; blurCtx.drawImage(mainCanvas, -blurRadius, -blurRadius, width + blurRadius * 2, height + blurRadius * 2); // 覆盖基础颜色确保不透明 blurCtx.globalCompositeOperation = 'source-over'; blurCtx.fillStyle = gradient; blurCtx.fillRect(0, 0, width, height); return blurCanvas; } function wrapText(ctx, text, maxWidth, fontSize, lineHeight) { const lines = []; const paragraphs = text.split('\n').filter(p => p); paragraphs.forEach(para => { let currentLine = ''; for (const char of para) { const testLine = currentLine + char; const metrics = ctx.measureText(testLine); if (metrics.width > maxWidth && currentLine !== '') { lines.push(currentLine); currentLine = char; } else { currentLine = testLine; } } lines.push(currentLine); }); return { lines: lines.length ? lines : [' '], textHeight: lines.length * fontSize * lineHeight }; } function downloadImage(canvas, title) { const url = canvas.toDataURL('image/png'); const link = document.createElement('a'); link.download = `${title}.png`; // 使用标题作为文件名 link.href = url; document.body.appendChild(link); link.click(); document.body.removeChild(link); } function downloadMD() { const wFull = document.querySelector("#root"); const wFullList = wFull.childNodes[0].childNodes[1].childNodes[1].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes; for (var i = 0; i < wFullList.length; i++) { var title = wFull.childNodes[0].childNodes[1].childNodes[1].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[i].innerText; var contentList = wFull.childNodes[0].childNodes[1].childNodes[1].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[i + 1].childNodes; var content = wFull.childNodes[0].childNodes[1].childNodes[1].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[i + 1].childNodes[contentList.length - 2].innerText; i++; generateTextImage(title, content, { titleFontSize: 80, titleColor: '#26374c', bodyFontSize: 36, bodyColor: 'rgba(38, 55, 76, 0.9)', blurRadius: 40, padding: 80 }); } } //下载图标 window.onload=function(){ var svgDom= '
'; var newDiv = document.createElement("div"); newDiv.innerHTML = svgDom; newDiv.addEventListener("click", () => { downloadMD(); }); document.body.append(newDiv); };