fix: remove revison and buttons from screenshot

This commit is contained in:
Pionxzh
2023-04-24 22:36:19 +08:00
parent 42a1d75ca7
commit ba41b79516
2 changed files with 28 additions and 2 deletions
+25 -1
View File
@@ -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
+3 -1
View File
@@ -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)