Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ai/chatgpt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [1.1.2] - 2026-11-10

### Fixed

- Fixed language detection crashing when code has no recognized language signals.
- Replaced the placeholder regular expression with a single-pass delimiter scanner.
- Fixed Markdown table escaping for backslashes and pipes.
- Fixed shared export parsing of escaped table cells.
- Export failures are now logged with their actual error.

## [1.1.1] - 2026-11-10

### Export and reliability
Expand Down Expand Up @@ -67,3 +77,4 @@
[1.0.0]: https://github.com/thenolle/userscripts/releases/tag/better-chatgpt-v1.0.0
[1.1.0]: https://github.com/thenolle/userscripts/releases/tag/better-chatgpt-v1.1.0
[1.1.1]: https://github.com/thenolle/userscripts/releases/tag/better-chatgpt-v1.1.1
[1.1.2]: https://github.com/thenolle/userscripts/releases/tag/better-chatgpt-v1.1.2
4 changes: 4 additions & 0 deletions ai/chatgpt/docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ Open the browser console on chatgpt.com and run `betterChatgptDump()`. It prints
- **Export finds no messages:** ChatGPT changed how it marks messages. The dump shows `page.turns`; if both counts are 0 while messages are on screen, report it.
- **Limits are empty:** send a message or reload the page.
- **Update check failed (404):** the first release has not been published yet.

## Code and table fixes in 1.1.2

Code with no recognized language is displayed using the plain-text fallback. Markdown table exports escape backslashes and pipes; the shared document parser preserves those cell contents.
2 changes: 1 addition & 1 deletion ai/chatgpt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nolly/ai-chatgpt",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"type": "module",
"license": "PolyForm-Strict-1.0.0",
Expand Down
221 changes: 121 additions & 100 deletions ai/chatgpt/src/dom-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,123 +11,144 @@ const tex = (element: HTMLElement): string => element.querySelector('annotation[
const wrap = (mark: string, value: string): string => (value.trim() ? `${mark}${value.trim()}${mark}` : value)

const inline = (node: Node): string => {
if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? '').replace(/\s+/g, ' ')
if (!(node instanceof HTMLElement) || skipped(node)) return ''
if (node.classList.contains('katex-display')) return `\n\n$$${tex(node)}$$\n\n`
if (node.classList.contains('katex')) return `$${tex(node)}$`
if (node.hasAttribute('data-pill')) {
const href = node.querySelector('a[href]')?.getAttribute('href')
const label = (node.textContent ?? '').trim()
return href && label ? ` [${label}](${href})` : ''
}
const inner = (): string => [...node.childNodes].map(inline).join('')
if (node.hasAttribute('data-d-default-strong')) return wrap('**', inner())
switch (node.tagName) {
case 'BR':
return ' \n'
case 'STRONG':
case 'B':
return wrap('**', inner())
case 'EM':
case 'I':
return wrap('*', inner())
case 'DEL':
case 'S':
return wrap('~~', inner())
case 'CODE':
return `\`${node.textContent ?? ''}\``
case 'A': {
const href = node.getAttribute('href')
const label = inner().trim()
return href && label ? `[${label}](${href})` : label
}
case 'IMG': {
const source = node.getAttribute('src')
return source ? `![${node.getAttribute('alt') ?? ''}](${source})` : ''
}
default:
return inner()
}
if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? '').replace(/\s+/g, ' ')
if (!(node instanceof HTMLElement) || skipped(node)) return ''
if (node.classList.contains('katex-display')) return `\n\n$$${tex(node)}$$\n\n`
if (node.classList.contains('katex')) return `$${tex(node)}$`
if (node.hasAttribute('data-pill')) {
const href = node.querySelector('a[href]')?.getAttribute('href')
const label = (node.textContent ?? '').trim()
return href && label ? ` [${label}](${href})` : ''
}
const inner = (): string => [...node.childNodes].map(inline).join('')
if (node.hasAttribute('data-d-default-strong')) return wrap('**', inner())
switch (node.tagName) {
case 'BR':
return ' \n'
case 'STRONG':
case 'B':
return wrap('**', inner())
case 'EM':
case 'I':
return wrap('*', inner())
case 'DEL':
case 'S':
return wrap('~~', inner())
case 'CODE':
return `\`${node.textContent ?? ''}\``
case 'A': {
const href = node.getAttribute('href')
const label = inner().trim()
return href && label ? `[${label}](${href})` : label
}
case 'IMG': {
const source = node.getAttribute('src')
return source ? `![${node.getAttribute('alt') ?? ''}](${source})` : ''
}
default:
return inner()
}
}

