我尝试用 chatgpt 写了一个油猴脚本 目前是可用的。他经常更新前端 DOM 结构 后面不能用了就要自己更新。
![](
https://img.xsojson.com/file/dbd60904a03905d517fa0.png)
```javascript
// ==UserScript==
// @
name ChatGPT 截长图工具
// @
namespace http://tampermonkey.net/// @
version 0.1
// @
description try to take over the world!
// @
author You
// @
match https://chatgpt.com/*// @
icon https://www.google.com/s2/favicons?sz=64&domain=openai.com// @
grant GM_addElement
// @
require https://unpkg.com/file-saver@2.0.5/dist/FileSaver.min.js// @
require https://unpkg.com/html2canvas@1.4.1/dist/html2canvas.js// ==/UserScript==
(function () {
'use strict';
const init = () => {
function snapChat() {
var selector = '#__next > div.relative.z-0.flex.h-full.w-full.overflow-hidden > div.relative.flex.h-full.max-w-full.flex-1.flex-col.overflow-hidden > main > div > div > div > div > div > div';
var headSelector = `#__next > div.relative.z-0.flex.h-full.w-full.overflow-hidden > div.relative.flex.h-full.max-w-full.flex-1.flex-col.overflow-hidden > main > div.flex.h-full.flex-col.focus-visible\\:outline-0 > div.flex-1.overflow-hidden > div > div > div > div >
div.sticky.top-0.juice\\:p-3.mb-1\\.5.flex.items
-center.justify-between.z-10.h-14.p-2.font-semibold.bg-token-main-surface-primary`
document.querySelector(headSelector).style.display = "none"
var target = document.querySelector(selector);
if (!target) {
return;
}
html2canvas(target).then(function (canvas) {
canvas.toBlob(blob => {
saveAs(blob, "chatshot.png");
document.querySelector(headSelector).style.display = "flex"
});
});
}
var btn = document.createElement('a');
btn.className = 'flex py-3 px-3 items-center gap-3 rounded-md hover:bg-gray-500/10 transition-colors duration-200 cursor-pointer text-sm';
btn.innerText = '截取当前对话长图';
btn.onclick = snapChat;
var menu = document.querySelector('nav');
menu.appendChild(btn);
window.snapChat = snapChat;
};
init();
})();
```