// ==UserScript== // @name ChatGPT Exporter // @name:zh-CN ChatGPT Exporter // @name:zh-TW ChatGPT Exporter // @namespace pionxzh // @version 2.5.2 // @author pionxzh // @description Easily export the whole ChatGPT conversation history for further analysis or sharing. // @description:zh-CN 轻松导出 ChatGPT 聊天记录,以便进一步分析或分享。 // @description:zh-TW 輕鬆匯出 ChatGPT 聊天紀錄,以便進一步分析或分享。 // @license MIT // @icon https://chat.openai.com/favicon.ico // @match https://chat.openai.com/chat // @match https://chat.openai.com/chat?* // @match https://chat.openai.com/chat/* // @require https://cdn.jsdelivr.net/npm/jszip@3.9.1/dist/jszip.min.js // @require https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js // @grant GM_deleteValue // @grant GM_getValue // @grant GM_setValue // @grant unsafeWindow // @run-at document-end // @downloadURL none // ==/UserScript== (e=>{const n=document.createElement("style");n.dataset.source="vite-plugin-monkey",n.innerText=e,document.head.appendChild(n)})(` .CheckBoxLabel { position: relative; display: flex; font-size: 16px; vertical-align: middle; } .CheckBoxLabel * { cursor: pointer; } .CheckBoxLabel[disabled] { opacity: 0.7; } .CheckBoxLabel[disabled] * { cursor: not-allowed; } .CheckBoxLabel input { position: absolute; opacity: 0; width: 100%; height: 100%; top: 0; left: 0; margin: 0; padding: 0; } .CheckBoxLabel .IconWrapper { display: inline-flex; align-items: center; position: relative; vertical-align: middle; font-size: 1.5rem; } .CheckBoxLabel input:checked ~ svg { color: rgb(28 100 242); } .dark .CheckBoxLabel input:checked ~ svg { color: rgb(144, 202, 249); } .CheckBoxLabel .LabelText { margin-left: 0.5rem; font-size: 1rem; line-height: 1.5; } img[src*="https://source.unsplash.com/"] { visibility: hidden; } /* hide the flickering */ p > img[src*="https://images.unsplash.com/"] { animation: fadeIn .3s; } .Select { padding: 0 0 0 0.5rem; width: 7.5rem; border-radius: 4px; box-shadow: 0 0 0 1px #6f6e77; } .dark .Select { background-color: #2f2f2f; color: #fff; box-shadow: 0 0 0 1px #6f6e77; } .menu-item { height: 46px; } .menu-item[disabled] { pointer-events: none; filter: brightness(0.5); } .inputFieldSet { display: block; border-width: 2px; border-style: groove; } .inputFieldSet legend { margin-left: 4px; } .inputFieldSet input { background-color: transparent; box-shadow: none!important; } .row-half { grid-column: auto / span 1; } .row-full { grid-column: auto / span 2; } .dropdown-backdrop { display: none; position: fixed; top: 0; bottom: 0; left: 0; right: 0; background-color: rgba(0,0,0,.5); z-index: 998; animation-name: pointerFadeIn; animation-duration: .3s; } .dropdown-menu { display: none; position: absolute; grid-template-columns: 1fr 1fr; column-gap: 4px; left: calc(100% + 1rem); top: -3.85rem; width: 268px; padding: .75rem .4rem 0 .4rem; border-radius: .375rem; box-shadow: 0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1); animation: fadeIn .3s; } .dropdown-menu::before { content: ''; position: absolute; top: 0; left: -1rem; width: 1rem; height: 100%; } #exporter-menu[disabled] { cursor: not-allowed; } #exporter-menu:not([disabled]):hover::after { content: ''; position: absolute; top: 1.2rem; right: -1rem; width: 0; height: 0; border-top: .5rem solid transparent; border-bottom: .5rem solid transparent; border-right: .5rem solid #202123; animation: fadeIn .3s; } @supports not selector(:has(.test:hover)) { #exporter-menu:not([disabled]):hover .dropdown-menu { display: grid; } } @supports selector(:has(.test:hover)) { #exporter-menu:not([disabled]):not(:has(.dropdown-backdrop:hover)):hover .dropdown-menu { display: grid; } } @media screen and (hover: none) and (max-width: 768px) { .dropdown-menu { position: fixed; left: 0; top: unset; bottom: 0; width: 100%; border-radius: 0; box-shadow: none; z-index: 999; animation: slideUp .3s; } @supports selector(:has(.test:hover)) { #exporter-menu:not([disabled]):not(:has(.dropdown-backdrop:hover)):hover .dropdown-backdrop { display: block; } #exporter-menu:not([disabled]):has(.dropdown-backdrop:hover):hover .dropdown-backdrop { display: block; pointer-events: none; opacity: 0; animation-name: pointerFadeInReverse; } } #exporter-menu:hover::after { display: none; } } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } } @keyframes pointerFadeIn { from { opacity: 0; pointer-events: none; } to { opacity: 1; pointer-events: auto; } } /* Using \`animation-direction: reverse\` is not working in our case */ @keyframes pointerFadeInReverse { from { opacity: 1; pointer-events: auto; } to { opacity: 0; pointer-events: none; } } @keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } @keyframes circularDash { 0% { stroke-dasharray: 1px, 200px; stroke-dashoffset: 0; } 50% { stroke-dasharray: 100px, 200px; stroke-dashoffset: -15px; } 100% { stroke-dasharray: 100px, 200px; stroke-dashoffset: -125px; } } .DialogOverlay { background-color: rgba(0, 0, 0, 0.44); position: fixed; inset: 0; z-index: 1000; animation: fadeIn 150ms cubic-bezier(0.16, 1, 0.3, 1); } .DialogContent { background-color: white; border-radius: 6px; box-shadow: hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 90vw; max-width: 450px; max-height: 85vh; overflow-x: hidden; overflow-y: auto; padding: 16px 24px; z-index: 1001; animation: contentShow 150ms cubic-bezier(0.16, 1, 0.3, 1); } .dark .DialogContent { background-color: #2a2a2a; border-color: #40414f; border-width: 1px; } .DialogContent input[type="checkbox"] { border: none; outline: none; box-shadow: none; } .DialogTitle { margin: 0 0 16px 0; font-weight: 500; color: #1a1523; font-size: 20px; } .dark .DialogTitle { color: #fff; } .Button { display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; padding: 0 15px; font-size: 15px; line-height: 1; font-weight: 500; height: 35px; } .Button.green { background-color: #ddf3e4; color: #18794e; } .Button.green:hover { background-color: #ccebd7; } .Button:disabled { opacity: 0.5; color: #6f6e77; background-color: #e0e0e0; cursor: not-allowed; } .Button:disabled:hover { background-color: #e0e0e0; } .IconButton { font-family: inherit; border-radius: 100%; height: 25px; width: 25px; display: inline-flex; align-items: center; justify-content: center; color: #6f6e77; } .IconButton:hover { background-color: rgba(0, 0, 0, 0.06); } .CloseButton { position: absolute; top: 10px; right: 10px; } .Fieldset { display: flex; gap: 20px; align-items: center; margin-bottom: 15px; } .Label { font-size: 15px; color: #1a1523; min-width: 90px; text-align: right; } .dark .Label { color: #fff; } .Input { width: 100%; flex: 1; display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; padding: 0 10px; font-size: 15px; line-height: 1; color: #000; background-color: #fafafa; box-shadow: 0 0 0 1px #6f6e77; height: 35px; outline: none; } .dark .Input { background-color: #2f2f2f; color: #fff; box-shadow: 0 0 0 1px #6f6e77; } .Description { font-size: 13px; color: #5a5865; text-align: right; margin-bottom: 4px; } .dark .Description { color: #bcbcbc; } .SelectToolbar { display: flex; align-items: center; padding: 12px 16px; border-radius: 4px 4px 0 0; border: 1px solid #6f6e77; border-bottom: none; } .SelectList { position: relative; width: 100%; height: 300px; padding: 12px 16px; overflow-x: hidden; overflow-y: auto; border: 1px solid #6f6e77; border-radius: 0 0 4px 4px; white-space: nowrap; } .SelectItem { overflow: hidden; text-overflow: ellipsis; } .SelectItem label, .SelectItem input { cursor: pointer; } .SelectItem span { vertical-align: middle; } @keyframes contentShow { from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } } .invisible + .secondary-toolbar { display: none; } .bg-gray-200 { --tw-bg-opacity: 1; background-color: rgb(229 231 235/var(--tw-bg-opacity)); } .bg-blue-600 { --tw-bg-opacity: 1; background-color: rgb(28 100 242/var(--tw-bg-opacity)); } .border-\\[\\#6f6e77\\] { border-color: #6f6e77; } .cursor-help { cursor: help; } .dark .dark\\:border-gray-\\[\\#86858d\\] { border-color: #86858d; } .dark .dark\\:hover\\:bg-gray-700:hover { --tw-bg-opacity: 1; background-color: rgb(55 65 81/var(--tw-bg-opacity)); } .h-2\\.5 { height: 0.625rem; } .mr-8 { margin-right: 2rem; } .pr-8 { padding-right: 2rem; } .rounded-full { border-radius: 9999px; } .select-all { user-select: all!important; } .space-y-6>:not([hidden])~:not([hidden]) { --tw-space-y-reverse: 0; margin-top: calc(1.5rem * calc(1 - var(--tw-space-y-reverse))); margin-bottom: calc(1.5rem * var(--tw-space-y-reverse)); } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .whitespace-nowrap { white-space: nowrap; } @media (min-width:768px) { /* md */ } @media (min-width:1024px) { .lg\\:mt-0 { margin-top: 0; } .lg\\:top-8 { top: 2rem; } } `); var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; (function(JSZip2, html2canvas2) { "use strict"; var n, l$1, u$1, t$1, r$1, o$2, f$1, e$1, c$1 = {}, s$1 = [], a$1 = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i; function h$1(n2, l2) { for (var u2 in l2) n2[u2] = l2[u2]; return n2; } function v$1(n2) { var l2 = n2.parentNode; l2 && l2.removeChild(n2); } function y$1(l2, u2, i2) { var t2, r2, o2, f2 = {}; for (o2 in u2) "key" == o2 ? t2 = u2[o2] : "ref" == o2 ? r2 = u2[o2] : f2[o2] = u2[o2]; if (arguments.length > 2 && (f2.children = arguments.length > 3 ? n.call(arguments, 2) : i2), "function" == typeof l2 && null != l2.defaultProps) for (o2 in l2.defaultProps) void 0 === f2[o2] && (f2[o2] = l2.defaultProps[o2]); return p$2(l2, f2, t2, r2, null); } function p$2(n2, i2, t2, r2, o2) { var f2 = { type: n2, props: i2, key: t2, ref: r2, __k: null, __: null, __b: 0, __e: null, __d: void 0, __c: null, __h: null, constructor: void 0, __v: null == o2 ? ++u$1 : o2 }; return null == o2 && null != l$1.vnode && l$1.vnode(f2), f2; } function d$1() { return { current: null }; } function _$2(n2) { return n2.children; } function k$2(n2, l2) { this.props = n2, this.context = l2; } function b$1(n2, l2) { if (null == l2) return n2.__ ? b$1(n2.__, n2.__.__k.indexOf(n2) + 1) : null; for (var u2; l2 < n2.__k.length; l2++) if (null != (u2 = n2.__k[l2]) && null != u2.__e) return u2.__e; return "function" == typeof n2.type ? b$1(n2) : null; } function g$2(n2) { var l2, u2; if (null != (n2 = n2.__) && null != n2.__c) { for (n2.__e = n2.__c.base = null, l2 = 0; l2 < n2.__k.length; l2++) if (null != (u2 = n2.__k[l2]) && null != u2.__e) { n2.__e = n2.__c.base = u2.__e; break; } return g$2(n2); } } function m$1(n2) { (!n2.__d && (n2.__d = true) && t$1.push(n2) && !w$2.__r++ || r$1 !== l$1.debounceRendering) && ((r$1 = l$1.debounceRendering) || o$2)(w$2); } function w$2() { var n2, l2, u2, i2, r2, o2, e2, c2; for (t$1.sort(f$1); n2 = t$1.shift(); ) n2.__d && (l2 = t$1.length, i2 = void 0, r2 = void 0, e2 = (o2 = (u2 = n2).__v).__e, (c2 = u2.__P) && (i2 = [], (r2 = h$1({}, o2)).__v = o2.__v + 1, L$1(c2, o2, r2, u2.__n, void 0 !== c2.ownerSVGElement, null != o2.__h ? [e2] : null, i2, null == e2 ? b$1(o2) : e2, o2.__h), M$1(i2, o2), o2.__e != e2 && g$2(o2)), t$1.length > l2 && t$1.sort(f$1)); w$2.__r = 0; } function x$2(n2, l2, u2, i2, t2, r2, o2, f2, e2, a2) { var h2, v2, y2, d2, k2, g2, m2, w2 = i2 && i2.__k || s$1, x2 = w2.length; for (u2.__k = [], h2 = 0; h2 < l2.length; h2++) if (null != (d2 = u2.__k[h2] = null == (d2 = l2[h2]) || "boolean" == typeof d2 || "function" == typeof d2 ? null : "string" == typeof d2 || "number" == typeof d2 || "bigint" == typeof d2 ? p$2(null, d2, null, null, d2) : Array.isArray(d2) ? p$2(_$2, { children: d2 }, null, null, null) : d2.__b > 0 ? p$2(d2.type, d2.props, d2.key, d2.ref ? d2.ref : null, d2.__v) : d2)) { if (d2.__ = u2, d2.__b = u2.__b + 1, null === (y2 = w2[h2]) || y2 && d2.key == y2.key && d2.type === y2.type) w2[h2] = void 0; else for (v2 = 0; v2 < x2; v2++) { if ((y2 = w2[v2]) && d2.key == y2.key && d2.type === y2.type) { w2[v2] = void 0; break; } y2 = null; } L$1(n2, d2, y2 = y2 || c$1, t2, r2, o2, f2, e2, a2), k2 = d2.__e, (v2 = d2.ref) && y2.ref != v2 && (m2 || (m2 = []), y2.ref && m2.push(y2.ref, null, d2), m2.push(v2, d2.__c || k2, d2)), null != k2 ? (null == g2 && (g2 = k2), "function" == typeof d2.type && d2.__k === y2.__k ? d2.__d = e2 = A$2(d2, e2, n2) : e2 = C$1(n2, d2, y2, w2, k2, e2), "function" == typeof u2.type && (u2.__d = e2)) : e2 && y2.__e == e2 && e2.parentNode != n2 && (e2 = b$1(y2)); } for (u2.__e = g2, h2 = x2; h2--; ) null != w2[h2] && ("function" == typeof u2.type && null != w2[h2].__e && w2[h2].__e == u2.__d && (u2.__d = $$1(i2).nextSibling), S(w2[h2], w2[h2])); if (m2) for (h2 = 0; h2 < m2.length; h2++) O$1(m2[h2], m2[++h2], m2[++h2]); } function A$2(n2, l2, u2) { for (var i2, t2 = n2.__k, r2 = 0; t2 && r2 < t2.length; r2++) (i2 = t2[r2]) && (i2.__ = n2, l2 = "function" == typeof i2.type ? A$2(i2, l2, u2) : C$1(u2, i2, i2, t2, i2.__e, l2)); return l2; } function P$2(n2, l2) { return l2 = l2 || [], null == n2 || "boolean" == typeof n2 || (Array.isArray(n2) ? n2.some(function(n3) { P$2(n3, l2); }) : l2.push(n2)), l2; } function C$1(n2, l2, u2, i2, t2, r2) { var o2, f2, e2; if (void 0 !== l2.__d) o2 = l2.__d, l2.__d = void 0; else if (null == u2 || t2 != r2 || null == t2.parentNode) n: if (null == r2 || r2.parentNode !== n2) n2.appendChild(t2), o2 = null; else { for (f2 = r2, e2 = 0; (f2 = f2.nextSibling) && e2 < i2.length; e2 += 1) if (f2 == t2) break n; n2.insertBefore(t2, r2), o2 = r2; } return void 0 !== o2 ? o2 : t2.nextSibling; } function $$1(n2) { var l2, u2, i2; if (null == n2.type || "string" == typeof n2.type) return n2.__e; if (n2.__k) { for (l2 = n2.__k.length - 1; l2 >= 0; l2--) if ((u2 = n2.__k[l2]) && (i2 = $$1(u2))) return i2; } return null; } function H$1(n2, l2, u2, i2, t2) { var r2; for (r2 in u2) "children" === r2 || "key" === r2 || r2 in l2 || T$2(n2, r2, null, u2[r2], i2); for (r2 in l2) t2 && "function" != typeof l2[r2] || "children" === r2 || "key" === r2 || "value" === r2 || "checked" === r2 || u2[r2] === l2[r2] || T$2(n2, r2, l2[r2], u2[r2], i2); } function I$1(n2, l2, u2) { "-" === l2[0] ? n2.setProperty(l2, null == u2 ? "" : u2) : n2[l2] = null == u2 ? "" : "number" != typeof u2 || a$1.test(l2) ? u2 : u2 + "px"; } function T$2(n2, l2, u2, i2, t2) { var r2; n: if ("style" === l2) if ("string" == typeof u2) n2.style.cssText = u2; else { if ("string" == typeof i2 && (n2.style.cssText = i2 = ""), i2) for (l2 in i2) u2 && l2 in u2 || I$1(n2.style, l2, ""); if (u2) for (l2 in u2) i2 && u2[l2] === i2[l2] || I$1(n2.style, l2, u2[l2]); } else if ("o" === l2[0] && "n" === l2[1]) r2 = l2 !== (l2 = l2.replace(/Capture$/, "")), l2 = l2.toLowerCase() in n2 ? l2.toLowerCase().slice(2) : l2.slice(2), n2.l || (n2.l = {}), n2.l[l2 + r2] = u2, u2 ? i2 || n2.addEventListener(l2, r2 ? z$2 : j$2, r2) : n2.removeEventListener(l2, r2 ? z$2 : j$2, r2); else if ("dangerouslySetInnerHTML" !== l2) { if (t2) l2 = l2.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s"); else if ("width" !== l2 && "height" !== l2 && "href" !== l2 && "list" !== l2 && "form" !== l2 && "tabIndex" !== l2 && "download" !== l2 && l2 in n2) try { n2[l2] = null == u2 ? "" : u2; break n; } catch (n3) { } "function" == typeof u2 || (null == u2 || false === u2 && "-" !== l2[4] ? n2.removeAttribute(l2) : n2.setAttribute(l2, u2)); } } function j$2(n2) { return this.l[n2.type + false](l$1.event ? l$1.event(n2) : n2); } function z$2(n2) { return this.l[n2.type + true](l$1.event ? l$1.event(n2) : n2); } function L$1(n2, u2, i2, t2, r2, o2, f2, e2, c2) { var s2, a2, v2, y2, p2, d2, b2, g2, m2, w2, A2, P2, C2, $2, H2, I2 = u2.type; if (void 0 !== u2.constructor) return null; null != i2.__h && (c2 = i2.__h, e2 = u2.__e = i2.__e, u2.__h = null, o2 = [e2]), (s2 = l$1.__b) && s2(u2); try { n: if ("function" == typeof I2) { if (g2 = u2.props, m2 = (s2 = I2.contextType) && t2[s2.__c], w2 = s2 ? m2 ? m2.props.value : s2.__ : t2, i2.__c ? b2 = (a2 = u2.__c = i2.__c).__ = a2.__E : ("prototype" in I2 && I2.prototype.render ? u2.__c = a2 = new I2(g2, w2) : (u2.__c = a2 = new k$2(g2, w2), a2.constructor = I2, a2.render = q$2), m2 && m2.sub(a2), a2.props = g2, a2.state || (a2.state = {}), a2.context = w2, a2.__n = t2, v2 = a2.__d = true, a2.__h = [], a2._sb = []), null == a2.__s && (a2.__s = a2.state), null != I2.getDerivedStateFromProps && (a2.__s == a2.state && (a2.__s = h$1({}, a2.__s)), h$1(a2.__s, I2.getDerivedStateFromProps(g2, a2.__s))), y2 = a2.props, p2 = a2.state, a2.__v = u2, v2) null == I2.getDerivedStateFromProps && null != a2.componentWillMount && a2.componentWillMount(), null != a2.componentDidMount && a2.__h.push(a2.componentDidMount); else { if (null == I2.getDerivedStateFromProps && g2 !== y2 && null != a2.componentWillReceiveProps && a2.componentWillReceiveProps(g2, w2), !a2.__e && null != a2.shouldComponentUpdate && false === a2.shouldComponentUpdate(g2, a2.__s, w2) || u2.__v === i2.__v) { for (u2.__v !== i2.__v && (a2.props = g2, a2.state = a2.__s, a2.__d = false), a2.__e = false, u2.__e = i2.__e, u2.__k = i2.__k, u2.__k.forEach(function(n3) { n3 && (n3.__ = u2); }), A2 = 0; A2 < a2._sb.length; A2++) a2.__h.push(a2._sb[A2]); a2._sb = [], a2.__h.length && f2.push(a2); break n; } null != a2.componentWillUpdate && a2.componentWillUpdate(g2, a2.__s, w2), null != a2.componentDidUpdate && a2.__h.push(function() { a2.componentDidUpdate(y2, p2, d2); }); } if (a2.context = w2, a2.props = g2, a2.__P = n2, P2 = l$1.__r, C2 = 0, "prototype" in I2 && I2.prototype.render) { for (a2.state = a2.__s, a2.__d = false, P2 && P2(u2), s2 = a2.render(a2.props, a2.state, a2.context), $2 = 0; $2 < a2._sb.length; $2++) a2.__h.push(a2._sb[$2]); a2._sb = []; } else do { a2.__d = false, P2 && P2(u2), s2 = a2.render(a2.props, a2.state, a2.context), a2.state = a2.__s; } while (a2.__d && ++C2 < 25); a2.state = a2.__s, null != a2.getChildContext && (t2 = h$1(h$1({}, t2), a2.getChildContext())), v2 || null == a2.getSnapshotBeforeUpdate || (d2 = a2.getSnapshotBeforeUpdate(y2, p2)), H2 = null != s2 && s2.type === _$2 && null == s2.key ? s2.props.children : s2, x$2(n2, Array.isArray(H2) ? H2 : [H2], u2, i2, t2, r2, o2, f2, e2, c2), a2.base = u2.__e, u2.__h = null, a2.__h.length && f2.push(a2), b2 && (a2.__E = a2.__ = null), a2.__e = false; } else null == o2 && u2.__v === i2.__v ? (u2.__k = i2.__k, u2.__e = i2.__e) : u2.__e = N$1(i2.__e, u2, i2, t2, r2, o2, f2, c2); (s2 = l$1.diffed) && s2(u2); } catch (n3) { u2.__v = null, (c2 || null != o2) && (u2.__e = e2, u2.__h = !!c2, o2[o2.indexOf(e2)] = null), l$1.__e(n3, u2, i2); } } function M$1(n2, u2) { l$1.__c && l$1.__c(u2, n2), n2.some(function(u3) { try { n2 = u3.__h, u3.__h = [], n2.some(function(n3) { n3.call(u3); }); } catch (n3) { l$1.__e(n3, u3.__v); } }); } function N$1(l2, u2, i2, t2, r2, o2, f2, e2) { var s2, a2, h2, y2 = i2.props, p2 = u2.props, d2 = u2.type, _2 = 0; if ("svg" === d2 && (r2 = true), null != o2) { for (; _2 < o2.length; _2++) if ((s2 = o2[_2]) && "setAttribute" in s2 == !!d2 && (d2 ? s2.localName === d2 : 3 === s2.nodeType)) { l2 = s2, o2[_2] = null; break; } } if (null == l2) { if (null === d2) return document.createTextNode(p2); l2 = r2 ? document.createElementNS("http://www.w3.org/2000/svg", d2) : document.createElement(d2, p2.is && p2), o2 = null, e2 = false; } if (null === d2) y2 === p2 || e2 && l2.data === p2 || (l2.data = p2); else { if (o2 = o2 && n.call(l2.childNodes), a2 = (y2 = i2.props || c$1).dangerouslySetInnerHTML, h2 = p2.dangerouslySetInnerHTML, !e2) { if (null != o2) for (y2 = {}, _2 = 0; _2 < l2.attributes.length; _2++) y2[l2.attributes[_2].name] = l2.attributes[_2].value; (h2 || a2) && (h2 && (a2 && h2.__html == a2.__html || h2.__html === l2.innerHTML) || (l2.innerHTML = h2 && h2.__html || "")); } if (H$1(l2, p2, y2, r2, e2), h2) u2.__k = []; else if (_2 = u2.props.children, x$2(l2, Array.isArray(_2) ? _2 : [_2], u2, i2, t2, r2 && "foreignObject" !== d2, o2, f2, o2 ? o2[0] : i2.__k && b$1(i2, 0), e2), null != o2) for (_2 = o2.length; _2--; ) null != o2[_2] && v$1(o2[_2]); e2 || ("value" in p2 && void 0 !== (_2 = p2.value) && (_2 !== l2.value || "progress" === d2 && !_2 || "option" === d2 && _2 !== y2.value) && T$2(l2, "value", _2, y2.value, false), "checked" in p2 && void 0 !== (_2 = p2.checked) && _2 !== l2.checked && T$2(l2, "checked", _2, y2.checked, false)); } return l2; } function O$1(n2, u2, i2) { try { "function" == typeof n2 ? n2(u2) : n2.current = u2; } catch (n3) { l$1.__e(n3, i2); } } function S(n2, u2, i2) { var t2, r2; if (l$1.unmount && l$1.unmount(n2), (t2 = n2.ref) && (t2.current && t2.current !== n2.__e || O$1(t2, null, u2)), null != (t2 = n2.__c)) { if (t2.componentWillUnmount) try { t2.componentWillUnmount(); } catch (n3) { l$1.__e(n3, u2); } t2.base = t2.__P = null, n2.__c = void 0; } if (t2 = n2.__k) for (r2 = 0; r2 < t2.length; r2++) t2[r2] && S(t2[r2], u2, i2 || "function" != typeof n2.type); i2 || null == n2.__e || v$1(n2.__e), n2.__ = n2.__e = n2.__d = void 0; } function q$2(n2, l2, u2) { return this.constructor(n2, u2); } function B$2(u2, i2, t2) { var r2, o2, f2; l$1.__ && l$1.__(u2, i2), o2 = (r2 = "function" == typeof t2) ? null : t2 && t2.__k || i2.__k, f2 = [], L$1(i2, u2 = (!r2 && t2 || i2).__k = y$1(_$2, null, [u2]), o2 || c$1, c$1, void 0 !== i2.ownerSVGElement, !r2 && t2 ? [t2] : o2 ? null : i2.firstChild ? n.call(i2.childNodes) : null, f2, !r2 && t2 ? t2 : o2 ? o2.__e : i2.firstChild, r2), M$1(f2, u2); } function D$1(n2, l2) { B$2(n2, l2, D$1); } function E$1(l2, u2, i2) { var t2, r2, o2, f2 = h$1({}, l2.props); for (o2 in u2) "key" == o2 ? t2 = u2[o2] : "ref" == o2 ? r2 = u2[o2] : f2[o2] = u2[o2]; return arguments.length > 2 && (f2.children = arguments.length > 3 ? n.call(arguments, 2) : i2), p$2(l2.type, f2, t2 || l2.key, r2 || l2.ref, null); } function F$2(n2, l2) { var u2 = { __c: l2 = "__cC" + e$1++, __: n2, Consumer: function(n3, l3) { return n3.children(l3); }, Provider: function(n3) { var u3, i2; return this.getChildContext || (u3 = [], (i2 = {})[l2] = this, this.getChildContext = function() { return i2; }, this.shouldComponentUpdate = function(n4) { this.props.value !== n4.value && u3.some(function(n5) { n5.__e = true, m$1(n5); }); }, this.sub = function(n4) { u3.push(n4); var l3 = n4.componentWillUnmount; n4.componentWillUnmount = function() { u3.splice(u3.indexOf(n4), 1), l3 && l3.call(n4); }; }), n3.children; } }; return u2.Provider.__ = u2.Consumer.contextType = u2; } n = s$1.slice, l$1 = { __e: function(n2, l2, u2, i2) { for (var t2, r2, o2; l2 = l2.__; ) if ((t2 = l2.__c) && !t2.__) try { if ((r2 = t2.constructor) && null != r2.getDerivedStateFromError && (t2.setState(r2.getDerivedStateFromError(n2)), o2 = t2.__d), null != t2.componentDidCatch && (t2.componentDidCatch(n2, i2 || {}), o2 = t2.__d), o2) return t2.__E = t2; } catch (l3) { n2 = l3; } throw n2; } }, u$1 = 0, k$2.prototype.setState = function(n2, l2) { var u2; u2 = null != this.__s && this.__s !== this.state ? this.__s : this.__s = h$1({}, this.state), "function" == typeof n2 && (n2 = n2(h$1({}, u2), this.props)), n2 && h$1(u2, n2), null != n2 && this.__v && (l2 && this._sb.push(l2), m$1(this)); }, k$2.prototype.forceUpdate = function(n2) { this.__v && (this.__e = true, n2 && this.__h.push(n2), m$1(this)); }, k$2.prototype.render = _$2, t$1 = [], o$2 = "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, f$1 = function(n2, l2) { return n2.__v.__b - l2.__v.__b; }, w$2.__r = 0, e$1 = 0; var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; var sentinel_umdExports = {}; var sentinel_umd = { get exports() { return sentinel_umdExports; }, set exports(v2) { sentinel_umdExports = v2; } }; (function(module, exports) { (function(root2, factory) { { module.exports = factory(); } })(commonjsGlobal, function() { var isArray = Array.isArray, selectorToAnimationMap = {}, animationCallbacks = {}, styleEl, styleSheet, cssRules; return { /** * Add watcher. * @param {array} cssSelectors - List of CSS selector strings * @param {Function} callback - The callback function */ on: function(cssSelectors, callback) { if (!callback) return; if (!styleEl) { var doc = document, head2 = doc.head; doc.addEventListener("animationstart", function(ev, callbacks, l2, i2) { callbacks = animationCallbacks[ev.animationName]; if (!callbacks) return; ev.stopImmediatePropagation(); l2 = callbacks.length; for (i2 = 0; i2 < l2; i2++) callbacks[i2](ev.target); }, true); styleEl = doc.createElement("style"); head2.append(styleEl); styleSheet = styleEl.sheet; cssRules = styleSheet.cssRules; } (isArray(cssSelectors) ? cssSelectors : [cssSelectors]).map(function(selector, animId, isCustomName) { animId = selectorToAnimationMap[selector]; if (!animId) { isCustomName = selector[0] == "!"; selectorToAnimationMap[selector] = animId = isCustomName ? selector.slice(1) : "sentinel-" + Math.random().toString(16).slice(2); cssRules[styleSheet.insertRule( "@keyframes " + animId + "{from{transform:none;}to{transform:none;}}", cssRules.length )]._id = selector; if (!isCustomName) { cssRules[styleSheet.insertRule( selector + "{animation-duration:0.0001s;animation-name:" + animId + ";}", cssRules.length )]._id = selector; } selectorToAnimationMap[selector] = animId; } (animationCallbacks[animId] = animationCallbacks[animId] || []).push(callback); }); }, /** * Remove watcher. * @param {array} cssSelectors - List of CSS selector strings * @param {Function} callback - The callback function (optional) */ off: function(cssSelectors, callback) { (isArray(cssSelectors) ? cssSelectors : [cssSelectors]).map(function(selector, animId, callbackList, i2) { if (!(animId = selectorToAnimationMap[selector])) return; callbackList = animationCallbacks[animId]; if (callback) { i2 = callbackList.length; while (i2--) { if (callbackList[i2] === callback) callbackList.splice(i2, 1); } } else { callbackList = []; } if (callbackList.length) return; i2 = cssRules.length; while (i2--) { if (cssRules[i2]._id == selector) styleSheet.deleteRule(i2); } delete selectorToAnimationMap[selector]; delete animationCallbacks[animId]; }); }, /** * Reset watchers and cache */ reset: function() { selectorToAnimationMap = {}; animationCallbacks = {}; if (styleEl) styleEl.parentNode.removeChild(styleEl); styleEl = 0; } }; }); })(sentinel_umd); const sentinel = sentinel_umdExports; var monkeyWindow = window; var unsafeWindow = /* @__PURE__ */ (() => { return monkeyWindow.unsafeWindow; })(); var GM_setValue = /* @__PURE__ */ (() => monkeyWindow.GM_setValue)(); var GM_deleteValue = /* @__PURE__ */ (() => monkeyWindow.GM_deleteValue)(); var GM_getValue = /* @__PURE__ */ (() => monkeyWindow.GM_getValue)(); const baseUrl = "https://chat.openai.com"; const LEGACY_KEY_FILENAME_FORMAT = "exporter-format"; const KEY_FILENAME_FORMAT = "exporter:filename_format"; const KEY_META_ENABLED = "exporter:enable_meta"; const KEY_META_LIST = "exporter:meta_list"; var t, r, u, i, o$1 = 0, f = [], c = [], e = l$1.__b, a = l$1.__r, v = l$1.diffed, l = l$1.__c, m = l$1.unmount; function d(t2, u2) { l$1.__h && l$1.__h(r, t2, o$1 || u2), o$1 = 0; var i2 = r.__H || (r.__H = { __: [], __h: [] }); return t2 >= i2.__.length && i2.__.push({ __V: c }), i2.__[t2]; } function h(n2) { return o$1 = 1, s(B$1, n2); } function s(n2, u2, i2) { var o2 = d(t++, 2); if (o2.t = n2, !o2.__c && (o2.__ = [i2 ? i2(u2) : B$1(void 0, u2), function(n3) { var t2 = o2.__N ? o2.__N[0] : o2.__[0], r2 = o2.t(t2, n3); t2 !== r2 && (o2.__N = [r2, o2.__[1]], o2.__c.setState({})); }], o2.__c = r, !r.u)) { var f2 = function(n3, t2, r2) { if (!o2.__c.__H) return true; var u3 = o2.__c.__H.__.filter(function(n4) { return n4.__c; }); if (u3.every(function(n4) { return !n4.__N; })) return !c2 || c2.call(this, n3, t2, r2); var i3 = false; return u3.forEach(function(n4) { if (n4.__N) { var t3 = n4.__[0]; n4.__ = n4.__N, n4.__N = void 0, t3 !== n4.__[0] && (i3 = true); } }), !(!i3 && o2.__c.props === n3) && (!c2 || c2.call(this, n3, t2, r2)); }; r.u = true; var c2 = r.shouldComponentUpdate, e2 = r.componentWillUpdate; r.componentWillUpdate = function(n3, t2, r2) { if (this.__e) { var u3 = c2; c2 = void 0, f2(n3, t2, r2), c2 = u3; } e2 && e2.call(this, n3, t2, r2); }, r.shouldComponentUpdate = f2; } return o2.__N || o2.__; } function p$1(u2, i2) { var o2 = d(t++, 3); !l$1.__s && z$1(o2.__H, i2) && (o2.__ = u2, o2.i = i2, r.__H.__h.push(o2)); } function y(u2, i2) { var o2 = d(t++, 4); !l$1.__s && z$1(o2.__H, i2) && (o2.__ = u2, o2.i = i2, r.__h.push(o2)); } function _$1(n2) { return o$1 = 5, F$1(function() { return { current: n2 }; }, []); } function A$1(n2, t2, r2) { o$1 = 6, y(function() { return "function" == typeof n2 ? (n2(t2()), function() { return n2(null); }) : n2 ? (n2.current = t2(), function() { return n2.current = null; }) : void 0; }, null == r2 ? r2 : r2.concat(n2)); } function F$1(n2, r2) { var u2 = d(t++, 7); return z$1(u2.__H, r2) ? (u2.__V = n2(), u2.i = r2, u2.__h = n2, u2.__V) : u2.__; } function T$1(n2, t2) { return o$1 = 8, F$1(function() { return n2; }, t2); } function q$1(n2) { var u2 = r.context[n2.__c], i2 = d(t++, 9); return i2.c = n2, u2 ? (null == i2.__ && (i2.__ = true, u2.sub(r)), u2.props.value) : n2.__; } function x$1(t2, r2) { l$1.useDebugValue && l$1.useDebugValue(r2 ? r2(t2) : t2); } function P$1(n2) { var u2 = d(t++, 10), i2 = h(); return u2.__ = n2, r.componentDidCatch || (r.componentDidCatch = function(n3, t2) { u2.__ && u2.__(n3, t2), i2[1](n3); }), [i2[0], function() { i2[1](void 0); }]; } function V$1() { var n2 = d(t++, 11); if (!n2.__) { for (var u2 = r.__v; null !== u2 && !u2.__m && null !== u2.__; ) u2 = u2.__; var i2 = u2.__m || (u2.__m = [0, 0]); n2.__ = "P" + i2[0] + "-" + i2[1]++; } return n2.__; } function b() { for (var t2; t2 = f.shift(); ) if (t2.__P && t2.__H) try { t2.__H.__h.forEach(k$1), t2.__H.__h.forEach(w$1), t2.__H.__h = []; } catch (r2) { t2.__H.__h = [], l$1.__e(r2, t2.__v); } } l$1.__b = function(n2) { r = null, e && e(n2); }, l$1.__r = function(n2) { a && a(n2), t = 0; var i2 = (r = n2.__c).__H; i2 && (u === r ? (i2.__h = [], r.__h = [], i2.__.forEach(function(n3) { n3.__N && (n3.__ = n3.__N), n3.__V = c, n3.__N = n3.i = void 0; })) : (i2.__h.forEach(k$1), i2.__h.forEach(w$1), i2.__h = [])), u = r; }, l$1.diffed = function(t2) { v && v(t2); var o2 = t2.__c; o2 && o2.__H && (o2.__H.__h.length && (1 !== f.push(o2) && i === l$1.requestAnimationFrame || ((i = l$1.requestAnimationFrame) || j$1)(b)), o2.__H.__.forEach(function(n2) { n2.i && (n2.__H = n2.i), n2.__V !== c && (n2.__ = n2.__V), n2.i = void 0, n2.__V = c; })), u = r = null; }, l$1.__c = function(t2, r2) { r2.some(function(t3) { try { t3.__h.forEach(k$1), t3.__h = t3.__h.filter(function(n2) { return !n2.__ || w$1(n2); }); } catch (u2) { r2.some(function(n2) { n2.__h && (n2.__h = []); }), r2 = [], l$1.__e(u2, t3.__v); } }), l && l(t2, r2); }, l$1.unmount = function(t2) { m && m(t2); var r2, u2 = t2.__c; u2 && u2.__H && (u2.__H.__.forEach(function(n2) { try { k$1(n2); } catch (n3) { r2 = n3; } }), u2.__H = void 0, r2 && l$1.__e(r2, u2.__v)); }; var g$1 = "function" == typeof requestAnimationFrame; function j$1(n2) { var t2, r2 = function() { clearTimeout(u2), g$1 && cancelAnimationFrame(t2), setTimeout(n2); }, u2 = setTimeout(r2, 100); g$1 && (t2 = requestAnimationFrame(r2)); } function k$1(n2) { var t2 = r, u2 = n2.__c; "function" == typeof u2 && (n2.__c = void 0, u2()), r = t2; } function w$1(n2) { var t2 = r; n2.__c = n2.__(), r = t2; } function z$1(n2, t2) { return !n2 || n2.length !== t2.length || t2.some(function(t3, r2) { return t3 !== n2[r2]; }); } function B$1(n2, t2) { return "function" == typeof t2 ? t2(n2) : t2; } var dist = {}; var __assign$1 = commonjsGlobal && commonjsGlobal.__assign || function() { __assign$1 = Object.assign || function(t2) { for (var s2, i2 = 1, n2 = arguments.length; i2 < n2; i2++) { s2 = arguments[i2]; for (var p2 in s2) if (Object.prototype.hasOwnProperty.call(s2, p2)) t2[p2] = s2[p2]; } return t2; }; return __assign$1.apply(this, arguments); }; Object.defineProperty(dist, "__esModule", { value: true }); dist.join = dist.subst = dist.query = void 0; function urlcat(baseUrlOrTemplate, pathTemplateOrParams, maybeParams) { if (maybeParams === void 0) { maybeParams = {}; } if (typeof pathTemplateOrParams === "string") { var baseUrl2 = baseUrlOrTemplate; var pathTemplate = pathTemplateOrParams; var params = maybeParams; return urlcatImpl(pathTemplate, params, baseUrl2); } else { var baseTemplate = baseUrlOrTemplate; var params = pathTemplateOrParams; return urlcatImpl(baseTemplate, params); } } var _default = dist.default = urlcat; function urlcatImpl(pathTemplate, params, baseUrl2) { var _a = path$1(pathTemplate, params), renderedPath = _a.renderedPath, remainingParams = _a.remainingParams; var cleanParams = removeNullOrUndef(remainingParams); var renderedQuery = query(cleanParams); var pathAndQuery = join$1(renderedPath, "?", renderedQuery); return baseUrl2 ? join$1(baseUrl2, "/", pathAndQuery) : pathAndQuery; } function query(params) { return new URLSearchParams(params).toString(); } dist.query = query; function subst(template, params) { var renderedPath = path$1(template, params).renderedPath; return renderedPath; } dist.subst = subst; function path$1(template, params) { var remainingParams = __assign$1({}, params); var allowedTypes = ["boolean", "string", "number"]; var renderedPath = template.replace(/:\w+/g, function(p2) { var key2 = p2.slice(1); if (/^\d+$/.test(key2)) { return p2; } if (!params.hasOwnProperty(key2)) { throw new Error("Missing value for path parameter " + key2 + "."); } if (!allowedTypes.includes(typeof params[key2])) { throw new TypeError("Path parameter " + key2 + " cannot be of type " + typeof params[key2] + ". " + ("Allowed types are: " + allowedTypes.join(", ") + ".")); } if (typeof params[key2] === "string" && params[key2].trim() === "") { throw new Error("Path parameter " + key2 + " cannot be an empty string."); } delete remainingParams[key2]; return encodeURIComponent(params[key2]); }); return { renderedPath, remainingParams }; } function join$1(part1, separator, part2) { var p1 = part1.endsWith(separator) ? part1.slice(0, -separator.length) : part1; var p2 = part2.startsWith(separator) ? part2.slice(separator.length) : part2; return p1 === "" || p2 === "" ? p1 + p2 : p1 + separator + p2; } dist.join = join$1; function removeNullOrUndef(params) { return Object.keys(params).filter(function(k2) { return notNullOrUndefined(params[k2]); }).reduce(function(result, k2) { result[k2] = params[k2]; return result; }, {}); } function notNullOrUndefined(v2) { return v2 !== void 0 && v2 !== null; } function getBase64FromImg(el) { const canvas = document.createElement("canvas"); canvas.width = el.naturalWidth; canvas.height = el.naturalHeight; const ctx = canvas.getContext("2d"); if (!ctx) return ""; ctx.drawImage(el, 0, 0); return canvas.toDataURL("image/png"); } async function getBase64FromImageUrl(url) { const img = await loadImage(url); return getBase64FromImg(img); } function loadImage(url) { return new Promise((resolve, reject) => { const img = new Image(); img.src = url; img.crossOrigin = "anonymous"; img.onload = () => resolve(img); img.onerror = reject; }); } function getPageAccessToken() { var _a, _b, _c; return ((_c = (_b = (_a = unsafeWindow == null ? void 0 : unsafeWindow.__NEXT_DATA__) == null ? void 0 : _a.props) == null ? void 0 : _b.pageProps) == null ? void 0 : _c.accessToken) ?? null; } function getHistoryDisabled() { var _a, _b, _c; return ((_c = (_b = (_a = unsafeWindow == null ? void 0 : unsafeWindow.__NEXT_DATA__) == null ? void 0 : _a.props) == null ? void 0 : _b.pageProps) == null ? void 0 : _c.shouldDisableHistory) ?? false; } function getUserProfile() { var _a, _b, _c; const user = (_c = (_b = (_a = unsafeWindow == null ? void 0 : unsafeWindow.__NEXT_DATA__) == null ? void 0 : _a.props) == null ? void 0 : _b.pageProps) == null ? void 0 : _c.user; if (!user) throw new Error("No user found."); return user; } function getChatIdFromUrl() { const match = location.pathname.match(/^\/chat\/([a-z0-9-]+)$/i); if (match) return match[1]; return null; } function getConversationChoice() { const conversationChoices = Array.from(document.querySelectorAll("main .group")).map((group) => group.querySelector(".flex.justify-center span.flex-grow")).map((span) => { var _a; return parseInt(((_a = span == null ? void 0 : span.textContent) == null ? void 0 : _a.trim().split(" / ")[0]) ?? "0") - 1; }).map((x2) => x2 === -1 ? null : x2); return conversationChoices; } const defaultAvatar = "data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e"; async function getUserAvatar() { try { const { picture } = getUserProfile(); if (picture) return await getBase64FromImageUrl(picture); } catch (e2) { console.error(e2); } try { const avatars = Array.from(document.querySelectorAll("img[alt]:not([aria-hidden])")); const avatar = avatars.find((avatar2) => !avatar2.src.startsWith("data:")); if (avatar) return getBase64FromImg(avatar); } catch (e2) { console.error(e2); } return defaultAvatar; } function checkIfConversationStarted() { return !!document.querySelector("main .group"); } const apiUrl = `${baseUrl}/backend-api`; const sessionApi = _default(baseUrl, "/api/auth/session"); const conversationApi = (id) => _default(apiUrl, "/conversation/:id", { id }); const conversationsApi = (offset, limit) => _default(apiUrl, "/conversations", { offset, limit }); async function getCurrentChatId() { const chatId = getChatIdFromUrl(); if (chatId) return chatId; const conversations = await fetchConversations(); if (conversations && conversations.items.length > 0) { return conversations.items[0].id; } throw new Error("No chat id found."); } async function fetchConversation(chatId) { const url = conversationApi(chatId); const conversation = await fetchApi(url); return { id: chatId, ...conversation }; } async function fetchConversations(offset = 0, limit = 20) { const url = conversationsApi(offset, limit); return fetchApi(url); } async function fetchAllConversations() { const conversations = []; const limit = 20; let offset = 0; while (true) { const result = await fetchConversations(offset, limit); conversations.push(...result.items); if (offset + limit >= result.total) break; offset += limit; } return conversations; } async function fetchApi(url) { const accessToken = await getAccessToken(); const response = await fetch(url, { headers: { Authorization: `Bearer ${accessToken}` } }); if (!response.ok) { throw new Error(response.statusText); } return response.json(); } async function getAccessToken() { const _accessToken = getPageAccessToken(); if (_accessToken) return _accessToken; const session2 = await fetchSession(); return session2.accessToken; } let session = null; async function fetchSession() { if (session) return session; const response = await fetch(sessionApi); if (!response.ok) { throw new Error(response.statusText); } session = await response.json(); return session; } class LinkedListItem { constructor(value) { __publicField(this, "value"); __publicField(this, "child", null); this.value = value; } } const modelMapping = { "text-davinci-002-render-sha": "GTP-3.5", "text-davinci-002-render-paid": "GTP-3.5", "gpt-4": "GPT-4" }; function processConversation(conversation, conversationChoices = []) { var _a, _b, _c, _d; const title = conversation.title || "ChatGPT Conversation"; const createTime = conversation.create_time; const modelSlug = ((_c = (_b = (_a = Object.values(conversation.mapping).find((node2) => { var _a2, _b2; return (_b2 = (_a2 = node2.message) == null ? void 0 : _a2.metadata) == null ? void 0 : _b2.model_slug; })) == null ? void 0 : _a.message) == null ? void 0 : _b.metadata) == null ? void 0 : _c.model_slug) || ""; const model = modelSlug ? modelMapping[modelSlug] || "" : ""; const result = []; const nodes = Object.values(conversation.mapping); const root2 = nodes.find((node2) => !node2.parent); if (!root2) throw new Error("No root node found."); const nodeMap = new Map(Object.entries(conversation.mapping)); const tail = new LinkedListItem(root2); const queue = [tail]; let index2 = -1; while (queue.length > 0) { const current = queue.shift(); const node2 = nodeMap.get(current.value.id); if (!node2) throw new Error("No node found."); const role = (_d = node2.message) == null ? void 0 : _d.author.role; if (role === "assistant" || role === "user") { result.push(node2); } if (node2.children.length === 0) continue; const _last = node2.children.length - 1; const choice = conversationChoices[index2++] ?? _last; const childId = node2.children[choice] ?? node2.children[_last]; if (!childId) throw new Error("No child node found."); const child = nodeMap.get(childId); if (!child) throw new Error("No child node found."); const childItem = new LinkedListItem(child); current.child = childItem; queue.push(childItem); } return { id: conversation.id, title, modelSlug, model, createTime, conversationNodes: result }; } const templateHtml = `