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
16 changes: 16 additions & 0 deletions ai/chatgpt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [1.2.0] - 2026-11-10

### Changed

- Renamed Code Block Pro to Code Blocks V2.
- Rebuilt code selection around actual newline text nodes and source-faithful content.
- Added restrained toolbar styling, explicit folding, and a non-selectable line-number gutter.
- Improved shared dialog spacing and form styling.

### Fixed

- Removed unverified usage totals and misleading quota interpretations.
- ChatGPT header tools explicitly restore pointer interaction and reattach to the visible native row.
- Expired ChatGPT tool counters are labelled as awaiting an update rather than automatically refilled.

## [1.1.2] - 2026-11-10

### Fixed
Expand Down Expand Up @@ -78,3 +93,4 @@
[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
[1.2.0]: https://github.com/thenolle/userscripts/releases/tag/better-chatgpt-v1.2.0
38 changes: 20 additions & 18 deletions ai/chatgpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ Updates arrive automatically. The script also checks on its own and offers to up

## Features

| Feature | What you get |
| ----------------- | ---------------------------------------------------------------------------------------------------- |
| Usage Status | Remaining reasoning, upload, image and research limits with reset times, your plan, low/empty alerts |
| Code Block Pro | Language badges, syntax colours, line numbers, wrap, fold, download, indentation-safe copy |
| Message Splitter | Paste any amount of text; split into parts or attach as a file only when needed |
| Prompt Library | Your prompts plus community prompts, with a form for placeholders |
| Batch Runner | Run one template over a list, with pause, resume and reload recovery |
| Selection Toolbar | Ask, explain, summarize, fact-check or quote highlighted text |
| Exporter | Markdown, text, Word, PDF and JSON |
| Draft Guard | Drafts survive reloads; size meter; warning before closing with unsent text |
| Command Palette | Search every action |
| Enter as Newline | Enter adds a line, a shortcut sends |
| Message Queue | Queue follow-ups while an answer generates; they send one by one |
| Recall | Search everything you sent and reuse it |
| Tutorial | Guided tours of every feature, started from the “?” button in the header |
| Max Width | Full-width conversations, optional sidebar removal |
| Update Checker | Checks on load and every few minutes, tells you once per version |
| Context Packs | Save sourced excerpts from conversations and assemble a previewable briefing for your next task |
| Feature | What you get |
| ----------------- | ------------------------------------------------------------------------------------------------------------------ |
| Usage Status | Remaining counts reported by ChatGPT, your plan, and low/empty alerts; totals and reset schedules are not inferred |
| Code Blocks V2 | Language badges, syntax colours, line numbers, wrap, fold, download, indentation-safe copy |
| Message Splitter | Paste any amount of text; split into parts or attach as a file only when needed |
| Prompt Library | Your prompts plus community prompts, with a form for placeholders |
| Batch Runner | Run one template over a list, with pause, resume and reload recovery |
| Selection Toolbar | Ask, explain, summarize, fact-check or quote highlighted text |
| Exporter | Markdown, text, Word, PDF and JSON |
| Draft Guard | Drafts survive reloads; size meter; warning before closing with unsent text |
| Command Palette | Search every action |
| Enter as Newline | Enter adds a line, a shortcut sends |
| Message Queue | Queue follow-ups while an answer generates; they send one by one |
| Recall | Search everything you sent and reuse it |
| Tutorial | Guided tours of every feature, started from the “?” button in the header |
| Max Width | Full-width conversations, optional sidebar removal |
| Update Checker | Checks on load and every few minutes, tells you once per version |
| Context Packs | Save sourced excerpts from conversations and assemble a previewable briefing for your next task |

## Shortcuts

Expand All @@ -44,6 +44,8 @@ Updates arrive automatically. The script also checks on its own and offers to up

All of them can be changed from the settings dialog.

Usage Status shows reported remaining counts only; it does not invent totals or reset schedules. The `/wham/usage` endpoint is not displayed as the ordinary chat quota.

## Privacy

No analytics and no server of its own. The script reads ChatGPT's own responses in your session (for limits and the model in use) and talks to `raw.githubusercontent.com` for update checks and community prompts. Drafts, prompts and settings stay in your userscript manager's storage.
Expand Down
35 changes: 35 additions & 0 deletions ai/chatgpt/docs/code-blocks-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Code Blocks V2
description: Faithful source selection, syntax colors and a compact code toolbar.
section: Guides
order: 48
---

# Code Blocks V2

Code Blocks V2 keeps a continuous source text flow with actual newline characters.

## Copying

Select code and use Ctrl+C or Cmd+C. Line breaks and selected indentation are preserved. Selecting from the middle of a line copies only the selected portion of that line.

Copy code copies the entire original block. Line numbers are not part of the source.

The feature does not alter ChatGPT's editable Run-code editors.

## Reading

- Wrap toggles visual wrapping without changing the source.
- Line numbers appear when wrapping is off.
- Fold is available for sufficiently long blocks, but code starts expanded.
- Download saves the original source text.

Syntax highlighting is retained only when its reconstructed text matches the source. Otherwise the block falls back to plain text rather than corrupting code.

## Guided tour

Open Help and select Code blocks. The tour highlights the block and its toolbar.

## Verification

Copy a selection containing blank lines, tabs and nested indentation into a plain-text editor. Verify the result before using copied code in a project.
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.2",
"version": "1.2.0",
"private": true,
"type": "module",
"license": "PolyForm-Strict-1.0.0",
Expand Down
158 changes: 86 additions & 72 deletions ai/chatgpt/src/features/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,40 @@ import { Tooltip, createButton, createDataRow, createDialog, createSection, ensu
import { Feature, createElement, injectStyle } from '@nolly/core'
import type { MenuEntry, ScriptContext } from '@nolly/core'
import { placeTool } from '../header-tools'
import { PILL_BUTTON_CLASS } from '../header-style'
import { session } from '../runtime'
import { storage } from '../storage'
import { PILL_BUTTON_CLASS } from '../header-style'

const PRIMARY_KEY = 'usage-status:primary'
const LAST_KEY = 'usage-status:last'
const LOW = 2

const LABELS: Readonly<Record<string, string>> = {
reason: 'Reasoning',
reason: 'Reasoning tool',
file_upload: 'File uploads',
paste_text_to_file: 'Pasted text as file',
paste_text_to_file: 'Paste-to-file',
image_gen: 'Image generation',
deep_research: 'Deep research'
}

const CSS = `
.bp-usage-pill[data-level='low'] { color: var(--bp-yellow); }
.bp-usage-pill[data-level='empty'] { color: var(--bp-red); }
`

const labelOf = (feature: string): string => LABELS[feature] ?? feature.replace(/_/g, ' ').replace(/^\w/, (letter) => letter.toUpperCase())

const formatReset = (iso: string | null): string => {
const ms = iso ? Date.parse(iso) - Date.now() : Number.NaN
if (!Number.isFinite(ms)) return 'no reset time'
if (ms <= 0) return 'resetting now'
const minutes = Math.round(ms / 60_000)
if (minutes < 60) return `resets in ${minutes}m`
const hours = Math.floor(minutes / 60)
if (hours < 24) return `resets in ${hours}h ${minutes % 60}m`
return `resets ${new Date(iso as string).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}`
}
const labelOf = (feature: string): string => LABELS[feature] ?? feature.replace(/_/g, ' ')

const level = (remaining: number): 'ok' | 'low' | 'empty' => (remaining === 0 ? 'empty' : remaining <= LOW ? 'low' : 'ok')
const resetText = (iso: string | null): string => {
const timestamp = iso ? Date.parse(iso) : Number.NaN
if (!Number.isFinite(timestamp)) return 'reset not reported'
if (timestamp <= Date.now()) return 'reported reset passed · awaiting updated count'
return `reset ${new Date(timestamp).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })}`
}

const titleCase = (value: string): string => value.charAt(0).toUpperCase() + value.slice(1)
const expired = (iso: string | null): boolean => {
const timestamp = iso ? Date.parse(iso) : Number.NaN
return Number.isFinite(timestamp) && timestamp <= Date.now()
}

export class UsageFeature extends Feature {
readonly id = 'usage-status'
readonly name = 'Usage Status'
readonly description = 'Shows your remaining limits (reasoning, uploads, images, research) and your plan.'
readonly description = 'Shows reported tool allowances without inventing a chat-message quota.'

private readonly pill = markUi(createElement('button', `${PILL_BUTTON_CLASS} bp-usage-pill bp-themed`))
private readonly label = createElement('span')
Expand All @@ -52,27 +44,37 @@ export class UsageFeature extends Feature {
constructor(context: ScriptContext) {
super(context)
ensureUiStyles()
injectStyle(`${uiConfig().id}-usage-styles`, CSS)
injectStyle(`${uiConfig().id}-usage-styles`, `.bp-usage-pill[data-level='low'] { color: var(--bp-yellow); }.bp-usage-pill[data-level='empty'] { color: var(--bp-red); }`)
this.pill.type = 'button'
this.pill.setAttribute('aria-label', 'Usage status')
this.pill.appendChild(this.label)
this.pill.addEventListener('click', () => this.open())
this.tooltip = new Tooltip(this.pill, (container) => container.append(this.rows()), { align: 'end' })
this.tooltip = new Tooltip(this.pill, (container) => container.appendChild(this.rows()), { align: 'end' })
}

private get primary(): string {
return storage.get(PRIMARY_KEY, 'reason')
}

override onEnable(): void {
this.scope.add(
session.subscribe((event) => {
if (event !== 'limits' && event !== 'usage' && event !== 'plan') return
if (event === 'limits') this.checkAlerts()
this.update()
this.context.refreshMenu()
})
)
this.scope.add(session.subscribe((event) => {
if (!['limits', 'usage', 'plan'].includes(event)) return
if (event === 'limits') this.checkAlerts()
this.update()
this.renderOpenDialog()
this.context.refreshMenu()
}))
this.scope.interval(() => {
this.update()
this.renderOpenDialog()
}, 30_000)
}

override onDisable(): void {
this.tooltip.hide()
this.pill.remove()
const dialog = document.getElementById(this.dialogId)
if (dialog instanceof HTMLDialogElement) dialog.close()
}

run(): void {
Expand All @@ -87,79 +89,91 @@ export class UsageFeature extends Feature {
override menuEntries(): MenuEntry[] {
return [
{ id: 'details', label: 'Show Usage Details', action: () => this.open() },
{ id: 'metric', label: `Badge Shows: ${labelOf(this.primary)} (click to change)`, action: () => this.cycle() }
{ id: 'metric', label: `Badge: ${labelOf(this.primary)} · change`, action: () => this.cycle() }
]
}

private get dialogId(): string {
return `${uiConfig().id}-usage-dialog`
}

private update(): void {
const entry = session.limit(this.primary)
this.label.textContent = entry ? `${labelOf(entry.feature)} ${entry.remaining}` : session.plan ? `${titleCase(session.plan)} plan` : 'Usage'
this.pill.dataset['level'] = entry ? level(entry.remaining) : 'ok'
const stale = entry ? expired(entry.resetAfter) : false
this.label.textContent = entry ? `${labelOf(entry.feature)} ${stale ? '—' : entry.remaining}` : 'Tool usage'
this.pill.dataset['level'] = !entry || stale ? 'ok' : entry.remaining <= 0 ? 'empty' : entry.remaining <= LOW ? 'low' : 'ok'
this.tooltip.refresh()
}

private cycle(): void {
const features = session.limits.map((limit) => limit.feature)
if (!features.length) return
storage.set(PRIMARY_KEY, features[(features.indexOf(this.primary) + 1) % features.length] ?? 'reason')
this.context.refreshMenu()
const next = features[(features.indexOf(this.primary) + 1) % features.length]!
storage.set(PRIMARY_KEY, next)
this.update()
this.context.refreshMenu()
}

private rows(): HTMLElement {
const list = createElement('div', 'bp-data-list')
const limits = session.limits
if (!limits.length) {
list.appendChild(createElement('div', 'bp-empty', 'No limit data yet. Send a message or reload the page.'))
if (!session.limits.length) {
list.appendChild(createElement('div', 'bp-empty', 'No tool allowances reported yet.'))
return list
}
for (const limit of limits) list.appendChild(createDataRow(labelOf(limit.feature), `${limit.remaining} left · ${formatReset(limit.resetAfter)}`, limit.remaining === 0 ? 'negative' : ''))
for (const limit of session.limits) {
const value = expired(limit.resetAfter) ? `Last reported: ${limit.remaining} · ${resetText(limit.resetAfter)}` : `${limit.remaining} remaining · ${resetText(limit.resetAfter)}`
list.appendChild(createDataRow(labelOf(limit.feature), value))
}
return list
}

private body(): HTMLElement[] {
const limits = createSection('Reported tool allowances')
limits.appendChild(this.rows())
const explanation = createElement('p', 'bp-hint', 'These are tool counters returned by ChatGPT, not a verified total chat-message allowance. Totals are not supplied. Counts refresh when ChatGPT returns new data; elapsed reset times do not imply a confirmed refill.')
const nodes = [limits, explanation]
if (session.maxFileMb !== null) {
const files = createSection('Reported attachment ceiling')
files.appendChild(createDataRow('General file ceiling', `${session.maxFileMb} MB`))
files.appendChild(createElement('p', 'bp-hint', 'File-type and account restrictions can be lower.'))
nodes.push(files)
}
if (session.usage) nodes.push(createElement('p', 'bp-hint', 'The separate /wham/usage window is excluded because it has not been established as the quota for this chat.'))
return nodes
}

private renderOpenDialog(): void {
const dialog = document.getElementById(this.dialogId)
if (!(dialog instanceof HTMLDialogElement) || !dialog.open) return
const body = dialog.querySelector<HTMLElement>('.bp-dialog-body')
if (!body) return
const top = body.scrollTop
body.replaceChildren(...this.body())
body.scrollTop = top
}

private open(): void {
const dialogId = `${uiConfig().id}-usage-dialog`
const existing = document.getElementById(dialogId)
const existing = document.getElementById(this.dialogId)
if (existing instanceof HTMLDialogElement) {
existing.close()
return
}
const ui = createDialog({ id: dialogId, title: 'Usage', description: session.plan ? `${titleCase(session.plan)} plan` : 'Plan not detected yet', width: 480 })
const limits = createSection('Limits')
limits.appendChild(this.rows())
const body = [limits]
const { usage } = session
if (usage?.usedPercent !== null && usage?.usedPercent !== undefined) {
const window = createSection('Rolling window')
const bar = createElement('div', 'bp-progress')
const fill = createElement('div', `bp-progress-fill ${usage.limitReached ? 'empty' : ''}`.trim())
fill.style.width = `${Math.min(100, usage.usedPercent)}%`
bar.appendChild(fill)
const reset = usage.resetAt ? new Date(usage.resetAt * 1000).toLocaleString() : 'unknown'
window.append(bar, createDataRow('Used', `${usage.usedPercent}%`), createDataRow('Resets', reset))
body.push(window)
}
if (session.maxFileMb !== null) {
const files = createSection('Files')
files.appendChild(createDataRow('Largest file', `${session.maxFileMb} MB`))
body.push(files)
}
ui.body.replaceChildren(...body)
const ui = createDialog({ id: this.dialogId, title: 'Usage', description: session.plan ? `Reported plan: ${session.plan}` : 'Plan not reported', width: 600 })
ui.body.append(...this.body())
ui.footer.append(createButton('Close', { primary: true, onClick: ui.close }))
ui.show()
}

private checkAlerts(): void {
const last = storage.get<Record<string, number>>(LAST_KEY, {})
const next = { ...last }
for (const { feature, remaining, resetAfter } of session.limits) {
const before = last[feature]
next[feature] = remaining
for (const entry of session.limits) {
if (expired(entry.resetAfter)) continue
const before = last[entry.feature]
next[entry.feature] = entry.remaining
if (before === undefined) continue
const name = labelOf(feature)
if (before > 0 && remaining === 0) showToast(`${name}: none left, ${formatReset(resetAfter)}.`, [], 10_000)
else if (before === 0 && remaining > 0) showToast(`${name} is available again (${remaining} left).`, [], 8_000)
else if (before > LOW && remaining > 0 && remaining <= LOW) showToast(`${name}: only ${remaining} left, ${formatReset(resetAfter)}.`, [], 8_000)
if (before > 0 && entry.remaining === 0) showToast(`${labelOf(entry.feature)}: none remaining · ${resetText(entry.resetAfter)}`)
else if (before === 0 && entry.remaining > 0) showToast(`${labelOf(entry.feature)}: ${entry.remaining} now reported available.`)
}
storage.set(LAST_KEY, next)
}
Expand Down
Loading
Loading