Skip to content

Commit c3ebb79

Browse files
committed
feat: add entry for Independent Panel and Keyboard Shortcuts
1 parent d9bd4bf commit c3ebb79

File tree

12 files changed

+93
-7
lines changed

12 files changed

+93
-7
lines changed

src/_locales/en/main.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,8 @@
9292
"Unpin": "Unpin",
9393
"Delete Conversation": "Delete Conversation",
9494
"Clear conversations": "Clear conversations",
95-
"Settings": "Settings"
95+
"Settings": "Settings",
96+
"Feature Pages": "Feature Pages",
97+
"Keyboard Shortcuts": "Keyboard Shortcuts",
98+
"Open Conversation Page": "Open Conversation Page"
9699
}

src/_locales/zh-hans/main.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,8 @@
9292
"Unpin": "收缩侧边",
9393
"Delete Conversation": "删除对话",
9494
"Clear conversations": "清空记录",
95-
"Settings": "设置"
95+
"Settings": "设置",
96+
"Feature Pages": "功能页",
97+
"Keyboard Shortcuts": "快捷键设置",
98+
"Open Conversation Page": "打开独立对话页"
9699
}

src/_locales/zh-hant/main.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,8 @@
9292
"Unpin": "收縮側邊",
9393
"Delete Conversation": "刪除對話",
9494
"Clear conversations": "清空記錄",
95-
"Settings": "設置"
95+
"Settings": "設置",
96+
"Feature Pages": "功能頁",
97+
"Keyboard Shortcuts": "快捷鍵設置",
98+
"Open Conversation Page": "打開獨立對話頁"
9699
}

src/background/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ Browser.commands.onCommand.addListener(async (command) => {
156156
selectionText: '',
157157
useMenuPosition: false,
158158
}
159+
console.debug('command triggered', message)
160+
if (menuConfig[command].action) menuConfig[command].action()
159161
Browser.tabs.sendMessage(currentTab.id, {
160162
type: 'CREATE_CHAT',
161163
data: message,
@@ -208,6 +210,7 @@ function refreshMenu() {
208210
useMenuPosition: tab.id === currentTab.id,
209211
}
210212
console.debug('menu clicked', message)
213+
if (menuConfig[message.itemId].action) menuConfig[message.itemId].action()
211214
Browser.tabs.sendMessage(currentTab.id, {
212215
type: 'CREATE_CHAT',
213216
data: message,

src/content-script/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ async function prepareForRightClickMenu() {
241241
if (data.itemId in toolsConfig) {
242242
prompt = await toolsConfig[data.itemId].genPrompt(data.selectionText)
243243
} else if (data.itemId in menuConfig) {
244-
prompt = await menuConfig[data.itemId].genPrompt()
244+
const menuItem = menuConfig[data.itemId]
245+
if (!menuItem.genPrompt) return
246+
else prompt = await menuItem.genPrompt()
245247
if (prompt) prompt = cropText(`Reply in ${await getPreferredLanguage()}.\n` + prompt)
246248
}
247249

src/content-script/menu-tools/index.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getCoreContentText } from '../../utils/get-core-content-text'
2+
import { openUrl } from '../../utils/open-url'
3+
import Browser from 'webextension-polyfill'
24

35
export const config = {
46
newChat: {
@@ -13,4 +15,10 @@ export const config = {
1315
return `The following is the text content of a web page, analyze the core content and summarize:\n${getCoreContentText()}`
1416
},
1517
},
18+
openConversationPage: {
19+
label: 'Open Conversation Page',
20+
action: async () => {
21+
openUrl(Browser.runtime.getURL('IndependentPanel.html'))
22+
},
23+
},
1624
}

src/manifest.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"commands",
1818
"cookies",
1919
"storage",
20-
"contextMenus"
20+
"contextMenus",
21+
"unlimitedStorage"
2122
],
2223
"background": {
2324
"service_worker": "background.js"
@@ -69,6 +70,13 @@
6970
"mac": "Alt+B"
7071
},
7172
"description": "Summarize this page"
73+
},
74+
"openConversationPage": {
75+
"suggested_key": {
76+
"default": "Ctrl+Shift+H",
77+
"mac": "MacCtrl+Shift+H"
78+
},
79+
"description": "Open the independent conversation page"
7280
}
7381
}
7482
}

src/manifest.v2.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"cookies",
1515
"storage",
1616
"contextMenus",
17+
"unlimitedStorage",
1718
"https://*.openai.com/",
1819
"https://*.bing.com/"
1920
],
@@ -62,6 +63,13 @@
6263
"mac": "Alt+B"
6364
},
6465
"description": "Summarize this page"
66+
},
67+
"openConversationPage": {
68+
"suggested_key": {
69+
"default": "Ctrl+Shift+H",
70+
"mac": "MacCtrl+Shift+H"
71+
},
72+
"description": "Open the independent conversation page"
6573
}
6674
}
6775
}