const fence = (pre: HTMLElement): string => {
const raw = pre.closest('[data-chatgpt-copy-code]')?.getAttribute('data-chatgpt-copy-code') ?? (pre.querySelector('code') ?? pre).textContent ?? ''
const label = pre.closest('[data-code-block]')?.querySelector('[data-markdown-copy="exclude"] .truncate')?.textContent ?? ''
const language = label.trim().toLowerCase().replace(/\s+/g, '-')
return `\`\`\`${language}\n${raw.replace(/\n$/, '')}\n\`\`\``
const raw = pre.closest('[data-chatgpt-copy-code]')?.getAttribute('data-chatgpt-copy-code') ?? (pre.querySelector('code') ?? pre).textContent ?? ''
const label = pre.closest('[data-code-block]')?.querySelector('[data-markdown-copy="exclude"] .truncate')?.textContent ?? ''
const language = label.trim().toLowerCase().replace(/\s+/g, '-')
return `\`\`\`${language}\n${raw.replace(/\n$/, '')}\n\`\`\``
}

const escapeTableCell = (value: string): string => {
const parts: string[] = []

for (const character of value) {
if (character === '\\' || character === '|') parts.push('\\')
parts.push(character)
}

return parts.join('').replace(/\s+/g, ' ').trim()
}

const table = (element: HTMLElement): string => {
const rows = [...element.querySelectorAll('tr')].map((row) => [...row.children].map((cell) => inline(cell).replace(/\|/g, '\\|').replace(/\s+/g, ' ').trim()))
if (!rows.length) return ''
const width = Math.max(...rows.map((row) => row.length))
const line = (row: string[]): string => `| ${Array.from({ length: width }, (_, index) => row[index] ?? '').join(' | ')} |`
const [head, ...body] = rows
return [line(head ?? []), `| ${Array.from({ length: width }, () => '---').join(' | ')} |`, ...body.map(line)].join('\n')
const rows = [...element.querySelectorAll('tr')].filter((row) => row.closest('table') === element).map((row) => [...row.children].map((cell) => escapeTableCell(inline(cell))))

if (!rows.length) return ''

const width = rows.reduce((maximum, row) => Math.max(maximum, row.length), 0)
if (!width) return ''

const line = (row: readonly string[]): string => `| ${Array.from({ length: width }, (_, index) => row[index] ?? '').join(' | ')} |`

const [head, ...body] = rows

return [
line(head ?? []),
line(Array.from({ length: width }, () => '---')),
...body.map(line)
].join('\n')
}

const flat = (node: Node): Node[] => (node instanceof HTMLElement && node.tagName === 'DIV' && !skipped(node) ? [...node.childNodes].flatMap(flat) : [node])

const list = (element: HTMLElement, depth: number): string => {
const ordered = element.tagName === 'OL'
let index = Number.parseInt(element.getAttribute('start') ?? '1', 10) || 1
const indent = ' '.repeat(depth)
const lines: string[] = []
for (const item of element.children) {
if (!(item instanceof HTMLElement) || item.tagName !== 'LI' || skipped(item)) continue
const own: string[] = []
const nested: string[] = []
for (const child of [...item.childNodes].flatMap(flat)) {
if (child instanceof HTMLElement && (child.tagName === 'UL' || child.tagName === 'OL')) nested.push(list(child, depth + 1))
else if (child instanceof HTMLElement && child.tagName === 'PRE') nested.push(fence(child).split('\n').map((line) => `${indent} ${line}`).join('\n'))
else own.push(child instanceof HTMLElement && child.tagName === 'P' ? `${inline(child)} ` : inline(child))
}
lines.push(`${indent}${ordered ? `${index++}.` : '-'} ${own.join('').trim()}`, ...nested.filter(Boolean))
}
return lines.join('\n')
const ordered = element.tagName === 'OL'
let index = Number.parseInt(element.getAttribute('start') ?? '1', 10) || 1
const indent = ' '.repeat(depth)
const lines: string[] = []
for (const item of element.children) {
if (!(item instanceof HTMLElement) || item.tagName !== 'LI' || skipped(item)) continue
const own: string[] = []
const nested: string[] = []
for (const child of [...item.childNodes].flatMap(flat)) {
if (child instanceof HTMLElement && (child.tagName === 'UL' || child.tagName === 'OL')) nested.push(list(child, depth + 1))
else if (child instanceof HTMLElement && child.tagName === 'PRE') nested.push(fence(child).split('\n').map((line) => `${indent} ${line}`).join('\n'))
else own.push(child instanceof HTMLElement && child.tagName === 'P' ? `${inline(child)} ` : inline(child))
}
lines.push(`${indent}${ordered ? `${index++}.` : '-'} ${own.join('').trim()}`, ...nested.filter(Boolean))
}
return lines.join('\n')
}

