Skip to content

Commit

Permalink
feat: add firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
Quilljou committed May 6, 2024
1 parent 359305d commit bb3dea7
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 17 deletions.
Binary file removed .DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"watch": "webpack --config webpack/webpack.dev.js --watch",
"build": "npm run clean && webpack --config webpack/webpack.prod.js && npm run pack",
"build": "npm run clean && webpack --config webpack/webpack.prod.js",
"build:ff": "npm run build && cp public/manifest-firefox.json dist/manifest.json && npm run pack",
"build:chrome": "npm run build && npm run pack",
"pack": "cd dist/ && zip -r dist.zip *",
"clean": "rimraf dist",
"test": "npx jest",
Expand All @@ -18,8 +20,10 @@
"url": "https://github.com/chibat/chrome-extension-typescript-starter.git"
},
"dependencies": {
"@types/webextension-polyfill": "^0.10.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"webextension-polyfill": "^0.11.0"
},
"devDependencies": {
"@types/chrome": "0.0.158",
Expand Down
23 changes: 23 additions & 0 deletions public/manifest-firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"manifest_version": 2,

"name": "Open in Perplexity",
"description": "Add Perplexity to your context menus.",
"version": "1.0",

"action": {
"default_icon": "icon.png"
},

"permissions": ["contextMenus"],

"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},

"background": {
"scripts": ["js/background.js"]
}
}
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,

"name": "Open in Perplexity",
"description": "Seamlessly search experience with Perplexity",
"description": "Add Perplexity to your context menus.",
"version": "1.0",