src/popup/Popup.jsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import wechatpay from './donation/wechatpay.jpg'
2424
import bugmeacoffee from './donation/bugmeacoffee.png'
2525
import { useWindowTheme } from '../hooks/use-window-theme.mjs'
2626
import { languageList } from '../config/language.mjs'
27-
import { isMobile, isSafari } from '../utils/index.mjs'
27+
import { isEdge, isFirefox, isMobile, isSafari, openUrl } from '../utils/index.mjs'
2828
import { useTranslation } from 'react-i18next'
2929

3030
function GeneralPart({ config, updateConfig }) {
@@ -256,6 +256,34 @@ GeneralPart.propTypes = {
256256
updateConfig: PropTypes.func.isRequired,
257257
}
258258

259+
function FeaturePages() {
260+
const { t } = useTranslation()
261+
262+
return (
263+
<div style="display:flex;flex-direction:column;align-items:center;">
264+
{!isMobile() && !isFirefox() && !isSafari() && (
265+
<button
266+
type="button"
267+
onClick={() => {
268+
if (isEdge()) openUrl('edge://extensions/shortcuts')
269+
else openUrl('chrome://extensions/shortcuts')
270+
}}
271+
>
272+
{t('Keyboard Shortcuts')}
273+
</button>
274+
)}
275+
<button
276+
type="button"
277+
onClick={() => {
278+
openUrl(Browser.runtime.getURL('IndependentPanel.html'))
279+
}}
280+
>
281+
{t('Open Conversation Page')}
282+
</button>
283+
</div>
284+
)
285+
}
286+
259287
function AdvancedPart({ config, updateConfig }) {
260288
const { t } = useTranslation()
261289

@@ -514,6 +542,7 @@ function Popup() {
514542
<Tabs selectedTabClassName="popup-tab--selected">
515543
<TabList>
516544
<Tab className="popup-tab">{t('General')}</Tab>
545+
<Tab className="popup-tab">{t('Feature Pages')}</Tab>
517546
<Tab className="popup-tab">{t('Selection Tools')}</Tab>
518547
<Tab className="popup-tab">{t('Sites')}</Tab>
519548
<Tab className="popup-tab">{t('Advanced')}</Tab>
@@ -523,6 +552,9 @@ function Popup() {
523552
<TabPanel>
524553
<GeneralPart config={config} updateConfig={updateConfig} />
525554
</TabPanel>
555+
<TabPanel>
556+
<FeaturePages />
557+
</TabPanel>
526558
<TabPanel>
527559
<SelectionTools config={config} updateConfig={updateConfig} />
528560
</TabPanel>

src/utils/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export * from './get-conversation-pairs'
88
export * from './get-core-content-text'
99
export * from './get-possible-element-by-query-selector'
1010
export * from './init-session'
11-
export * from './is-firefox.mjs'
11+
export * from './is-edge'
12+
export * from './is-firefox'
1213
export * from './is-mobile'
1314
export * from './is-safari'
1415
export * from './limited-fetch'
16+
export * from './open-url'
1517
export * from './set-element-position-in-viewport'
1618
export * from './stream-async-iterable'
1719
export * from './update-ref-height'

0 commit comments

Comments
 (0)