Skip to content

Commit f465930

Browse files
committed
Included queries from active tabs on toolbar icon click ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/perplexity-omnibox]
1 parent f92df35 commit f465930

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

chromium/extension/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"64": "icons/icon64.png",
1515
"128": "icons/icon128.png"
1616
},
17+
"permissions": ["activeTab"],
1718
"action": { "default_title": "__MSG_prefix_ask__ Perplexity.ai" },
1819
"omnibox": { "keyword" : "@perplexity" },
1920
"background": { "service_worker": "service-worker.js" },

chromium/extension/service-worker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ const perplexityURL = 'https://www.perplexity.ai'
1010
})()
1111

1212
// Launch Perplexity on toolbar icon click
13-
chrome.action.onClicked.addListener(() => chrome.tabs.create({ url: perplexityURL }))
13+
chrome.action.onClicked.addListener(async () => {
14+
const [activeTab] = await chrome.tabs.query({ active: true, currentWindow: true }),
15+
query = activeTab.url ? new URL(activeTab.url).searchParams.get('q') || 'hi' : 'hi'
16+
chrome.tabs.create({ url: `${perplexityURL}/search/new?q=${query}` })
17+
})
1418

1519
// Query Perplexity on omnibox query submitted
1620
chrome.omnibox.onInputEntered.addListener(query =>
17-
chrome.tabs.update({ url: `${perplexityURL}/search/new?q=${decodeURIComponent(query)}` }))
21+
chrome.tabs.update({ url: `${perplexityURL}/search/new?q=${query}` }))

0 commit comments

Comments
 (0)