├── .eslintignore ├── .eslintrc ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── e2e ├── basic.spec.ts └── fixtures.ts ├── extension └── assets │ ├── icon-128.png │ ├── icon-16.png │ ├── icon-32.png │ ├── icon-48.png │ └── icon.svg ├── modules.d.ts ├── package-lock.json ├── package.json ├── playwright.config.ts ├── pnpm-lock.yaml ├── scripts ├── manifest.ts ├── prepare.ts └── utils.ts ├── shim.d.ts ├── src ├── assets │ └── icon.svg ├── background │ ├── contentScriptHMR.ts │ ├── index.html │ └── main.ts ├── components │ ├── Logo.vue │ ├── README.md │ ├── SharedSubtitle.vue │ └── __tests__ │ │ └── Logo.test.ts ├── composables │ └── useStorageLocal.ts ├── contentScripts │ ├── index.ts │ └── views │ │ └── App.vue ├── env.ts ├── global.d.ts ├── logic │ ├── common-setup.ts │ ├── index.ts │ ├── message.ts │ ├── prompt.ts │ ├── prompts.ts │ └── storage.ts ├── manifest.ts ├── options │ ├── Options.vue │ ├── index.html │ └── main.ts ├── popup │ ├── Popup.vue │ ├── index.html │ └── main.ts ├── styles │ ├── index.ts │ ├── main.css │ └── popup.css └── tests │ └── demo.spec.ts ├── tsconfig.json ├── unocss.config.ts ├── vite.config.background.ts ├── vite.config.content.ts ├── vite.config.option.ts └── vite.config.ts /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | public 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@antfu" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/ 3 | .vite-ssg-dist 4 | .vite-ssg-temp 5 | *.crx 6 | *.local 7 | *.log 8 | *.pem 9 | *.xpi 10 | *.zip 11 | dist 12 | dist-ssr 13 | extension/manifest.json 14 | node_modules 15 | src/auto-imports.d.ts 16 | src/components.d.ts 17 | .eslintcache 18 | .vscode -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | auto-install-peers=true 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatGPT - Toolbox 2 | 3 | ChatGPT - Toolbox is a browser extension that allows users to easily interact with ChatGPT, a powerful language model trained by OpenAI. Users can simply select a piece of text on any webpage, right-click, and choose from a variety of pre-made prompts to engage in fascinating conversations with ChatGPT. 4 | 5 | # install 6 | 7 | [Chrome](https://chrome.google.com/webstore/detail/chatgpt-toolbox/pfimmkglmfkgbcinlmegcidajpcdnnhe?hl=en-GB&authuser=0) 8 | 9 | [Firefox](https://addons.mozilla.org/en-US/firefox/addon/chatgpt-toolbox/) 10 | 11 | # Screenshots 12 | 13 | Select a piece of text on the webpage and you can see your prompts on right-click menu -> ChatGPT Toolbox 14 | 15 | 16 | 17 | 18 | ### Add custom prompts on the option's page 19 | 20 | -------------------------------------------------------------------------------- /e2e/basic.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect, isDevArtifact, name, test } from './fixtures' 2 | 3 | test('example test', async ({ page }, testInfo) => { 4 | testInfo.skip(!isDevArtifact(), 'contentScript is in closed ShadowRoot mode') 5 | 6 | await page.goto('https://example.com') 7 | 8 | await page.locator(`#${name} button`).click() 9 | await expect(page.locator(`#${name} h1`)).toHaveText('Vitesse WebExt') 10 | }) 11 | 12 | test('popup page', async ({ page, extensionId }) => { 13 | await page.goto(`chrome-extension://${extensionId}/dist/popup/index.html`) 14 | await expect(page.locator('button')).toHaveText('Open Options') 15 | }) 16 | 17 | test('options page', async ({ page, extensionId }) => { 18 | await page.goto(`chrome-extension://${extensionId}/dist/options/index.html`) 19 | await expect(page.locator('img')).toHaveAttribute('alt', 'extension icon') 20 | }) 21 | -------------------------------------------------------------------------------- /e2e/fixtures.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path' 2 | import { setTimeout as sleep } from 'node:timers/promises' 3 | import fs from 'fs-extra' 4 | import { type BrowserContext, test as base, chromium } from '@playwright/test' 5 | import type { Manifest } from 'webextension-polyfill' 6 | 7 | export { name } from '../package.json' 8 | 9 | export const extensionPath = path.join(__dirname, '../extension') 10 | 11 | export const test = base.extend<{ 12 | context: BrowserContext 13 | extensionId: string 14 | }>({ 15 | context: async ({ headless }, use) => { 16 | // workaround for the Vite server has started but contentScript is not yet. 17 | await sleep(1000) 18 | const context = await chromium.launchPersistentContext('', { 19 | headless, 20 | args: [ 21 | ...(headless ? ['--headless=new'] : []), 22 | `--disable-extensions-except=${extensionPath}`, 23 | `--load-extension=${extensionPath}`, 24 | ], 25 | }) 26 | await use(context) 27 | await context.close() 28 | }, 29 | extensionId: async ({ context }, use) => { 30 | // for manifest v3: 31 | let [background] = context.serviceWorkers() 32 | if (!background) 33 | background = await context.waitForEvent('serviceworker') 34 | 35 | const extensionId = background.url().split('/')[2] 36 | await use(extensionId) 37 | }, 38 | }) 39 | 40 | export const expect = test.expect 41 | 42 | export function isDevArtifact() { 43 | const manifest: Manifest.WebExtensionManifest = fs.readJsonSync(path.resolve(extensionPath, 'manifest.json')) 44 | return Boolean( 45 | typeof manifest.content_security_policy === 'object' 46 | && manifest.content_security_policy.extension_pages?.includes('localhost'), 47 | ) 48 | } 49 | -------------------------------------------------------------------------------- /extension/assets/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smoqadam/chatgpt-toolbox/a695640a642bdc8bfd995f706e281dc7c979e558/extension/assets/icon-128.png -------------------------------------------------------------------------------- /extension/assets/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smoqadam/chatgpt-toolbox/a695640a642bdc8bfd995f706e281dc7c979e558/extension/assets/icon-16.png -------------------------------------------------------------------------------- /extension/assets/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smoqadam/chatgpt-toolbox/a695640a642bdc8bfd995f706e281dc7c979e558/extension/assets/icon-32.png -------------------------------------------------------------------------------- /extension/assets/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smoqadam/chatgpt-toolbox/a695640a642bdc8bfd995f706e281dc7c979e558/extension/assets/icon-48.png -------------------------------------------------------------------------------- /extension/assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@vue/runtime-core' { 2 | interface ComponentCustomProperties { 3 | $app: { 4 | context: string 5 | } 6 | } 7 | } 8 | 9 | // https://stackoverflow.com/a/64189046/479957 10 | export {} 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chatgpt-toolbox", 3 | "displayName": "ChatGPT-Toolbox", 4 | "version": "0.0.4", 5 | "private": true, 6 | "packageManager": "pnpm@8.3.1", 7 | "description": "ChatGPT-Toolbox helps you to interact with OpenAI's powerful AI", 8 | "scripts": { 9 | "dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*", 10 | "dev-firefox": "npm run clear && cross-env NODE_ENV=development EXTENSION=firefox run-p dev:*", 11 | "dev:prepare": "esno scripts/prepare.ts", 12 | "dev:background": "npm run build:background -- --mode development", 13 | "dev:option": "npm run build:option -- --mode development", 14 | "dev:web": "vite", 15 | "dev:js": "npm run build:js -- --mode development", 16 | "build": "cross-env NODE_ENV=production run-s clear build:web build:prepare build:option build:background build:js", 17 | "build:firefox": "cross-env NODE_ENV=production EXTENSION=firefox run-s clear build:web build:prepare build:option build:background build:js", 18 | "build:prepare": "esno scripts/prepare.ts", 19 | "build:background": "vite build --config vite.config.background.ts", 20 | "build:option": "vite build --config vite.config.option.ts", 21 | "build:web": "vite build", 22 | "build:js": "vite build --config vite.config.content.ts", 23 | "pack": "cross-env NODE_ENV=production run-p pack:*", 24 | "pack:zip": "rimraf extension.zip && jszip-cli add extension/* -o ./extension.zip", 25 | "pack:crx": "crx pack extension -o ./extension.crx", 26 | "pack:xpi": "cross-env WEB_EXT_ARTIFACTS_DIR=./ web-ext build --source-dir ./extension --filename extension.xpi --overwrite-dest", 27 | "start:chromium": "web-ext run --source-dir ./extension --target=chromium", 28 | "start:firefox": "web-ext run --source-dir ./extension --target=firefox-desktop", 29 | "clear": "rimraf --glob extension/dist extension/manifest.json extension.*", 30 | "lint": "eslint --cache .", 31 | "test": "vitest test", 32 | "test:e2e": "playwright test", 33 | "postinstall": "simple-git-hooks", 34 | "typecheck": "tsc --noEmit" 35 | }, 36 | "devDependencies": { 37 | "@antfu/eslint-config": "^0.36.0", 38 | "@ffflorian/jszip-cli": "^3.4.1", 39 | "@iconify/json": "^2.2.61", 40 | "@playwright/test": "^1.33.0", 41 | "@types/fs-extra": "^11.0.1", 42 | "@types/node": "^18.16.5", 43 | "@types/webextension-polyfill": "^0.10.0", 44 | "@typescript-eslint/eslint-plugin": "^5.59.2", 45 | "@unocss/reset": "^0.51.12", 46 | "@vitejs/plugin-vue": "^4.2.1", 47 | "@vue/compiler-sfc": "^3.2.47", 48 | "@vue/test-utils": "^2.3.2", 49 | "@vueuse/core": "^10.1.2", 50 | "chokidar": "^3.5.3", 51 | "cross-env": "^7.0.3", 52 | "crx": "^5.0.1", 53 | "eslint": "^8.40.0", 54 | "esno": "^0.16.3", 55 | "fs-extra": "^11.1.1", 56 | "jsdom": "^21.1.2", 57 | "kolorist": "^1.8.0", 58 | "lint-staged": "^13.2.2", 59 | "npm-run-all": "^4.1.5", 60 | "rimraf": "^4.4.1", 61 | "simple-git-hooks": "^2.8.1", 62 | "typescript": "^4.9.5", 63 | "unocss": "^0.51.12", 64 | "unplugin-auto-import": "^0.15.3", 65 | "unplugin-icons": "^0.16.1", 66 | "unplugin-vue-components": "^0.24.1", 67 | "vite": "^4.3.5", 68 | "vitest": "^0.31.0", 69 | "vue": "^3.2.47", 70 | "vue-demi": "^0.14.0", 71 | "web-ext": "^7.6.2", 72 | "webext-bridge": "^6.0.1", 73 | "webextension-polyfill": "^0.10.0" 74 | }, 75 | "simple-git-hooks": { 76 | "pre-commit": "pnpm lint-staged" 77 | }, 78 | "lint-staged": { 79 | "*": "eslint --fix" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /playwright.config.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @see {@link https://playwright.dev/docs/chrome-extensions Chrome extensions | Playwright} 3 | */ 4 | import { defineConfig } from '@playwright/test' 5 | 6 | export default defineConfig({ 7 | testDir: './e2e', 8 | retries: 2, 9 | webServer: { 10 | command: 'npm run dev', 11 | // start e2e test after the Vite server is fully prepared 12 | url: 'http://localhost:3303/popup/main.ts', 13 | reuseExistingServer: true, 14 | }, 15 | }) 16 | -------------------------------------------------------------------------------- /scripts/manifest.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs-extra' 2 | import { getManifest } from '../src/manifest' 3 | import { log, r } from './utils' 4 | 5 | export async function writeManifest() { 6 | await fs.writeJSON(r('extension/manifest.json'), await getManifest(), { spaces: 2 }) 7 | log('PRE', 'write manifest.json') 8 | } 9 | 10 | writeManifest() 11 | -------------------------------------------------------------------------------- /scripts/prepare.ts: -------------------------------------------------------------------------------- 1 | // generate stub index.html files for dev entry 2 | import { execSync } from 'node:child_process' 3 | import fs from 'fs-extra' 4 | import chokidar from 'chokidar' 5 | import { isDev, log, port, r } from './utils' 6 | 7 | /** 8 | * Stub index.html to use Vite in development 9 | */ 10 | async function stubIndexHtml() { 11 | const views = [ 12 | 'options', 13 | 'popup', 14 | 'background', 15 | ] 16 | 17 | for (const view of views) { 18 | await fs.ensureDir(r(`extension/dist/${view}`)) 19 | let data = await fs.readFile(r(`src/${view}/index.html`), 'utf-8') 20 | data = data 21 | .replace('"./main.ts"', `"http://localhost:${port}/${view}/main.ts"`) 22 | .replace('
', '
Vite server did not start
') 23 | await fs.writeFile(r(`extension/dist/${view}/index.html`), data, 'utf-8') 24 | log('PRE', `stub ${view}`) 25 | } 26 | } 27 | 28 | function writeManifest() { 29 | execSync('npx esno ./scripts/manifest.ts', { stdio: 'inherit' }) 30 | } 31 | 32 | writeManifest() 33 | 34 | if (isDev) { 35 | stubIndexHtml() 36 | chokidar.watch(r('src/**/*.html')) 37 | .on('change', () => { 38 | stubIndexHtml() 39 | }) 40 | chokidar.watch([r('src/manifest.ts'), r('package.json')]) 41 | .on('change', () => { 42 | writeManifest() 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /scripts/utils.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'node:path' 2 | import { bgCyan, black } from 'kolorist' 3 | 4 | export const port = parseInt(process.env.PORT || '') || 3303 5 | export const r = (...args: string[]) => resolve(__dirname, '..', ...args) 6 | export const isDev = process.env.NODE_ENV !== 'production' 7 | export const isFirefox = process.env.EXTENSION === 'firefox' 8 | 9 | export function log(name: string, message: string) { 10 | console.log(black(bgCyan(` ${name} `)), message) 11 | } 12 | -------------------------------------------------------------------------------- /shim.d.ts: -------------------------------------------------------------------------------- 1 | import type { ProtocolWithReturn } from 'webext-bridge' 2 | 3 | declare module 'webext-bridge' { 4 | export interface ProtocolMap { 5 | // define message protocol types 6 | // see https://github.com/antfu/webext-bridge#type-safe-protocols 7 | 'tab-prev': { title: string | undefined } 8 | 'get-current-tab': ProtocolWithReturn<{ tabId: number }, { title?: string }> 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/background/contentScriptHMR.ts: -------------------------------------------------------------------------------- 1 | import { isFirefox, isForbiddenUrl } from '~/env' 2 | 3 | // Firefox fetch files from cache instead of reloading changes from disk, 4 | // hmr will not work as Chromium based browser 5 | browser.webNavigation.onCommitted.addListener(({ tabId, frameId, url }) => { 6 | // Filter out non main window events. 7 | if (frameId !== 0) 8 | return 9 | 10 | if (isForbiddenUrl(url)) 11 | return 12 | 13 | // inject the latest scripts 14 | browser.tabs.executeScript(tabId, { 15 | file: `${isFirefox ? '' : '.'}/dist/contentScripts/index.global.js`, 16 | runAt: 'document_end', 17 | }).catch(error => console.error(error)) 18 | }) 19 | -------------------------------------------------------------------------------- /src/background/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Background 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/background/main.ts: -------------------------------------------------------------------------------- 1 | import { getApiKey, getPrompts, getPrompt, openOptions, OpenaiFetchAPI, sendMessage } from '~/logic/common-setup'; 2 | import { defaultPrompts } from '~/logic/prompts'; 3 | browser.runtime.onInstalled.addListener((): void => { 4 | // eslint-disable-next-line no-console 5 | console.log('Extension installed'); 6 | openOptions(); 7 | }) 8 | 9 | 10 | 11 | 12 | browser.contextMenus.create({ 13 | id: "parent", 14 | title: "ChatGPT-Toolbox", 15 | contexts: ["selection"], 16 | }); 17 | 18 | 19 | getPrompts().then((prompts) => { 20 | console.log({ prompts }); 21 | initContextMenu(prompts); 22 | }).catch(e => { 23 | console.log('defaultPrompts', defaultPrompts); 24 | browser.storage.local.set({ 25 | "api_key": "", 26 | "prompts": JSON.stringify(defaultPrompts) 27 | }); 28 | initContextMenu(defaultPrompts); 29 | console.error(e); 30 | }); 31 | 32 | function initContextMenu(prompts: Array) { 33 | prompts.forEach((p: any, i: number) => { 34 | console.log(p, i); 35 | 36 | browser.contextMenus.create({ 37 | title: p.label, 38 | id: p.id, 39 | parentId: "parent", 40 | contexts: ["selection"] 41 | }); 42 | }); 43 | } 44 | 45 | browser.browserAction.onClicked.addListener(openOptions); 46 | 47 | browser.runtime.onMessage.addListener((req) => { 48 | if (req.type == "openOption") { 49 | openOptions(); 50 | } 51 | }); 52 | 53 | 54 | 55 | browser.contextMenus.onClicked.addListener(async (info, tab) => { 56 | 57 | let promptObj = await getPrompt(info.menuItemId); 58 | let promptTxt: string = ""; 59 | 60 | promptTxt = promptObj.prompt.replace("{{TEXT}}", info.selectionText) 61 | 62 | console.log('context menu clicked', promptTxt); 63 | 64 | getApiKey().then(async (api_key) => { 65 | 66 | console.log('get api key', api_key); 67 | 68 | sendMessage(tab, { 69 | msg: 'clicked', 70 | data: { 71 | prompt: promptTxt, 72 | response: "" 73 | } 74 | }); 75 | 76 | OpenaiFetchAPI(promptTxt, api_key).then((response) => { 77 | 78 | sendMessage(tab, { 79 | msg: 'response', 80 | data: { 81 | prompt: promptTxt, 82 | response: response.choices[0].text 83 | } 84 | }); 85 | 86 | }).catch(e => { 87 | console.log(e); 88 | 89 | 90 | sendMessage(tab, { 91 | msg: 'missing_api_key', data: { 92 | prompt: promptTxt, 93 | response: 'Yout API key is missing. Please open the settings and enter your OpenAI\'s API key.' 94 | } 95 | } 96 | ); 97 | }) 98 | }).catch(async (e) => { 99 | console.log({ e }); 100 | sendMessage(tab, { 101 | msg: 'missing_api_key', data: { 102 | prompt: promptTxt, 103 | response: 'Yout API key is missing. Please open the settings and enter your OpenAI\'s API key.' 104 | } 105 | } 106 | ); 107 | }) 108 | }); 109 | -------------------------------------------------------------------------------- /src/components/Logo.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/components/README.md: -------------------------------------------------------------------------------- 1 | ## Components 2 | 3 | Components in this dir will be auto-registered and on-demand, powered by [`vite-plugin-components`](https://github.com/antfu/vite-plugin-components). 4 | 5 | Components can be shared in all views. 6 | 7 | ### Icons 8 | 9 | You can use icons from almost any icon sets by the power of [Iconify](https://iconify.design/). 10 | 11 | It will only bundle the icons you use. Check out [vite-plugin-icons](https://github.com/antfu/vite-plugin-icons) for more details. 12 | -------------------------------------------------------------------------------- /src/components/SharedSubtitle.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/components/__tests__/Logo.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | import { mount } from '@vue/test-utils' 3 | import Logo from '../Logo.vue' 4 | 5 | describe('Logo Component', () => { 6 | it('should render', () => { 7 | const wrapper = mount(Logo) 8 | 9 | expect(wrapper.html()).toBeTruthy() 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /src/composables/useStorageLocal.ts: -------------------------------------------------------------------------------- 1 | import { storage } from 'webextension-polyfill' 2 | import type { 3 | MaybeRef, 4 | RemovableRef, 5 | StorageLikeAsync, 6 | UseStorageAsyncOptions, 7 | } from '@vueuse/core' 8 | import { 9 | useStorageAsync, 10 | } from '@vueuse/core' 11 | 12 | export const storageLocal: StorageLikeAsync = { 13 | removeItem(key: string) { 14 | return storage.local.remove(key) 15 | }, 16 | 17 | setItem(key: string, value: string) { 18 | return storage.local.set({ [key]: value }) 19 | }, 20 | 21 | async getItem(key: string) { 22 | return (await storage.local.get(key))[key] 23 | }, 24 | } 25 | 26 | export const useStorageLocal = ( 27 | key: string, 28 | initialValue: MaybeRef, 29 | options?: UseStorageAsyncOptions, 30 | ): RemovableRef => useStorageAsync(key, initialValue, storageLocal, options) 31 | -------------------------------------------------------------------------------- /src/contentScripts/index.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './views/App.vue' 3 | import { setupApp } from '~/logic/common-setup' 4 | // import 5 | import '../styles/popup.css'; 6 | 7 | // Firefox `browser.tabs.executeScript()` requires scripts return a primitive value 8 | (() => { 9 | 10 | // mount component to context window 11 | const container = document.createElement('div') 12 | container.id = __NAME__ 13 | const root = document.createElement('div') 14 | const styleEl = document.createElement('link') 15 | const shadowDOM = container.attachShadow?.({ mode: __DEV__ ? 'open' : 'closed' }) || container 16 | styleEl.setAttribute('rel', 'stylesheet') 17 | styleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css')) 18 | shadowDOM.appendChild(styleEl) 19 | shadowDOM.appendChild(root) 20 | document.body.appendChild(container) 21 | const app = createApp(App) 22 | setupApp(app) 23 | app.mount(root) 24 | })() 25 | -------------------------------------------------------------------------------- /src/contentScripts/views/App.vue: -------------------------------------------------------------------------------- 1 | 33 | 77 | -------------------------------------------------------------------------------- /src/env.ts: -------------------------------------------------------------------------------- 1 | const forbiddenProtocols = [ 2 | 'chrome-extension://', 3 | 'chrome-search://', 4 | 'chrome://', 5 | 'devtools://', 6 | 'edge://', 7 | 'https://chrome.google.com/webstore', 8 | ] 9 | 10 | export function isForbiddenUrl(url: string): boolean { 11 | return forbiddenProtocols.some(protocol => url.startsWith(protocol)) 12 | } 13 | 14 | export const isFirefox = navigator.userAgent.includes('Firefox') 15 | -------------------------------------------------------------------------------- /src/global.d.ts: -------------------------------------------------------------------------------- 1 | declare const __DEV__: boolean 2 | /** Extension name, defined in packageJson.name */ 3 | declare const __NAME__: string 4 | 5 | declare module '*.vue' { 6 | const component: any 7 | export default component 8 | } 9 | -------------------------------------------------------------------------------- /src/logic/common-setup.ts: -------------------------------------------------------------------------------- 1 | import type { App } from 'vue' 2 | 3 | export function setupApp(app: App) { 4 | // Inject a globally available `$app` object in template 5 | app.config.globalProperties.$app = { 6 | context: '', 7 | } 8 | 9 | // Provide access to `app` in script setup with `const app = inject('app')` 10 | app.provide('app', app.config.globalProperties.$app) 11 | 12 | // Here you can install additional plugins for all contexts: popup, options page and content-script. 13 | // example: app.use(i18n) 14 | // example excluding content-script context: if (context !== 'content-script') app.use(i18n) 15 | } 16 | 17 | 18 | export async function getPrompts(): Promise { 19 | 20 | return new Promise((resolve, reject) => { 21 | browser.storage.local.get("prompts").then((result) => { 22 | if (result.prompts !== undefined) { 23 | console.log({result}); 24 | 25 | let json = JSON.parse(result.prompts); 26 | resolve(json); 27 | } else { 28 | let err = new Error('There is no prompts in local db') 29 | reject(err); 30 | } 31 | }) 32 | }); 33 | } 34 | 35 | 36 | export const getPrompt = async (id: string|number): Promise => { 37 | return new Promise(async (resolve, reject) => { 38 | let prompts = await getPrompts(); 39 | prompts.forEach((v: Prompt) => { 40 | if (v.id == id) { 41 | resolve(v); 42 | } 43 | }); 44 | }); 45 | } 46 | 47 | export async function getApiKey(): Promise { 48 | 49 | return new Promise((resolve, reject) => { 50 | browser.storage.local.get("api_key").then(result => { 51 | if (result.api_key !== undefined) { 52 | resolve(result.api_key); 53 | } else { 54 | let err = new Error('API key must be set') 55 | reject(err) 56 | } 57 | }); 58 | }); 59 | } 60 | 61 | 62 | export function openOptions() { 63 | let url = browser.runtime.getURL('./dist/options/index.html'); 64 | browser.tabs.create({ 'url': url }); 65 | } 66 | 67 | 68 | export async function OpenaiFetchAPI(prompt: string, token: string) { 69 | console.log({token}); 70 | 71 | var url = "https://api.openai.com/v1/completions"; 72 | var bearer = 'Bearer ' + token 73 | 74 | let res = await fetch(url, { 75 | method: 'POST', 76 | headers: { 77 | 'Authorization': bearer, 78 | 'Content-Type': 'application/json' 79 | }, 80 | body: JSON.stringify({ 81 | "model": "text-davinci-003", 82 | "prompt": prompt, 83 | "max_tokens": 3000, 84 | "temperature": 1, 85 | }) 86 | }); 87 | return await res.json(); 88 | 89 | } 90 | 91 | 92 | export function sendMessage(tab: any, msg: Message): void { 93 | browser.tabs.sendMessage(tab.id, msg); 94 | } -------------------------------------------------------------------------------- /src/logic/index.ts: -------------------------------------------------------------------------------- 1 | export * from './storage' 2 | -------------------------------------------------------------------------------- /src/logic/message.ts: -------------------------------------------------------------------------------- 1 | interface Message { 2 | msg: string, 3 | data: { 4 | prompt: string, 5 | response: string, 6 | } 7 | } -------------------------------------------------------------------------------- /src/logic/prompt.ts: -------------------------------------------------------------------------------- 1 | 2 | interface Prompt { 3 | id: string, 4 | label: string, 5 | prompt: string 6 | } -------------------------------------------------------------------------------- /src/logic/prompts.ts: -------------------------------------------------------------------------------- 1 | export let defaultPrompts = [ 2 | { 3 | "label": "Use as a prompt", 4 | "id": "prompt", 5 | "prompt": "{{TEXT}}" 6 | }, 7 | { 8 | "label": "Explain this", 9 | "id": "explain", 10 | "prompt": "Explain this text: \"{{TEXT}}\"" 11 | }, 12 | { 13 | "label": "ELI5", 14 | "id": "elif", 15 | "prompt": "Explaing this text like I'm 5 years old: \"{{TEXT}}\"" 16 | }, 17 | { 18 | "label": "English Translator and Improver", 19 | "id": "english_tr", 20 | "prompt": "I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. The text is \"{{TEXT}}\"" 21 | }, 22 | { 23 | "label": "Proofreader", 24 | "id": "proofreader", 25 | "prompt": "I want you act as a proofreader. I will provide you texts and I would like you to review them for any spelling, grammar, or punctuation errors. Once you have finished reviewing the text, provide me with any necessary corrections or suggestions for improve the text. The text is: \"{{TEXT}}\"" 26 | } 27 | ] -------------------------------------------------------------------------------- /src/logic/storage.ts: -------------------------------------------------------------------------------- 1 | import { useStorageLocal } from '~/composables/useStorageLocal' 2 | 3 | export const openaiApiKey = useStorageLocal('openai-apikey', '') 4 | export const prompts = useStorageLocal('prompts', []) 5 | 6 | -------------------------------------------------------------------------------- /src/manifest.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs-extra' 2 | import type { Manifest } from 'webextension-polyfill' 3 | import type PkgType from '../package.json' 4 | import { isDev, isFirefox, r } from '../scripts/utils' 5 | 6 | export async function getManifest() { 7 | const pkg = await fs.readJSON(r('package.json')) as typeof PkgType 8 | 9 | console.log(process.env.EXTENSION) 10 | // update this file to update this manifest.json 11 | // can also be conditional based on your need 12 | const manifest: Manifest.WebExtensionManifest = { 13 | manifest_version: isFirefox ? 2 : 3, 14 | name: pkg.displayName || pkg.name, 15 | version: pkg.version, 16 | description: pkg.description, 17 | options_ui: { 18 | page: './dist/options/index.html', 19 | open_in_tab: true, 20 | }, 21 | background: isFirefox 22 | ? { 23 | scripts: ['dist/background/index.mjs'], 24 | type: 'module', 25 | } 26 | : { 27 | service_worker: './dist/background/index.mjs', 28 | }, 29 | icons: { 30 | 16: './assets/icon-16.png', 31 | 48: './assets/icon-48.png', 32 | 128: './assets/icon-128.png', 33 | }, 34 | permissions: [ 35 | 'tabs', 36 | 'storage', 37 | 'activeTab', 38 | "contextMenus", 39 | "*://api.openai.com/*" 40 | ], 41 | content_scripts: [ 42 | { 43 | matches: [ 44 | '', 45 | ], 46 | js: [ 47 | 'dist/contentScripts/index.global.js', 48 | ], 49 | }, 50 | ], 51 | web_accessible_resources: 52 | isFirefox ? 53 | ['dist/contentScripts/style.css'] 54 | : 55 | [ 56 | 57 | { 58 | resources: ['dist/contentScripts/style.css'], 59 | matches: [''], 60 | }, 61 | ], 62 | browser_action: { 63 | "default_icon": { 64 | 16: './assets/icon-16.png', 65 | 48: './assets/icon-48.png', 66 | 128: './assets/icon-128.png', 67 | }, 68 | } 69 | } 70 | 71 | if (!isFirefox) { 72 | manifest.action = { 73 | default_icon: './assets/icon-512.png', 74 | default_popup: './dist/popup/index.html', 75 | }; 76 | 77 | manifest.host_permissions = ['*://*/*']; 78 | } 79 | 80 | // FIXME: not work in MV3 81 | if (isDev && false) { 82 | // for content script, as browsers will cache them for each reload, 83 | // we use a background script to always inject the latest version 84 | // see src/background/contentScriptHMR.ts 85 | delete manifest.content_scripts 86 | manifest.permissions?.push('webNavigation') 87 | } 88 | 89 | return manifest 90 | } 91 | -------------------------------------------------------------------------------- /src/options/Options.vue: -------------------------------------------------------------------------------- 1 | 98 | 99 | 212 | -------------------------------------------------------------------------------- /src/options/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ChatGPT-Toolbox Options 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/options/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './Options.vue' 3 | import { setupApp } from '~/logic/common-setup' 4 | import '../styles' 5 | 6 | const app = createApp(App) 7 | setupApp(app) 8 | app.mount('#options') 9 | -------------------------------------------------------------------------------- /src/popup/Popup.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 22 | -------------------------------------------------------------------------------- /src/popup/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Popup 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/popup/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './Popup.vue' 3 | import { setupApp } from '~/logic/common-setup' 4 | import '../styles' 5 | 6 | const app = createApp(App) 7 | setupApp(app) 8 | app.mount('#app') 9 | -------------------------------------------------------------------------------- /src/styles/index.ts: -------------------------------------------------------------------------------- 1 | import '@unocss/reset/tailwind.css' 2 | import './main.css' 3 | import 'uno.css' 4 | -------------------------------------------------------------------------------- /src/styles/main.css: -------------------------------------------------------------------------------- 1 | html, 2 | body, 3 | #app { 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | .btn { 9 | @apply px-4 py-1 rounded inline-block 10 | bg-teal-600 text-white cursor-pointer 11 | hover:bg-teal-700 12 | disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50; 13 | } 14 | 15 | .icon-btn { 16 | @apply inline-block cursor-pointer select-none 17 | opacity-75 transition duration-200 ease-in-out 18 | hover:opacity-100 hover:text-teal-600; 19 | font-size: 0.9em; 20 | } 21 | 22 | .input { 23 | padding: 5px; 24 | } -------------------------------------------------------------------------------- /src/styles/popup.css: -------------------------------------------------------------------------------- 1 | #chatgpt-toolbox__container { 2 | width: 350px !important; 3 | height: 590px !important; 4 | position: fixed !important; 5 | top: 10px !important; 6 | right: 20px !important; 7 | background-color: #444654 !important; 8 | z-index: 9999 !important; 9 | color: aliceblue !important; 10 | border-radius: 5px !important; 11 | font-family: 'helvetica neue' !important; 12 | flex-direction: column; 13 | } 14 | 15 | #chatgpt-toolbox-hidden { 16 | display: none !important; 17 | } 18 | 19 | .chatgpt-toolbox-show { 20 | display: flex !important; 21 | } 22 | 23 | #chatgpt-toolbox__header-content { 24 | display: flex !important; 25 | flex-direction: row; 26 | padding: 4 !important; 27 | height: 40px; 28 | align-items: center; 29 | } 30 | 31 | #chatgpt-toolbox__header h3 { 32 | flex-grow: 9 !important; 33 | font-size: 15px !important; 34 | margin: 0 !important; 35 | color: #eee !important; 36 | font-family: sans-serif !important; 37 | padding: 5px !important; 38 | font-weight: bold !important; 39 | text-align: left !important; 40 | display: flex !important; 41 | align-items: center !important; 42 | 43 | } 44 | 45 | #chatgpt-toolbox__close { 46 | cursor: pointer !important; 47 | /* display: flex !important; 48 | align-items: center !important;*/ 49 | width: 25px !important; 50 | height: 25px !important; 51 | 52 | flex: 1 !important; 53 | padding: 5px !important; 54 | 55 | margin: 0 6px !important; 56 | } 57 | 58 | #chatgpt-toolbox__close:hover { 59 | background-image: url('/src/assets/icons/close-hover.png') !important; 60 | 61 | } 62 | 63 | #chatgpt-toolbox__settings { 64 | padding: 5px !important; 65 | cursor: pointer !important; 66 | flex: 1 !important; 67 | display: flex !important; 68 | align-items: center; 69 | width: 20px !important; 70 | height: 20px !important; 71 | background-image: url('/src/assets/icons/settings.png') !important; 72 | text-align: right !important; 73 | font-weight: bold !important; 74 | font-family: sans-serif !important; 75 | background-size: 18px !important; 76 | background-repeat: no-repeat !important; 77 | background-position: center !important; 78 | max-width: 15px !important; 79 | } 80 | 81 | 82 | #chatgpt-toolbox__settings:hover { 83 | background-image: url('/src/assets/icons/settings-hover.png') !important; 84 | 85 | } 86 | 87 | #chatgpt-toolbox__box { 88 | background: #343541 !important; 89 | flex: 5; 90 | display: flex; 91 | flex-direction: column; 92 | max-height: 40% !important; 93 | height: 40% !important; 94 | } 95 | 96 | #chatgpt-toolbox__box-content { 97 | font-size: 15px !important; 98 | padding: 10px !important; 99 | display: flex !important; 100 | flex-direction: column !important; 101 | overflow-y: auto !important; 102 | } 103 | 104 | #chatgpt-toolbox__box-response { 105 | background-color: #444654 !important; 106 | } 107 | 108 | #chatgpt-toolkit__response code { 109 | font-size: 13px !important; 110 | background: #191919 !important; 111 | clear: both !important; 112 | display: flex !important; 113 | max-width: 100% !important; 114 | overflow-x: auto !important; 115 | padding: 10px !important; 116 | margin: 10px 0 !important; 117 | } 118 | 119 | #chatgpt-toolbox__title { 120 | font-weight: bold !important; 121 | margin-bottom: 10px; 122 | } 123 | -------------------------------------------------------------------------------- /src/tests/demo.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | describe('Demo', () => { 4 | it('should work', () => { 5 | expect(1 + 1).toBe(2) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "module": "ESNext", 5 | "target": "es2016", 6 | "lib": ["DOM", "ESNext"], 7 | "strict": true, 8 | "esModuleInterop": true, 9 | "incremental": false, 10 | "skipLibCheck": true, 11 | "jsx": "preserve", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "noUnusedLocals": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "types": [ 17 | "vite/client" 18 | ], 19 | "paths": { 20 | "~/*": ["src/*"] 21 | } 22 | }, 23 | "exclude": ["dist", "node_modules"] 24 | } 25 | -------------------------------------------------------------------------------- /unocss.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'unocss/vite' 2 | import { presetAttributify, presetIcons, presetUno, transformerDirectives } from 'unocss' 3 | 4 | export default defineConfig({ 5 | presets: [ 6 | presetUno(), 7 | presetAttributify(), 8 | presetIcons(), 9 | ], 10 | transformers: [ 11 | transformerDirectives(), 12 | ], 13 | }) 14 | -------------------------------------------------------------------------------- /vite.config.background.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import { sharedConfig } from './vite.config' 3 | import { isDev, r } from './scripts/utils' 4 | import packageJson from './package.json' 5 | 6 | // bundling the content script using Vite 7 | export default defineConfig({ 8 | ...sharedConfig, 9 | define: { 10 | '__DEV__': isDev, 11 | '__NAME__': JSON.stringify(packageJson.name), 12 | // https://github.com/vitejs/vite/issues/9320 13 | // https://github.com/vitejs/vite/issues/9186 14 | 'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'), 15 | }, 16 | build: { 17 | watch: isDev 18 | ? {} 19 | : undefined, 20 | outDir: r('extension/dist/background'), 21 | cssCodeSplit: false, 22 | emptyOutDir: false, 23 | sourcemap: isDev ? 'inline' : false, 24 | lib: { 25 | entry: r('src/background/main.ts'), 26 | name: packageJson.name, 27 | formats: ['iife'], 28 | }, 29 | rollupOptions: { 30 | output: { 31 | entryFileNames: 'index.mjs', 32 | extend: true, 33 | }, 34 | }, 35 | }, 36 | }) 37 | -------------------------------------------------------------------------------- /vite.config.content.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import { sharedConfig } from './vite.config' 3 | import { isDev, r } from './scripts/utils' 4 | import packageJson from './package.json' 5 | 6 | // bundling the content script using Vite 7 | export default defineConfig({ 8 | ...sharedConfig, 9 | define: { 10 | '__DEV__': isDev, 11 | '__NAME__': JSON.stringify(packageJson.name), 12 | // https://github.com/vitejs/vite/issues/9320 13 | // https://github.com/vitejs/vite/issues/9186 14 | 'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'), 15 | }, 16 | build: { 17 | watch: isDev 18 | ? {} 19 | : undefined, 20 | outDir: r('extension/dist/contentScripts'), 21 | cssCodeSplit: false, 22 | emptyOutDir: false, 23 | sourcemap: isDev ? 'inline' : false, 24 | lib: { 25 | entry: r('src/contentScripts/index.ts'), 26 | name: packageJson.name, 27 | formats: ['iife'], 28 | }, 29 | rollupOptions: { 30 | output: { 31 | entryFileNames: 'index.global.js', 32 | extend: true, 33 | }, 34 | }, 35 | }, 36 | }) 37 | -------------------------------------------------------------------------------- /vite.config.option.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import { sharedConfig } from './vite.config' 3 | import { isDev, r } from './scripts/utils' 4 | import packageJson from './package.json' 5 | 6 | // bundling the content script using Vite 7 | export default defineConfig({ 8 | ...sharedConfig, 9 | define: { 10 | '__DEV__': isDev, 11 | '__NAME__': JSON.stringify(packageJson.name), 12 | // https://github.com/vitejs/vite/issues/9320 13 | // https://github.com/vitejs/vite/issues/9186 14 | 'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'), 15 | }, 16 | build: { 17 | watch: isDev 18 | ? {} 19 | : undefined, 20 | outDir: r('extension/dist/options'), 21 | cssCodeSplit: false, 22 | emptyOutDir: false, 23 | sourcemap: isDev ? 'inline' : false, 24 | lib: { 25 | entry: r('src/options/main.ts'), 26 | name: packageJson.name, 27 | formats: ['iife'], 28 | }, 29 | rollupOptions: { 30 | output: { 31 | entryFileNames: 'index.global.js', 32 | extend: true, 33 | }, 34 | }, 35 | }, 36 | }) 37 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { dirname, relative } from 'node:path' 4 | import type { UserConfig } from 'vite' 5 | import { defineConfig } from 'vite' 6 | import Vue from '@vitejs/plugin-vue' 7 | import Icons from 'unplugin-icons/vite' 8 | import IconsResolver from 'unplugin-icons/resolver' 9 | import Components from 'unplugin-vue-components/vite' 10 | import AutoImport from 'unplugin-auto-import/vite' 11 | import UnoCSS from 'unocss/vite' 12 | import { isDev, port, r } from './scripts/utils' 13 | import packageJson from './package.json' 14 | 15 | export const sharedConfig: UserConfig = { 16 | root: r('src'), 17 | resolve: { 18 | alias: { 19 | '~/': `${r('src')}/`, 20 | }, 21 | }, 22 | define: { 23 | __DEV__: isDev, 24 | __NAME__: JSON.stringify(packageJson.name), 25 | }, 26 | plugins: [ 27 | Vue(), 28 | 29 | AutoImport({ 30 | imports: [ 31 | 'vue', 32 | { 33 | 'webextension-polyfill': [ 34 | ['*', 'browser'], 35 | ], 36 | }, 37 | ], 38 | dts: r('src/auto-imports.d.ts'), 39 | }), 40 | 41 | // https://github.com/antfu/unplugin-vue-components 42 | Components({ 43 | dirs: [r('src/components')], 44 | // generate `components.d.ts` for ts support with Volar 45 | dts: r('src/components.d.ts'), 46 | resolvers: [ 47 | // auto import icons 48 | IconsResolver({ 49 | componentPrefix: '', 50 | }), 51 | ], 52 | }), 53 | 54 | // https://github.com/antfu/unplugin-icons 55 | Icons(), 56 | 57 | // https://github.com/unocss/unocss 58 | UnoCSS(), 59 | 60 | // rewrite assets to use relative path 61 | { 62 | name: 'assets-rewrite', 63 | enforce: 'post', 64 | apply: 'build', 65 | transformIndexHtml(html, { path }) { 66 | return html.replace(/"\/assets\//g, `"${relative(dirname(path), '/assets')}/`) 67 | }, 68 | }, 69 | ], 70 | optimizeDeps: { 71 | include: [ 72 | 'vue', 73 | '@vueuse/core', 74 | 'webextension-polyfill', 75 | ], 76 | exclude: [ 77 | 'vue-demi', 78 | ], 79 | }, 80 | } 81 | 82 | export default defineConfig(({ command }) => ({ 83 | ...sharedConfig, 84 | base: command === 'serve' ? `http://localhost:${port}/` : '/dist/', 85 | server: { 86 | port, 87 | hmr: { 88 | host: 'localhost', 89 | }, 90 | }, 91 | build: { 92 | watch: isDev 93 | ? {} 94 | : undefined, 95 | outDir: r('extension/dist'), 96 | emptyOutDir: false, 97 | sourcemap: isDev ? 'inline' : false, 98 | // https://developer.chrome.com/docs/webstore/program_policies/#:~:text=Code%20Readability%20Requirements 99 | terserOptions: { 100 | mangle: false, 101 | }, 102 | rollupOptions: { 103 | input: { 104 | options: r('src/options/index.html'), 105 | popup: r('src/popup/index.html'), 106 | }, 107 | }, 108 | }, 109 | test: { 110 | globals: true, 111 | environment: 'jsdom', 112 | }, 113 | })) 114 | --------------------------------------------------------------------------------