Skip to content

Commit

Permalink
Merge pull request #137 from extension-js/extension/develop
Browse files Browse the repository at this point in the history
Several performance improvements
  • Loading branch information
cezaraugusto authored Aug 9, 2024
2 parents b3b6f51 + b550a41 commit 49f0da3
Show file tree
Hide file tree
Showing 1,412 changed files with 24,456 additions and 35,540 deletions.
46 changes: 0 additions & 46 deletions .eslintignore

This file was deleted.

36 changes: 0 additions & 36 deletions .eslintrc.js

This file was deleted.

8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ yarn-error.log*
# vercel
.vercel

# swc
.swc

# Extension.js (beta)
packages/*/demo
packages/*/spec
browser-extension-test-data
TODO.yml
examples/*"
__TEST__
14 changes: 0 additions & 14 deletions .npmrc

This file was deleted.

15 changes: 0 additions & 15 deletions .prettierignore

This file was deleted.

11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "always"
}
25 changes: 0 additions & 25 deletions .prettierrc.js

This file was deleted.

25 changes: 25 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import js from '@eslint/js'
import globals from 'globals'

export default [
{
languageOptions: {
globals: {
...globals.browser,
...globals.webextensions,
...globals.node
}
}
},
js.configs.recommended,
{
ignores: [
'__TEST__',
'**/dist/',
'**/webpack.config.js',
'**/postcss.config.js',
'**/tailwind.config.js',
'**/stylelint.config.js'
]
}
]
25 changes: 25 additions & 0 deletions examples/action/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/dist

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# lock files
yarn.lock
package-lock.json
14 changes: 14 additions & 0 deletions examples/action/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"manifest_version": 3,
"version": "0.0.1",
"name": "action",
"description": "An Extension.js example.",
"author": "Cezar Augusto",
"action": {
"default_icon": {
"16": "test_16.png",
"48": "test_48.png",
"128": "public/icon.png"
}
}
}
23 changes: 23 additions & 0 deletions examples/action/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"private": true,
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/extension-js/extension.git",
"directory": "examples/action"
},
"name": "action",
"description": "An Extension.js example.",
"version": "0.0.1",
"author": {
"name": "Cezar Augusto",
"email": "boss@cezaraugusto.net",
"url": "https://cezaraugusto.com"
},
"keywords": [
"extension",
"browser-extension",
"web-extension",
"template"
]
}
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions examples/chatgpt/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXTENSION_OPENAI_API_KEY='My API Key'
25 changes: 25 additions & 0 deletions examples/chatgpt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/dist

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# lock files
yarn.lock
package-lock.json
91 changes: 91 additions & 0 deletions examples/chatgpt/action/ActionApp.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { useState } from 'react';
import OpenAI from "openai";
import chatgptLogo from '../images/chatgpt.png'
import extensionJsLogo from '../images/extension.png'

const openai = new OpenAI({
apiKey: process.env.EXTENSION_OPENAI_API_KEY,
dangerouslyAllowBrowser: true,
});

function ActionApp() {
const [messages, setMessages] = useState([
{
content: (
"Hello there! This is your ChatGPT extension sample, " +
"built with React, Tailwind.css, and DaisyUI. " +
"For it to work, create a .env file with your EXTENSION_OPENAI_API_KEY. " +
"You can get an API key from OpenAI's website."
),
role: "assistant"
},
{
content: "https://platform.openai.com/api-keys",
role: "assistant"
},
]);

const [isTyping, setIsTyping] = useState(false);


const handleSubmit = async (e) => {
e.preventDefault();

const newMessage = {
content: e.target[0].value,
role: "user"
}

const newMessages = [...messages, newMessage];

setMessages(newMessages);
setIsTyping(true);
e.target.reset();

const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [...newMessages],
});

setMessages([...newMessages, completion.choices[0].message]);
setIsTyping(false);
}

return (
<section className='container mx-auto p-5 fixed inset-0'>
<div className="w-full h-full flex flex-col">
<div className='flex-grow overflow-auto'>
{
messages.length && messages.map((msg, i) => {
return (
<div className={`chat ${msg.role === 'assistant' ? 'chat-start' : 'chat-end'}`} key={'chatKey' + i}>
<div className="chat-image avatar">
<div className="w-10 rounded-full">
<img src={msg.role === 'assistant' ? chatgptLogo : extensionJsLogo} />
</div>
</div>
<div className="chat-bubble">{msg.content}</div>
</div>
)
})
}
</div>

<form className="form-control items-center" onSubmit={(e) => handleSubmit(e)}>
<div className="input-group max-w-full w-[800px] relative flex items-center">
{isTyping && <small className='absolute -top-5 left-0.5 animate-pulse'>ChatGPT Extension is typing...</small>}

<input type="text" placeholder="Ask ChatGPT a question." className="input input-bordered flex-grow mr-2.5" required />
<button className="btn btn-square" type="submit">
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="currentColor" viewBox="0 0 16 16">
<path d="M15.854.146a.5.5 0 0 1 .11.54l-5.819 14.547a.75.75 0 0 1-1.329.124l-3.178-4.995L.643 7.184a.75.75 0 0 1 .124-1.33L15.314.037a.5.5 0 0 1 .54.11ZM6.636 10.07l2.761 4.338L14.13 2.576 6.636 10.07Zm6.787-8.201L1.591 6.602l4.339 2.76 7.494-7.493Z" />
</svg>
</button>
</div>
</form>
</div>
</section>
);
}

export default ActionApp;
13 changes: 13 additions & 0 deletions examples/chatgpt/action/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>ChatGPT Template</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this extension.</noscript>
<div id="root"></div>
</body>
<script src="./scripts.jsx"></script>
</html>
Loading

0 comments on commit 49f0da3

Please sign in to comment.