Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add floating toolbar display mode option #747

Merged
merged 1 commit into from
Jul 9, 2024
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
7 changes: 7 additions & 0 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const TriggerMode = {
manually: 'Manually',
}

export const DisplayMode = {
sidebar: 'Display in sidebar',
floatingToolbar: 'Display in floating toolbar',
}

export const ThemeMode = {
light: 'Light',
dark: 'Dark',
Expand Down Expand Up @@ -202,6 +207,8 @@ export const defaultConfig = {

/** @type {keyof TriggerMode}*/
triggerMode: 'manually',
/** @type {keyof DisplayMode}*/
displayMode: 'sidebar',
/** @type {keyof ThemeMode}*/
themeMode: 'auto',
/** @type {keyof Models}*/
Expand Down
24 changes: 23 additions & 1 deletion src/content-script/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,33 @@ async function mountComponent(siteConfig, userConfig) {
unmountComponentAtNode(e)
e.remove()
})

const position = {
x: window.innerWidth - 300 - (Math.floor((20 / 100) * window.innerWidth)),
y: window.innerHeight / 2 - 200,
}
const toolbarContainer = createElementAtPosition(position.x, position.y)
toolbarContainer.className = 'chatgptbox-toolbar-container-not-queryable'
if (userConfig.displayMode === 'floatingToolbar') {
render(
<FloatingToolbar
session={initSession({ modelName: userConfig.modelName })}
selection={question}
container={toolbarContainer}
dockable={true}
triggered={true}
closeable={true}
prompt={question}
/>,
toolbarContainer,
)
return
}
const container = document.createElement('div')
container.id = 'chatgptbox-container'
render(
<DecisionCard
session={initSession({ modelName: (await getUserConfig()).modelName })}
session={initSession({ modelName: userConfig.modelName })}
question={question}
siteConfig={siteConfig}
container={container}
Expand Down
19 changes: 19 additions & 0 deletions src/popup/sections/GeneralPart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Models,
ThemeMode,
TriggerMode,
DisplayMode,
isUsingMoonshotApi,
} from '../../config/index.mjs'
import Browser from 'webextension-polyfill'
Expand Down Expand Up @@ -118,6 +119,24 @@ export function GeneralPart({ config, updateConfig }) {
})}
</select>
</label>
<label>
<legend>{t('DisplayMode')}</legend>
<select
required
onChange={(e) => {
const mode = e.target.value
updateConfig({ displayMode: mode })
}}
>
{Object.entries(DisplayMode).map(([key, desc]) => {
return (
<option value={key} key={key} selected={key === config.displayMode}>
{t(desc)}
</option>
)
})}
</select>
</label>
<label>
<legend>{t('Theme')}</legend>
<select
Expand Down