mirror of
https://github.com/pionxzh/chatgpt-exporter.git
synced 2026-09-21 13:37:42 -05:00
fix: remove revison and buttons from screenshot
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import html2canvas from 'html2canvas'
|
||||
import i18n from '../i18n'
|
||||
import { checkIfConversationStarted, getChatIdFromUrl } from '../page'
|
||||
import { checkIfConversationStarted, conversationChoiceSelector, getChatIdFromUrl } from '../page'
|
||||
import { downloadUrl, getFileNameWithFormat } from '../utils/download'
|
||||
import { Effect } from '../utils/effect'
|
||||
import { sleep } from '../utils/utils'
|
||||
@@ -37,6 +37,30 @@ export async function exportToPng(fileNameFormat: string) {
|
||||
return () => bottomBar.classList.remove('hidden')
|
||||
})
|
||||
|
||||
// hide buttons
|
||||
const buttonWrappers = document.querySelectorAll<HTMLDivElement>('main .flex.justify-between')
|
||||
buttonWrappers.forEach((wrapper) => {
|
||||
if (!wrapper.querySelector('button')) return
|
||||
// ignore codeblock
|
||||
if (wrapper.closest('pre')) return
|
||||
|
||||
effect.add(() => {
|
||||
wrapper.style.display = 'none'
|
||||
return () => wrapper.style.display = ''
|
||||
})
|
||||
})
|
||||
|
||||
// hide conversation choices. eg. <1 / 6>
|
||||
const conversationChoices = document.querySelectorAll(conversationChoiceSelector)
|
||||
conversationChoices.forEach((choice) => {
|
||||
effect.add(() => {
|
||||
const parent = choice.parentElement
|
||||
if (!parent) return
|
||||
parent.classList.add('hidden')
|
||||
return () => parent.classList.remove('hidden')
|
||||
})
|
||||
})
|
||||
|
||||
// disabled the avatar srcset
|
||||
// fix https://github.com/pionxzh/chatgpt-exporter/issues/53
|
||||
// seems related to https://github.com/niklasvh/html2canvas/issues/2218
|
||||
|
||||
@@ -47,10 +47,12 @@ export function getChatIdFromUrl() {
|
||||
return null
|
||||
}
|
||||
|
||||
export const conversationChoiceSelector = '.flex.justify-center span.flex-grow'
|
||||
|
||||
export function getConversationChoice() {
|
||||
// parse x from `< x / y >` to get the index of the selected response
|
||||
const conversationChoices: Array<number | null> = Array.from(document.querySelectorAll('main .group'))
|
||||
.map(group => group.querySelector('.flex.justify-center span.flex-grow'))
|
||||
.map(group => group.querySelector(conversationChoiceSelector))
|
||||
// non-existing element will produce null here, which will point to the last child
|
||||
// just in case the selector changed
|
||||
.map(span => parseInt(span?.textContent?.trim().split(' / ')[0] ?? '0') - 1)
|
||||
|
||||
Reference in New Issue
Block a user