diff --git a/ai/chatgpt/CHANGELOG.md b/ai/chatgpt/CHANGELOG.md index 94cb540..8483357 100644 --- a/ai/chatgpt/CHANGELOG.md +++ b/ai/chatgpt/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [1.1.0] - 2026-11-10 + +### Added + +- **Tutorial:** guided tours for every feature, started from the “?” button in the header. + +### Fixed + +- **Header buttons:** the settings, usage, download and help buttons now sit after ChatGPT's own buttons in the same row, with the same size and hover as the native ones. +- **Export:** finds the messages in the current ChatGPT layout and converts the new answer format (lists, tables, source chips, bold text) to Markdown. + ## [1.0.0] - 2026-11-10 - Exporter built from the conversation view (Markdown, text, Word, PDF, JSON) and update checker. diff --git a/ai/chatgpt/docs/getting-started.md b/ai/chatgpt/docs/getting-started.md index 09941c6..90393da 100644 --- a/ai/chatgpt/docs/getting-started.md +++ b/ai/chatgpt/docs/getting-started.md @@ -12,6 +12,7 @@ Install a userscript manager, then the script, and open chatgpt.com. After the p - **Settings** (sliders icon) in the header: turn modules on or off and open each module's own settings. - **Usage** pill: your remaining reasoning messages. Hover for every limit, click for details. - **Download** icon inside a conversation: exports it. +- A **?** button opens guided tours for each feature. - Extra buttons next to the message box for big messages, prompts, batches, queue and recall. Press Alt + Shift + P at any time to search every action. diff --git a/ai/chatgpt/package.json b/ai/chatgpt/package.json index 8c7de1f..32bdde6 100644 --- a/ai/chatgpt/package.json +++ b/ai/chatgpt/package.json @@ -1,6 +1,6 @@ { "name": "@nolly/ai-chatgpt", - "version": "1.0.0", + "version": "1.1.0", "private": true, "type": "module", "license": "PolyForm-Strict-1.0.0", diff --git a/ai/chatgpt/src/header-tools.ts b/ai/chatgpt/src/header-tools.ts index 94f52ef..51c99da 100644 --- a/ai/chatgpt/src/header-tools.ts +++ b/ai/chatgpt/src/header-tools.ts @@ -1,6 +1,6 @@ import { findHeaderSlot } from './locate' -const ORDER = ['settings', 'usage', 'export'] as const +const ORDER = ['settings', 'usage', 'export', 'help'] as const export type ToolId = (typeof ORDER)[number] @@ -13,11 +13,13 @@ export const placeTool = (button: HTMLElement, id: ToolId): boolean => { const row = toolRow() if (!row) return false button.dataset['bcTool'] = id - if (button.parentElement !== row) row.prepend(button) + if (button.parentElement !== row) row.append(button) const ours = ORDER.flatMap((name) => row.querySelector(`:scope > [data-bc-tool="${name}"]`) ?? []) - ours.forEach((element, index) => { - const expected = row.children[index] ?? null - if (expected !== element) row.insertBefore(element, expected) - }) + let cursor: Element | null = [...row.children].filter((child) => !child.hasAttribute('data-bc-tool')).at(-1) ?? null + for (const element of ours) { + const wanted: Element | null = cursor ? cursor.nextElementSibling : row.firstElementChild + if (wanted !== element) row.insertBefore(element, wanted) + cursor = element + } return true } diff --git a/ai/chatgpt/src/main.ts b/ai/chatgpt/src/main.ts index db6a199..b308699 100644 --- a/ai/chatgpt/src/main.ts +++ b/ai/chatgpt/src/main.ts @@ -11,6 +11,7 @@ import { PromptQueueFeature, RecallFeature, SelectionToolbarFeature, + TutorialFeature, UpdatesFeature, configurePlatform, configureUi, @@ -32,6 +33,7 @@ import { SLUG, URLS } from './repo' import { session } from './runtime' import { storage } from './storage' import { threadOf } from './threads' +import { tutorialSource } from './tutorial-source' import { installTheme } from './theme' const onSend = (listener: () => void): (() => void) => @@ -60,6 +62,7 @@ whenReady(() => { promptsUrl: URLS.prompts, exporter: exportSource, release: { name: 'Better ChatGPT', slug: SLUG, version: __VERSION__, metaUrl: URLS.meta, installUrl: URLS.install, releasesUrl: URLS.releases }, + tutorial: tutorialSource, codeBlockRoot: (pre) => pre.closest('[data-chatgpt-copy-code]') ?? pre.closest('[data-code-block]') }) @@ -98,6 +101,7 @@ whenReady(() => { .register((context) => new ExporterFeature(context)) .register((context) => new UpdatesFeature(context)) .register((context) => new UsageFeature(context)) + .register((context) => new TutorialFeature(context)) .register((context) => new DiagnosticsFeature(context)) .start() }) diff --git a/ai/chatgpt/src/selectors.ts b/ai/chatgpt/src/selectors.ts index 85e4b36..9060fb6 100644 --- a/ai/chatgpt/src/selectors.ts +++ b/ai/chatgpt/src/selectors.ts @@ -1,11 +1,11 @@ export const SELECTORS = { - composerForm: 'form:has(fieldset)', - editable: '[contenteditable="true"], textarea', - codeSurface: '[data-code-block], .cm-editor', - attach: '[data-composer-navigation-target="add-context"]', - modeToggle: 'button[aria-pressed]', - headerSlot: '[data-app-shell-header-obstacle="true"]', - sidebar: 'aside' + composerForm: 'form:has(fieldset)', + editable: '[contenteditable="true"], textarea', + codeSurface: '[data-code-block], .cm-editor', + attach: '[data-composer-navigation-target="add-context"]', + modeToggle: 'button[aria-pressed]', + headerSlot: '[data-app-shell-main-titlebar="true"] [data-app-shell-header-obstacle="true"]', + sidebar: 'aside' } as const export const STOP_LABEL = /\b(stop|arr[eê]t\w*|stopp\w*|detener|parar)\b/i diff --git a/ai/chatgpt/src/tours.ts b/ai/chatgpt/src/tours.ts new file mode 100644 index 0000000..03385f7 --- /dev/null +++ b/ai/chatgpt/src/tours.ts @@ -0,0 +1,128 @@ +import { loadPromptShortcut, loadShortcut, tour } from '@nolly/ai' +import type { Tour } from '@nolly/ai' +import { composerKit } from './kit' + +const { click, closed, escape, find, info, inside, point, press, wait } = tour + +const dialog = (name: string): string => `better-chatgpt-${name}` +const tool = (name: string) => find(`[data-bc-tool="${name}"]`) + +const gettingStarted: Tour = { + id: 'start', + title: 'Getting started', + summary: 'The header buttons and where everything lives.', + steps: [ + info('Welcome to Better ChatGPT', 'This tour shows where everything is. You can exit any time and restart it from the “?” button in the header.'), + point('Settings', 'Turn modules on or off and open each module’s own settings.', tool('settings')), + point('Usage', 'Shows what you have left of the limit you chose. Hover for every limit and when it resets, click for details.', tool('usage')), + point('Export', 'Appears inside a conversation. Exports it as Markdown, Word, PDF, plain text or JSON.', tool('export')), + point('Message box buttons', 'These buttons sit next to the message box. This one configures how Enter works: Enter adds a new line and a shortcut sends.', find('.bp-config-button')), + point('Big messages', 'Paste very long text here. It is only split when it is too big for one message.', find('.bp-cb-big')), + point('Prompt library', 'Insert saved and community prompts. The shortcut works from anywhere.', find('.bp-cb-prompts')), + point('Batch runner', 'Send the same kind of message for a whole list of items.', find('.bp-cb-batch')), + press('Command palette', 'Every action in Better ChatGPT is searchable. Try opening it now.', () => loadShortcut()), + press('Close it again', 'Press Escape to close the palette.', escape), + info('That’s it', 'Open “?” any time to run a focused tour on one feature.') + ] +} + +const usage: Tour = { + id: 'usage', + title: 'Usage and limits', + summary: 'What you have left, and when it comes back.', + steps: [ + point('The usage pill', 'It shows the limit you picked. It turns yellow when only a couple are left and red at zero.', tool('usage')), + click('Open the details', 'Click it to see every limit with its reset time, your plan and the rolling window.', tool('usage')), + wait('Close the dialog', 'Use Close when you are done.', closed(dialog('usage-dialog'))), + info('Choose what it shows', 'Open Settings, then Usage Status, then “Badge Shows” to switch the pill to another limit.') + ] +} + +const longMessages: Tour = { + id: 'long', + title: 'Writing long messages', + summary: 'The size meter, big-message box and automatic splitting.', + steps: [ + point('The message box', 'While you type, a small chip above it shows characters and estimated tokens against the limit.', () => composerKit.findComposer()), + point('Size meter', 'It turns yellow near the limit and red above it, with a Split button. It only appears once there is text in the box.', find('.bp-draft-meter')), + click('Open the big message box', 'Click to open it. You can paste any amount of text.', find('.bp-cb-big')), + point('Paste here', 'Paste or write the message. The line under it says whether it fits in one message.', inside(dialog('bigtext-dialog'), 'textarea')), + point('Too big?', 'If it is too big, you get a preview of the parts and a choice: send them in order, or attach as a file.', inside(dialog('bigtext-dialog'), '.bp-split-summary')), + wait('Close the box', 'Use Cancel when you are done.', closed(dialog('bigtext-dialog'))) + ] +} + +const prompts: Tour = { + id: 'prompts', + title: 'Prompts and placeholders', + summary: 'Saved prompts, community prompts and the fill-in form.', + steps: [ + click('Open the prompt library', 'Click the book button, or use the shortcut.', find('.bp-cb-prompts')), + point('Search', 'Type to search your prompts and community prompts from GitHub. Enter inserts the highlighted one.', inside(dialog('prompt-picker'), '.bp-palette-input')), + point('Community prompts', 'Prompts marked “Community” come from the shared library. Press Save to copy one into your own list.', inside(dialog('prompt-picker'), '.bp-palette-list')), + info('Placeholders', 'Prompts can contain blanks like {{topic}} or {{item}}. When you insert one, a form asks what to put in each blank.'), + press('Close the picker', 'Press Escape to close it.', escape), + press('The shortcut', 'You can also open the library without the mouse.', () => loadPromptShortcut()), + press('Close again', 'Press Escape.', escape) + ] +} + +const batch: Tour = { + id: 'batch', + title: 'Batch Runner', + summary: 'Send one message per list item, automatically.', + steps: [ + info('What it does', 'Imagine researching ten companies. Instead of ten copy-pastes, you write the message once and paste the list.'), + click('Open the Batch Runner', 'Click the layers button.', find('.bp-cb-batch')), + point('Step 1: the message', 'Write it once and put {{item}} where each list entry goes. The example buttons fill everything in for you.', inside(dialog('batch-dialog'), '[data-tour="batch-template"]')), + point('Step 2: the list', 'One entry per line. Each line becomes one message.', inside(dialog('batch-dialog'), '[data-tour="batch-items"]')), + point('Step 3: review', 'The first messages are previewed before anything is sent, so you confirm before starting.', inside(dialog('batch-dialog'), '[data-tour="batch-review"]')), + info('While it runs', 'A card appears in the corner with Pause and Cancel. If you reload the page, it offers to resume.'), + wait('Close the dialog', 'Use Cancel to leave without starting.', closed(dialog('batch-dialog'))) + ] +} + +const codeBlocks: Tour = { + id: 'code', + title: 'Code blocks', + summary: 'Language badges, folding, wrapping and copying.', + steps: [ + point('Enhanced code', 'When an answer finishes, its code blocks are replaced with these. Ask for some code if you do not see one.', find('.bp-code')), + point('Toolbar', 'Wrap long lines, toggle line numbers, fold long code, copy, or download as a file.', find('.bp-code-actions')), + info('Selecting and copying', 'You can select part of a block and copy it. Indentation and line breaks are kept exactly.') + ] +} + +const exporting: Tour = { + id: 'export', + title: 'Exporting a conversation', + summary: 'Markdown, Word, PDF, plain text and JSON.', + steps: [ + click('Open the exporter', 'Click the download button inside a conversation.', tool('export')), + point('Pick a format', 'Markdown, plain text, Word and PDF are generated right here. JSON lists each message with its role.', inside(dialog('export-dialog'), '.bp-stack')), + wait('Close the dialog', 'Use Close when you are done.', closed(dialog('export-dialog'))) + ] +} + +const selection: Tour = { + id: 'selection', + title: 'Selection toolbar', + summary: 'Ask about any text you highlight.', + steps: [ + wait('Select some text', 'Highlight a sentence in any answer.', () => document.querySelector('.bp-sel[data-visible="true"]') !== null, 'Select a few words in an answer.'), + point('Quick actions', 'Ask, Explain, Summarize, Fact-check or Quote. Hold Shift while clicking to send immediately.', find('.bp-sel[data-visible="true"]')) + ] +} + +const palette: Tour = { + id: 'palette', + title: 'Command palette', + summary: 'Search and run any action from the keyboard.', + steps: [ + press('Open it', 'Use your command palette shortcut.', () => loadShortcut()), + point('Type to search', 'Try “export”, “usage” or “split”. Arrow keys move, Enter runs.', inside(dialog('palette'), '.bp-palette-input')), + press('Close it', 'Press Escape.', escape) + ] +} + +export const TOURS: readonly Tour[] = [gettingStarted, usage, longMessages, prompts, batch, codeBlocks, exporting, selection, palette] diff --git a/ai/chatgpt/src/tutorial-source.ts b/ai/chatgpt/src/tutorial-source.ts new file mode 100644 index 0000000..e13c85e --- /dev/null +++ b/ai/chatgpt/src/tutorial-source.ts @@ -0,0 +1,12 @@ +import type { TutorialSource } from '@nolly/ai' +import { ICON_BUTTON_CLASS } from './header-style' +import { placeTool } from './header-tools' +import { TOURS } from './tours' + +export const tutorialSource: TutorialSource = { + tours: TOURS, + place: (button) => { + if (button.className !== ICON_BUTTON_CLASS) button.className = ICON_BUTTON_CLASS + return placeTool(button, 'help') + } +} diff --git a/ai/perplexity/CHANGELOG.md b/ai/perplexity/CHANGELOG.md index f284f18..991fbc9 100644 --- a/ai/perplexity/CHANGELOG.md +++ b/ai/perplexity/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to Better Perplexity are documented here. The format follows - Internal: Code Block Pro now comes from the shared package. - Internal: Batch Runner, Selection Toolbar and Max Width now come from the shared package. - Internal: Exporter and Update checker now come from the shared package. +- Internal: Tutorial engine and styles now come from the shared package. - Internal: one shared settings dialog; Batch Runner uses the shared prompt sender. - Fixed: the batch runner was registered twice. diff --git a/ai/perplexity/src/main.ts b/ai/perplexity/src/main.ts index d0aa46f..420d2b6 100644 --- a/ai/perplexity/src/main.ts +++ b/ai/perplexity/src/main.ts @@ -1,4 +1,4 @@ -import { BatchRunnerFeature, CodeBlocksFeature, CommandPaletteFeature, DraftGuardFeature, EnterAsNewlineFeature, ExporterFeature, MaxWidthFeature, MessageSplitterFeature, PromptLibraryFeature, PromptQueueFeature, RecallFeature, SelectionToolbarFeature, UpdatesFeature, configurePlatform, configureUi, loadSplitterSettings } from '@nolly/ai' +import { BatchRunnerFeature, CodeBlocksFeature, CommandPaletteFeature, DraftGuardFeature, EnterAsNewlineFeature, ExporterFeature, MaxWidthFeature, MessageSplitterFeature, PromptLibraryFeature, PromptQueueFeature, RecallFeature, SelectionToolbarFeature, TutorialFeature, UpdatesFeature, configurePlatform, configureUi, loadSplitterSettings } from '@nolly/ai' import { App } from './core/app' import { composerKit, findComposer, writeComposer } from './core/composer' import { sendPrompt } from './core/dispatch' @@ -13,7 +13,7 @@ import { exportSource } from './export-source' import { findComposerActions } from './locate' import { GlobalSettingsModule } from './modules/global-settings' import { ALWAYS_HIDDEN, LAYOUT_RULES, RIGHT_SIDEBAR } from './modules/max-width/rules' -import { TutorialModule } from './modules/tutorial' +import { tutorialSource } from './tutorial-source' import { UsageStatusModule } from './modules/usage-status' import { URLS } from './repo' @@ -31,7 +31,8 @@ configurePlatform({ threadOf, promptsUrl: URLS.prompts, exporter: exportSource, - release: { name: 'Better Perplexity', slug: 'better-perplexity', version: __VERSION__, metaUrl: URLS.meta, installUrl: URLS.install, releasesUrl: URLS.releases } + release: { name: 'Better Perplexity', slug: 'better-perplexity', version: __VERSION__, metaUrl: URLS.meta, installUrl: URLS.install, releasesUrl: URLS.releases }, + tutorial: tutorialSource }) fetchSpy.install() @@ -48,7 +49,7 @@ new App() .register((context) => new ExporterFeature(context)) .register((context) => new UsageStatusModule(context)) .register((context) => new GlobalSettingsModule(context)) - .register((context) => new TutorialModule(context)) + .register((context) => new TutorialFeature(context)) .register((context) => new UpdatesFeature(context)) .register((context) => new PromptQueueFeature(context)) .register((context) => new RecallFeature(context)) diff --git a/ai/perplexity/src/modules/tutorial/tours.ts b/ai/perplexity/src/tours.ts similarity index 84% rename from ai/perplexity/src/modules/tutorial/tours.ts rename to ai/perplexity/src/tours.ts index a885f5b..556bc83 100644 --- a/ai/perplexity/src/modules/tutorial/tours.ts +++ b/ai/perplexity/src/tours.ts @@ -1,22 +1,7 @@ -import { findComposer } from '../../core/composer' -import { loadPromptShortcut, loadShortcut, type Shortcut } from '@nolly/ai' -import type { Step } from './engine' +import { findComposer } from './core/composer' +import { loadPromptShortcut, loadShortcut, tour, type Tour } from '@nolly/ai' -export interface Tour { - id: string - title: string - summary: string - steps: readonly Step[] -} - -const find = (selector: string) => (): HTMLElement | null => document.querySelector(selector) -const info = (title: string, body: string): Step => ({ title, body }) -const point = (title: string, body: string, target: () => HTMLElement | null): Step => ({ title, body, target }) -const click = (title: string, body: string, target: () => HTMLElement | null): Step => ({ title, body, target, kind: 'click' }) -const press = (title: string, body: string, shortcut: () => Shortcut): Step => ({ title, body, kind: 'key', shortcut }) -const wait = (title: string, body: string, until: () => boolean, hint?: string): Step => ({ title, body, kind: 'wait', until, hint }) -const escape: () => Shortcut = () => ({ ctrl: false, alt: false, shift: false, meta: false, code: 'Escape' }) -const closed = (id: string) => (): boolean => !document.getElementById(id) +const { click, closed, escape, find, info, inside, point, press, wait } = tour const DIALOG = { big: 'better-perplexity-bigtext-dialog', @@ -26,7 +11,6 @@ const DIALOG = { palette: 'better-perplexity-palette' } as const -const inside = (id: string, selector: string) => find(`#${id} ${selector}`) const gettingStarted: Tour = { id: 'start', @@ -136,10 +120,3 @@ const palette: Tour = { } export const TOURS: readonly Tour[] = [gettingStarted, longMessages, prompts, batch, codeBlocks, exporting, selection, palette] - -export const FULL_TOUR: Tour = { - id: 'all', - title: 'Full tour', - summary: 'Everything above, in order.', - steps: TOURS.flatMap((tour) => tour.steps) -} \ No newline at end of file diff --git a/ai/perplexity/src/tutorial-source.ts b/ai/perplexity/src/tutorial-source.ts new file mode 100644 index 0000000..9c000f9 --- /dev/null +++ b/ai/perplexity/src/tutorial-source.ts @@ -0,0 +1,13 @@ +import type { TutorialSource } from '@nolly/ai' +import { TOURS } from './tours' + +export const tutorialSource: TutorialSource = { + tours: TOURS, + place: (button) => { + const indicator = document.querySelector('.bp-usage-indicator') + if (!indicator) return false + const anchor = indicator.querySelector('.bp-export') ?? indicator.querySelector('.bp-gear') + if (button.parentElement !== indicator || (anchor && button.nextElementSibling !== anchor)) indicator.insertBefore(button, anchor) + return true + } +} diff --git a/bun.lock b/bun.lock index 99cc605..c81e648 100644 --- a/bun.lock +++ b/bun.lock @@ -7,7 +7,7 @@ }, "ai/chatgpt": { "name": "@nolly/ai-chatgpt", - "version": "0.1.0", + "version": "1.1.0", "dependencies": { "@nolly/ai": "workspace:*", "@nolly/core": "workspace:*", diff --git a/core/ai/src/features/index.ts b/core/ai/src/features/index.ts index f4d31d9..1d1da9e 100644 --- a/core/ai/src/features/index.ts +++ b/core/ai/src/features/index.ts @@ -19,3 +19,7 @@ export { CodeBlocksFeature } from './code-blocks' export { ExporterFeature } from './exporter' export { UpdatesFeature } from './updates' export type { ExportSource } from './exporter/source' +export { TutorialFeature } from './tutorial' +export type { Step } from './tutorial/engine' +export type { Tour, TutorialSource } from './tutorial/source' +export * as tour from './tutorial/steps' diff --git a/ai/perplexity/src/modules/tutorial/engine.ts b/core/ai/src/features/tutorial/engine.ts similarity index 95% rename from ai/perplexity/src/modules/tutorial/engine.ts rename to core/ai/src/features/tutorial/engine.ts index d50576a..abec669 100644 --- a/ai/perplexity/src/modules/tutorial/engine.ts +++ b/core/ai/src/features/tutorial/engine.ts @@ -1,6 +1,9 @@ import { createElement } from '@nolly/core' -import { markUi } from '../../core/dom' -import { createButton, ensureUiStyles, formatShortcut, matchesShortcut, type Shortcut } from '@nolly/ai' +import { markUi } from '../../ui/config' +import { createButton } from '../../ui/controls' +import { ensureUiStyles } from '../../ui/styles' +import { formatShortcut, matchesShortcut } from '../command-palette/shortcut' +import type { Shortcut } from '../command-palette/shortcut' import { ensureTourStyles } from './styles' export interface Step { diff --git a/ai/perplexity/src/modules/tutorial/index.ts b/core/ai/src/features/tutorial/index.ts similarity index 51% rename from ai/perplexity/src/modules/tutorial/index.ts rename to core/ai/src/features/tutorial/index.ts index d9ad0e8..1174b2c 100644 --- a/ai/perplexity/src/modules/tutorial/index.ts +++ b/core/ai/src/features/tutorial/index.ts @@ -1,21 +1,28 @@ -import { createElement, Feature, type MenuEntry, type ScriptContext } from '@nolly/core' -import { markUi } from '../../core/dom' -import { storage } from '../../core/storage' -import { createButton, createDialog, createIcon, ensureUiStyles, showToast, Tooltip } from '@nolly/ai' +import { Feature, createElement } from '@nolly/core' +import type { MenuEntry, ScriptContext } from '@nolly/core' +import { platform, storage } from '../../platform' +import { markUi, uiConfig } from '../../ui/config' +import { createButton } from '../../ui/controls' +import { createDialog } from '../../ui/dialog' +import { createIcon } from '../../ui/icons' +import { ensureUiStyles } from '../../ui/styles' +import { showToast } from '../../ui/toast' +import { Tooltip } from '../../ui/tooltip' import { TourRunner } from './engine' -import { FULL_TOUR, TOURS, type Tour } from './tours' +import type { Tour } from './source' const SEEN_KEY = 'tutorial:seen' -const CHOOSER_ID = 'better-perplexity-tour-chooser' const FIRST_RUN_DELAY = 5_000 -export class TutorialModule extends Feature { +const fullTour = (): Tour => ({ id: 'all', title: 'Full tour', summary: 'Everything above, in order.', steps: platform().tutorial.tours.flatMap((tour) => tour.steps) }) + +export class TutorialFeature extends Feature { readonly id = 'tutorial' readonly name = 'Tutorial' readonly description = 'Interactive guided tours of every feature.' private readonly runner = new TourRunner() - private readonly button = markUi(createElement('button', 'bp-header-btn bp-help')) + private readonly button = markUi(createElement('button', 'bp-header-btn bp-help bp-themed')) private readonly tooltip: Tooltip private offered = false @@ -23,38 +30,45 @@ export class TutorialModule extends Feature { super(context) ensureUiStyles() this.button.type = 'button' - this.button.setAttribute('aria-label', 'How to use Better Perplexity') + this.button.setAttribute('aria-label', `How to use ${uiConfig().title}`) this.button.appendChild(createIcon('help')) this.button.addEventListener('click', () => this.choose()) this.tooltip = new Tooltip(this.button, (container) => container.append(createElement('div', 'bp-tip-mode', 'How to use'), createElement('div', 'bp-tip-sub', 'Interactive guided tours'))) } run(): void { - const indicator = document.querySelector('.bp-usage-indicator') - if (!this.enabled || !indicator) { + if (!this.enabled || !platform().tutorial.place(this.button)) { this.tooltip.hide() this.button.remove() return } - const anchor = indicator.querySelector('.bp-export') ?? indicator.querySelector('.bp-gear') - if (this.button.parentElement !== indicator || (anchor && this.button.nextElementSibling !== anchor)) indicator.insertBefore(this.button, anchor) this.offerFirstRun() } override menuEntries(): MenuEntry[] { return [ { id: 'open', label: 'How to Use (Tutorial)…', action: () => this.choose() }, - { id: 'full', label: 'Run the Full Tour', action: () => this.start(FULL_TOUR) } + { id: 'full', label: 'Run the Full Tour', action: () => this.start(fullTour()) } ] } private offerFirstRun(): void { if (this.offered || storage.get(SEEN_KEY, false)) return this.offered = true - window.setTimeout(() => showToast('New here? Take a one-minute tour of Better Perplexity.', [ - { label: 'Start tour', primary: true, onClick: () => this.start(TOURS[0]!) }, - { label: 'No thanks', onClick: () => storage.set(SEEN_KEY, true) } - ], 0), FIRST_RUN_DELAY) + const first = platform().tutorial.tours[0] + if (!first) return + window.setTimeout( + () => + showToast( + `New here? Take a one-minute tour of ${uiConfig().title}.`, + [ + { label: 'Start tour', primary: true, onClick: () => this.start(first) }, + { label: 'No thanks', onClick: () => storage.set(SEEN_KEY, true) } + ], + 0 + ), + FIRST_RUN_DELAY + ) } private start(tour: Tour): void { @@ -63,24 +77,28 @@ export class TutorialModule extends Feature { } private choose(): void { - const existing = document.getElementById(CHOOSER_ID) + const dialogId = `${uiConfig().id}-tour-chooser` + const existing = document.getElementById(dialogId) if (existing instanceof HTMLDialogElement) { existing.close() return } - const ui = createDialog({ id: CHOOSER_ID, title: 'How to use', description: 'Pick a guided tour. Each one highlights real buttons and asks you to try them.', width: 560 }) + const ui = createDialog({ id: dialogId, title: 'How to use', description: 'Pick a guided tour. Each one highlights real buttons and asks you to try them.', width: 560 }) const stack = createElement('div', 'bp-stack') - for (const tour of TOURS) { + for (const tour of platform().tutorial.tours) { const row = createElement('div', 'bp-prompt-row') const text = createElement('div') text.append(createElement('div', undefined, tour.title), createElement('div', 'bp-data-label', `${tour.summary} · ${tour.steps.length} steps`)) - row.append(text, createButton('Start', { - primary: true, - onClick: () => { - ui.close() - window.setTimeout(() => this.start(tour), 0) - } - })) + row.append( + text, + createButton('Start', { + primary: true, + onClick: () => { + ui.close() + window.setTimeout(() => this.start(tour), 0) + } + }) + ) stack.appendChild(row) } ui.body.appendChild(stack) @@ -90,10 +108,10 @@ export class TutorialModule extends Feature { primary: true, onClick: () => { ui.close() - window.setTimeout(() => this.start(FULL_TOUR), 0) + window.setTimeout(() => this.start(fullTour()), 0) } }) ) ui.show() } -} \ No newline at end of file +} diff --git a/core/ai/src/features/tutorial/source.ts b/core/ai/src/features/tutorial/source.ts new file mode 100644 index 0000000..1ff97ec --- /dev/null +++ b/core/ai/src/features/tutorial/source.ts @@ -0,0 +1,13 @@ +import type { Step } from './engine' + +export interface Tour { + id: string + title: string + summary: string + steps: readonly Step[] +} + +export interface TutorialSource { + readonly tours: readonly Tour[] + readonly place: (button: HTMLElement) => boolean +} diff --git a/core/ai/src/features/tutorial/steps.ts b/core/ai/src/features/tutorial/steps.ts new file mode 100644 index 0000000..da4e739 --- /dev/null +++ b/core/ai/src/features/tutorial/steps.ts @@ -0,0 +1,12 @@ +import type { Shortcut } from '../command-palette/shortcut' +import type { Step } from './engine' + +export const find = (selector: string) => (): HTMLElement | null => document.querySelector(selector) +export const inside = (id: string, selector: string) => find(`#${id} ${selector}`) +export const info = (title: string, body: string): Step => ({ title, body }) +export const point = (title: string, body: string, target: () => HTMLElement | null): Step => ({ title, body, target }) +export const click = (title: string, body: string, target: () => HTMLElement | null): Step => ({ title, body, target, kind: 'click' }) +export const press = (title: string, body: string, shortcut: () => Shortcut): Step => ({ title, body, kind: 'key', shortcut }) +export const wait = (title: string, body: string, until: () => boolean, hint?: string): Step => ({ title, body, kind: 'wait', until, hint }) +export const escape: () => Shortcut = () => ({ ctrl: false, alt: false, shift: false, meta: false, code: 'Escape' }) +export const closed = (id: string) => (): boolean => !document.getElementById(id) diff --git a/ai/perplexity/src/modules/tutorial/styles.ts b/core/ai/src/features/tutorial/styles.ts similarity index 90% rename from ai/perplexity/src/modules/tutorial/styles.ts rename to core/ai/src/features/tutorial/styles.ts index a98abfd..a4c242f 100644 --- a/ai/perplexity/src/modules/tutorial/styles.ts +++ b/core/ai/src/features/tutorial/styles.ts @@ -1,4 +1,5 @@ import { injectStyle } from '@nolly/core' +import { uiConfig } from '../../ui/config' const CSS = ` .bp-tour { position: fixed; inset: 0; z-index: 2147483647; pointer-events: none; } @@ -13,4 +14,4 @@ const CSS = ` @media (prefers-reduced-motion: reduce) { .bp-tour-hole, .bp-tour-hole[data-pulse='true'] { transition: none; animation: none; } } ` -export const ensureTourStyles = (): void => injectStyle('better-perplexity-tour-styles', CSS) \ No newline at end of file +export const ensureTourStyles = (): void => injectStyle(`${uiConfig().id}-tour-styles`, CSS) \ No newline at end of file diff --git a/core/ai/src/platform.ts b/core/ai/src/platform.ts index 46db337..1cce329 100644 --- a/core/ai/src/platform.ts +++ b/core/ai/src/platform.ts @@ -3,6 +3,7 @@ import type { ComposerKit } from './composer' import type { GenerationKit } from './generation' import type { PromptSender } from './prompt' import type { ExportSource } from './features/exporter/source' +import type { TutorialSource } from './features/tutorial/source' export interface ReleaseInfo { readonly name: string @@ -19,12 +20,13 @@ export interface Platform { readonly logger: Logger readonly composer: ComposerKit readonly generation: GenerationKit - readonly sendPrompt: PromptSender - readonly onSend: (listener: () => void) => () => void - readonly threadOf: (pathname: string) => string | null readonly promptsUrl: string readonly exporter: ExportSource readonly release: ReleaseInfo + readonly tutorial: TutorialSource + readonly sendPrompt: PromptSender + readonly onSend: (listener: () => void) => () => void + readonly threadOf: (pathname: string) => string | null readonly codeBlockRoot?: (pre: HTMLElement) => HTMLElement | null }