const block = (element: HTMLElement): string => {
if (skipped(element)) return ''
const heading = HEADING.exec(element.tagName)
if (heading) return `${'#'.repeat(Number(heading[1]))} ${[...element.childNodes].map(inline).join('').trim()}`
switch (element.tagName) {
case 'P':
return [...element.childNodes].map(inline).join('').trim()
case 'UL':
case 'OL':
return list(element, 0)
case 'PRE':
return fence(element)
case 'HR':
return '---'
case 'TABLE':
return table(element)
case 'BLOCKQUOTE':
return children(element).split('\n').map((line) => `> ${line}`).join('\n')
default:
return children(element)
}
if (skipped(element)) return ''
const heading = HEADING.exec(element.tagName)
if (heading) return `${'#'.repeat(Number(heading[1]))} ${[...element.childNodes].map(inline).join('').trim()}`
switch (element.tagName) {
case 'P':
return [...element.childNodes].map(inline).join('').trim()
case 'UL':
case 'OL':
return list(element, 0)
case 'PRE':
return fence(element)
case 'HR':
return '---'
case 'TABLE':
return table(element)
case 'BLOCKQUOTE':
return children(element).split('\n').map((line) => `> ${line}`).join('\n')
default:
return children(element)
}
}

const children = (element: HTMLElement): string => {
const parts: string[] = []
let run = ''
const flush = (): void => {
if (run.trim()) parts.push(run.trim())
run = ''
}
for (const child of element.childNodes) {
if (child instanceof HTMLElement && BLOCKS.has(child.tagName)) {
flush()
const value = block(child)
if (value) parts.push(value)
} else {
run += inline(child)
}
}
flush()
return parts.join('\n\n')
const parts: string[] = []
let run = ''
const flush = (): void => {
if (run.trim()) parts.push(run.trim())
run = ''
}
for (const child of element.childNodes) {
if (child instanceof HTMLElement && BLOCKS.has(child.tagName)) {
flush()
const value = block(child)
if (value) parts.push(value)
} else {
run += inline(child)
}
}
flush()
return parts.join('\n\n')
}

export const toMarkdown = (root: HTMLElement): string => children(root).replace(/\n{3,}/g, '\n\n').trim()
12 changes: 12 additions & 0 deletions ai/perplexity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to Better Perplexity are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).

## [1.1.2] - 2026-11-10

### Fixed

- Fixed language detection crashing when code has no recognized language signals.
- Replaced the placeholder regular expression with a single-pass delimiter scanner.
- Added exporter request timeouts, transport fallback and response validation.
- Export errors now identify the endpoint, HTTP status and transport.
- Preserved thread-UUID recovery when the first export identifier is rejected.
- Fixed shared export parsing of escaped table cells.

## [1.1.1] - 2026-11-10

### Export and reliability
Expand Down Expand Up @@ -158,3 +169,4 @@ First public release.
[1.0.5-hotfix.1]: https://github.com/thenolle/userscripts/releases/tag/better-perplexity-v1.0.5-hotfix.1
[1.1.0]: https://github.com/thenolle/userscripts/releases/tag/better-perplexity-v1.1.0
[1.1.1]: https://github.com/thenolle/userscripts/releases/tag/better-perplexity-v1.1.1
[1.1.2]: https://github.com/thenolle/userscripts/releases/tag/better-perplexity-v1.1.2
10 changes: 10 additions & 0 deletions ai/perplexity/docs/code-and-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ Choose how sources appear: parenthesized links, inline links, domain names, a nu
## PDF workflow

PDF saving uses the browser print dialog. The preview contains selectable text, linked contents, styled sections, code panels and tables. See [PDF reports](pdf-reports.md) for colors, page numbers and limitations.

## Export failures

If export fails, the dialog reports the request and transport error. The browser console also logs “Conversation export failed”.

The exporter tries its existing session API with sandbox fetch, then page fetch where available. Requests have a timeout. If the first identifier fails, a thread-detail lookup may supply the thread UUID.

Raw JSON is a separate thread request, not a guaranteed offline fallback. If both requests fail, include their status messages in a bug report. Do not include tokens or private thread contents.

The exporter does not disable CORS, CSP, subresource integrity, browser tracking protection or site access restrictions.
2 changes: 1 addition & 1 deletion ai/perplexity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nolly/ai-perplexity",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"type": "module",
"license": "PolyForm-Strict-1.0.0",
Expand Down
Loading
Loading