"action": {
Expand Down
Binary file added src.zip
Binary file not shown.
25 changes: 12 additions & 13 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
const PAGE_ID = "open-in-perplexity"
const SELECTION_ID = "open-in-perplexity-selection"
const P_URL = 'https://www.perplexity.ai?utm_source=oip'
import browser from 'webextension-polyfill'

const PAGE_ID = "open-in-perplexity";
const SELECTION_ID = "open-in-perplexity-selection";
const P_URL = 'https://www.perplexity.ai';

chrome.contextMenus.create({
browser.contextMenus.create({
id: SELECTION_ID,
title: 'Perplexity "%s"',
contexts: ['selection']
});

chrome.contextMenus.create({
browser.contextMenus.create({
id: PAGE_ID,
title: 'Open Perplexity',
contexts: ['page', 'frame']
});



chrome.contextMenus.onClicked.addListener(function (info, tab) {
browser.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === SELECTION_ID) {
chrome.tabs.create({ url: P_URL + `&q=${info.selectionText}` });
browser.tabs.create({ url: P_URL + `?q=${info.selectionText}` });
} else if (info.menuItemId === PAGE_ID) {
chrome.tabs.create({ url: P_URL });
browser.tabs.create({ url: P_URL });
}
});

chrome.action.onClicked.addListener((tab) => {
chrome.tabs.create({ url: P_URL });
});
browser.action.onClicked.addListener((tab) => {
browser.tabs.create({ url: P_URL });
});
66 changes: 65 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@
resolved "https://registry.npmmirror.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==

"@types/webextension-polyfill@^0.10.7":
version "0.10.7"
resolved "https://registry.npmmirror.com/@types/webextension-polyfill/-/webextension-polyfill-0.10.7.tgz#de059250599733a60ed26c8a0c81e21e11183b90"
integrity sha512-10ql7A0qzBmFB+F+qAke/nP1PIonS0TXZAOMVOxEUsm+lGSW6uwVcISFNa0I4Oyj0884TZVWGGMIWeXOVSNFHw==

"@types/yargs-parser@*":
version "21.0.3"
resolved "https://registry.npmmirror.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
Expand Down Expand Up @@ -879,18 +884,33 @@
resolved "https://registry.npmmirror.com/@webpack-cli/configtest/-/configtest-1.2.0.tgz#7b20ce1c12533912c3b217ea68262365fa29a6f5"
integrity sha512-4FB8Tj6xyVkyqjj1OaTqCjXYULB9FMkqQ8yGrZjRDrYh0nOE+7Lhs45WioWQQMV+ceFlE368Ukhe6xdvJM9Egg==

"@webpack-cli/configtest@^2.1.1":
version "2.1.1"
resolved "https://registry.npmmirror.com/@webpack-cli/configtest/-/configtest-2.1.1.tgz#3b2f852e91dac6e3b85fb2a314fb8bef46d94646"
integrity sha512-wy0mglZpDSiSS0XHrVR+BAdId2+yxPSoJW8fsna3ZpYSlufjvxnP4YbKTCBZnNIcGN4r6ZPXV55X4mYExOfLmw==

"@webpack-cli/info@^1.5.0":
version "1.5.0"
resolved "https://registry.npmmirror.com/@webpack-cli/info/-/info-1.5.0.tgz#6c78c13c5874852d6e2dd17f08a41f3fe4c261b1"
integrity sha512-e8tSXZpw2hPl2uMJY6fsMswaok5FdlGNRTktvFk2sD8RjH0hE2+XistawJx1vmKteh4NmGmNUrp+Tb2w+udPcQ==
dependencies:
envinfo "^7.7.3"

"@webpack-cli/info@^2.0.2":
version "2.0.2"
resolved "https://registry.npmmirror.com/@webpack-cli/info/-/info-2.0.2.tgz#cc3fbf22efeb88ff62310cf885c5b09f44ae0fdd"
integrity sha512-zLHQdI/Qs1UyT5UBdWNqsARasIA+AaF8t+4u2aS2nEpBQh2mWIVb8qAklq0eUENnC5mOItrIB4LiS9xMtph18A==

"@webpack-cli/serve@^1.7.0":
version "1.7.0"
resolved "https://registry.npmmirror.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1"
integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q==

"@webpack-cli/serve@^2.0.5":
version "2.0.5"
resolved "https://registry.npmmirror.com/@webpack-cli/serve/-/serve-2.0.5.tgz#325db42395cd49fe6c14057f9a900e427df8810e"
integrity sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ==

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.npmmirror.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
Expand Down Expand Up @@ -1205,6 +1225,11 @@ colorette@^2.0.14:
resolved "https://registry.npmmirror.com/colorette/-/colorette-2.0.20.tgz#9eb793e6833067f7235902fcd3b09917a000a95a"
integrity sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==

commander@^10.0.1:
version "10.0.1"
resolved "https://registry.npmmirror.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==

commander@^2.20.0:
version "2.20.3"
resolved "https://registry.npmmirror.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
Expand Down Expand Up @@ -1656,6 +1681,11 @@ interpret@^2.2.0:
resolved "https://registry.npmmirror.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9"
integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==

interpret@^3.1.1:
version "3.1.1"
resolved "https://registry.npmmirror.com/interpret/-/interpret-3.1.1.tgz#5be0ceed67ca79c6c4bc5cf0d7ee843dcea110c4"
integrity sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==

is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.npmmirror.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
Expand Down Expand Up @@ -2539,6 +2569,13 @@ rechoir@^0.7.0:
dependencies:
resolve "^1.9.0"

rechoir@^0.8.0:
version "0.8.0"
resolved "https://registry.npmmirror.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22"
integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==
dependencies:
resolve "^1.20.0"

require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.npmmirror.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
Expand Down Expand Up @@ -2919,6 +2956,14 @@ watchpack@^2.4.1:
glob-to-regexp "^0.4.1"
graceful-fs "^4.1.2"

webextension-polyfill@^0.11.0:
version "0.11.0"
resolved "https://registry.npmmirror.com/webextension-polyfill/-/webextension-polyfill-0.11.0.tgz#1640c0d27192424fd5b420237acbe453f88c8246"
integrity sha512-YUBSKQA0iCx2YtM75VFgvvcx1hLKaGGiph6a6UaUdSgk32VT9SzrcDAKBjeGHXoAZTnNBqS5skA4VfoKMXhEBA==
dependencies:
webpack "^5.91.0"
webpack-cli "^5.1.4"

webpack-cli@^4.0.0:
version "4.10.0"
resolved "https://registry.npmmirror.com/webpack-cli/-/webpack-cli-4.10.0.tgz#37c1d69c8d85214c5a65e589378f53aec64dab31"
Expand All @@ -2937,6 +2982,25 @@ webpack-cli@^4.0.0:
rechoir "^0.7.0"
webpack-merge "^5.7.3"

webpack-cli@^5.1.4:
version "5.1.4"
resolved "https://registry.npmmirror.com/webpack-cli/-/webpack-cli-5.1.4.tgz#c8e046ba7eaae4911d7e71e2b25b776fcc35759b"
integrity sha512-pIDJHIEI9LR0yxHXQ+Qh95k2EvXpWzZ5l+d+jIo+RdSm9MiHfzazIxwwni/p7+x4eJZuvG1AJwgC4TNQ7NRgsg==
dependencies:
"@discoveryjs/json-ext" "^0.5.0"
"@webpack-cli/configtest" "^2.1.1"
"@webpack-cli/info" "^2.0.2"
"@webpack-cli/serve" "^2.0.5"
colorette "^2.0.14"
commander "^10.0.1"
cross-spawn "^7.0.3"
envinfo "^7.7.3"
fastest-levenshtein "^1.0.12"
import-local "^3.0.2"
interpret "^3.1.1"
rechoir "^0.8.0"
webpack-merge "^5.7.3"

webpack-merge@^5.0.0, webpack-merge@^5.7.3:
version "5.10.0"
resolved "https://registry.npmmirror.com/webpack-merge/-/webpack-merge-5.10.0.tgz#a3ad5d773241e9c682803abf628d4cd62b8a4177"
Expand All @@ -2951,7 +3015,7 @@ webpack-sources@^3.2.3:
resolved "https://registry.npmmirror.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==

webpack@^5.76.0:
webpack@^5.76.0, webpack@^5.91.0:
version "5.91.0"
resolved "https://registry.npmmirror.com/webpack/-/webpack-5.91.0.tgz#ffa92c1c618d18c878f06892bbdc3373c71a01d9"
integrity sha512-rzVwlLeBWHJbmgTC/8TvAcu5vpJNII+MelQpylD4jNERPwpBJOE2lEcko1zJX3QJeLjTTAnQxn/OJ8bjDzVQaw==
Expand Down

0 comments on commit bb3dea7

Please sign in to comment.