Merge pull request #248 from ttt246/feature/setting_extension_195
Browse files
Extension/src/pages/Background/index.js
CHANGED
|
@@ -8,10 +8,20 @@ chrome.runtime.onInstalled.addListener(function() {
|
|
| 8 |
});
|
| 9 |
|
| 10 |
// Handle the context menu item click
|
| 11 |
-
chrome.contextMenus.onClicked.addListener(function(info
|
| 12 |
if (info.menuItemId === 'risingExtension') {
|
| 13 |
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
| 14 |
chrome.tabs.sendMessage(tabs[0].id, { action: "open-modal" });
|
| 15 |
});
|
| 16 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
});
|
|
|
|
| 8 |
});
|
| 9 |
|
| 10 |
// Handle the context menu item click
|
| 11 |
+
chrome.contextMenus.onClicked.addListener(function(info) {
|
| 12 |
if (info.menuItemId === 'risingExtension') {
|
| 13 |
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
| 14 |
chrome.tabs.sendMessage(tabs[0].id, { action: "open-modal" });
|
| 15 |
});
|
| 16 |
}
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
// Handle the local storage get value
|
| 20 |
+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
| 21 |
+
if (request.method === 'getLocalStorage') {
|
| 22 |
+
chrome.storage.local.get(function(result) {
|
| 23 |
+
sendResponse({ data: result });
|
| 24 |
+
});
|
| 25 |
+
}
|
| 26 |
+
return true; // Important for asynchronous sendMessage
|
| 27 |
});
|
Extension/src/pages/Panel/Panel.css
CHANGED
|
@@ -4,8 +4,8 @@
|
|
| 4 |
}
|
| 5 |
|
| 6 |
[data-theme='dark'] {
|
| 7 |
-
--font-color: #
|
| 8 |
-
--theme-color: #
|
| 9 |
}
|
| 10 |
|
| 11 |
.main-layout {
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
[data-theme='dark'] {
|
| 7 |
+
--font-color: #e3e3e3;
|
| 8 |
+
--theme-color: #141414;
|
| 9 |
}
|
| 10 |
|
| 11 |
.main-layout {
|
Extension/src/pages/Panel/Panel.jsx
CHANGED
|
@@ -20,24 +20,9 @@ import {
|
|
| 20 |
} from '@ant-design/icons'
|
| 21 |
|
| 22 |
const {Footer, Content} = Layout;
|
| 23 |
-
const URL_BASE = 'https://ttt246-brain.hf.space/'
|
| 24 |
-
const URL_SEND_NOTIFICATION = URL_BASE + 'sendNotification'
|
| 25 |
-
const URL_BROWSER_ITEM = URL_BASE + 'browser/item'
|
| 26 |
-
const URL_ASK_WEBSITE = URL_BASE + 'browser/ask'
|
| 27 |
-
const URL_DELETE_RTD = URL_BASE + 'auto_task/delete'
|
| 28 |
|
| 29 |
let prompt = ""
|
| 30 |
-
|
| 31 |
-
"openai_key": "",
|
| 32 |
-
"pinecone_key": "",
|
| 33 |
-
"pinecone_env": "",
|
| 34 |
-
"firebase_key": "",
|
| 35 |
-
"token": "",
|
| 36 |
-
"uuid": "extension-uuid",
|
| 37 |
-
"settings": {
|
| 38 |
-
"temperature": 0.6
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
const logoUrl = Browser.runtime.getURL('logo_panel.png')
|
| 42 |
|
| 43 |
const Panel = () => {
|
|
@@ -45,6 +30,26 @@ const Panel = () => {
|
|
| 45 |
const [messages, setMessages] = useState([]);
|
| 46 |
const [isLoading, setLoadingStatus] = useState(false);
|
| 47 |
const chat_box = useRef(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
const handleQuestionUpdated = (event) => {
|
| 50 |
if (event.key === "Enter" && !isLoading) {
|
|
@@ -103,7 +108,7 @@ const Panel = () => {
|
|
| 103 |
}
|
| 104 |
setQuestion("")
|
| 105 |
|
| 106 |
-
sendRequest(params,
|
| 107 |
if (data.result === undefined || data.result == null) {
|
| 108 |
return
|
| 109 |
}
|
|
@@ -194,7 +199,7 @@ const Panel = () => {
|
|
| 194 |
"prompt": prompt,
|
| 195 |
"items": scrapeATags()
|
| 196 |
}
|
| 197 |
-
sendRequest(params,
|
| 198 |
window.open(data.result.content, '_blank', 'noreferrer')
|
| 199 |
}).catch(err => {
|
| 200 |
console.error((err))
|
|
@@ -207,7 +212,7 @@ const Panel = () => {
|
|
| 207 |
"prompt": prompt,
|
| 208 |
"items": scrapeWebsites()
|
| 209 |
}
|
| 210 |
-
sendRequest(params,
|
| 211 |
addMessage(data.result.content, false)
|
| 212 |
}).catch(err => {
|
| 213 |
console.error((err))
|
|
@@ -222,7 +227,7 @@ const Panel = () => {
|
|
| 222 |
}
|
| 223 |
}
|
| 224 |
|
| 225 |
-
sendRequest(params,
|
| 226 |
console.log(data.result)
|
| 227 |
}).catch(err => {
|
| 228 |
console.error(err)
|
|
|
|
| 20 |
} from '@ant-design/icons'
|
| 21 |
|
| 22 |
const {Footer, Content} = Layout;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
let prompt = ""
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
const logoUrl = Browser.runtime.getURL('logo_panel.png')
|
| 27 |
|
| 28 |
const Panel = () => {
|
|
|
|
| 30 |
const [messages, setMessages] = useState([]);
|
| 31 |
const [isLoading, setLoadingStatus] = useState(false);
|
| 32 |
const chat_box = useRef(null);
|
| 33 |
+
const [confs, setConfs] = useState({});
|
| 34 |
+
const [hostname, setHostname] = useState("")
|
| 35 |
+
|
| 36 |
+
useEffect(() => {
|
| 37 |
+
// Send a message to background script to get the storage value
|
| 38 |
+
chrome.runtime.sendMessage({ method: 'getLocalStorage' }, (response) => {
|
| 39 |
+
setHostname(response.data.host_name)
|
| 40 |
+
setConfs({
|
| 41 |
+
openai_key: response.data.openai_key,
|
| 42 |
+
pinecone_key: response.data.pinecone_key,
|
| 43 |
+
pinecone_env: response.data.pinecone_env,
|
| 44 |
+
firebase_key: btoa(response.data.firebase_key),
|
| 45 |
+
token: response.data.token,
|
| 46 |
+
uuid: response.data.uuid,
|
| 47 |
+
settings: {
|
| 48 |
+
temperature: response.data.temperature
|
| 49 |
+
}
|
| 50 |
+
});
|
| 51 |
+
});
|
| 52 |
+
}, []);
|
| 53 |
|
| 54 |
const handleQuestionUpdated = (event) => {
|
| 55 |
if (event.key === "Enter" && !isLoading) {
|
|
|
|
| 108 |
}
|
| 109 |
setQuestion("")
|
| 110 |
|
| 111 |
+
sendRequest(params, `${hostname}/sendNotification`).then(data => {
|
| 112 |
if (data.result === undefined || data.result == null) {
|
| 113 |
return
|
| 114 |
}
|
|
|
|
| 199 |
"prompt": prompt,
|
| 200 |
"items": scrapeATags()
|
| 201 |
}
|
| 202 |
+
sendRequest(params, `${hostname}/browser/item`).then(data => {
|
| 203 |
window.open(data.result.content, '_blank', 'noreferrer')
|
| 204 |
}).catch(err => {
|
| 205 |
console.error((err))
|
|
|
|
| 212 |
"prompt": prompt,
|
| 213 |
"items": scrapeWebsites()
|
| 214 |
}
|
| 215 |
+
sendRequest(params, `${hostname}/browser/ask`).then(data => {
|
| 216 |
addMessage(data.result.content, false)
|
| 217 |
}).catch(err => {
|
| 218 |
console.error((err))
|
|
|
|
| 227 |
}
|
| 228 |
}
|
| 229 |
|
| 230 |
+
sendRequest(params, `${hostname}/auto_task/delete`).then(data => {
|
| 231 |
console.log(data.result)
|
| 232 |
}).catch(err => {
|
| 233 |
console.error(err)
|
Extension/src/pages/Popup/Popup.css
CHANGED
|
@@ -1,3 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
}
|
|
|
|
| 1 |
+
[data-theme='light'] {
|
| 2 |
+
--font-color: #c9d1d9;
|
| 3 |
+
--theme-color: #333333;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
[data-theme='dark'] {
|
| 7 |
+
--font-color: #e3e3e3;
|
| 8 |
+
--theme-color: #141414;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.main-layout {
|
| 12 |
+
display: flex;
|
| 13 |
+
flex-direction: column;
|
| 14 |
+
height: 520px; /* Set the height of the layout to be 100% of the viewport */
|
| 15 |
+
width: 400px;
|
| 16 |
+
background-color: var(--theme-color);
|
| 17 |
+
color: var(--font-color);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.header {
|
| 21 |
+
height: 55px;
|
| 22 |
+
text-align: left;
|
| 23 |
+
padding-top: 5px;
|
| 24 |
+
padding-left: 10px;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.divider {
|
| 28 |
+
margin: 0;
|
| 29 |
+
background-color: grey;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.content {
|
| 33 |
+
padding: 10px;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.footer {
|
| 37 |
+
padding: 10px;
|
| 38 |
+
background-color: var(--theme-color);
|
| 39 |
+
display: flex;
|
| 40 |
+
justify-content: flex-end;
|
| 41 |
+
gap: 15px;
|
| 42 |
+
align-items: center;
|
| 43 |
+
color: grey;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.custom-input {
|
| 47 |
+
margin-bottom: 15px;
|
| 48 |
+
background-color: #202020;
|
| 49 |
+
color: white;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.ant-input-group-addon {
|
| 53 |
+
color: var(--font-color) !important;
|
| 54 |
+
width: 120px !important;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.ant-input {
|
| 58 |
+
background-color: #202020;
|
| 59 |
+
color: var(--font-color) !important;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.footer-btn {
|
| 63 |
+
background-color: inherit;
|
| 64 |
+
color: var(--font-color);
|
| 65 |
+
border: 0;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.footer-btn:hover {
|
| 69 |
+
border: 1px solid white !important;
|
| 70 |
+
color: var(--font-color) !important;
|
| 71 |
+
border-radius: 10px !important;
|
| 72 |
}
|
Extension/src/pages/Popup/Popup.jsx
CHANGED
|
@@ -1,12 +1,143 @@
|
|
| 1 |
-
import React from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import './Popup.css';
|
| 3 |
|
|
|
|
|
|
|
| 4 |
const Popup = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
return (
|
| 6 |
-
<
|
| 7 |
-
<
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
);
|
| 11 |
};
|
| 12 |
|
|
|
|
| 1 |
+
import React, {useState, useEffect} from 'react';
|
| 2 |
+
import {
|
| 3 |
+
Divider,
|
| 4 |
+
Input,
|
| 5 |
+
Layout,
|
| 6 |
+
Button,
|
| 7 |
+
} from 'antd';
|
| 8 |
import './Popup.css';
|
| 9 |
|
| 10 |
+
const {Footer, Content} = Layout;
|
| 11 |
+
|
| 12 |
const Popup = () => {
|
| 13 |
+
const [hostName,setHostName] = useState("")
|
| 14 |
+
const [openaiKey,setOpenaiKey] = useState("")
|
| 15 |
+
const [pineconeKey,setPineconeKey] = useState("")
|
| 16 |
+
const [pineconeEnv,setPineconeEnv] = useState("")
|
| 17 |
+
const [firebaseKey,setFirebaseKey] = useState("")
|
| 18 |
+
const [token,setToken] = useState("")
|
| 19 |
+
const [uuid,setUuid] = useState("")
|
| 20 |
+
const [temperature,setTemperature] = useState(0)
|
| 21 |
+
|
| 22 |
+
/// Check if the user's system is in dark mode
|
| 23 |
+
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
| 24 |
+
let isDarkMode = darkModeMediaQuery.matches;
|
| 25 |
+
|
| 26 |
+
useEffect(() => {
|
| 27 |
+
// Send a message to background script to get the storage value
|
| 28 |
+
chrome.runtime.sendMessage({ method: 'getLocalStorage' }, (response) => {
|
| 29 |
+
setOpenaiKey(response.data.openai_key);
|
| 30 |
+
setPineconeKey(response.data.pinecone_key)
|
| 31 |
+
setPineconeEnv(response.data.pinecone_env)
|
| 32 |
+
setFirebaseKey(response.data.firebase_key)
|
| 33 |
+
setToken(response.data.token)
|
| 34 |
+
setUuid(response.data.uuid)
|
| 35 |
+
setTemperature(response.data.temperature)
|
| 36 |
+
setHostName(response.data.host_name)
|
| 37 |
+
});
|
| 38 |
+
}, []);
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
const handleThemeChange = (e) => {
|
| 42 |
+
isDarkMode = e.matches;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
// Listen for changes in the theme data
|
| 46 |
+
darkModeMediaQuery.addEventListener('change', handleThemeChange);
|
| 47 |
+
|
| 48 |
+
const handleSave = () => {
|
| 49 |
+
chrome.storage.local.set({
|
| 50 |
+
"host_name": hostName,
|
| 51 |
+
"openai_key": openaiKey,
|
| 52 |
+
"pinecone_key": pineconeKey,
|
| 53 |
+
"pinecone_env": pineconeEnv,
|
| 54 |
+
"firebase_key": firebaseKey,
|
| 55 |
+
"token": token,
|
| 56 |
+
"uuid": uuid,
|
| 57 |
+
"temperature": temperature
|
| 58 |
+
}, () => {
|
| 59 |
+
console.log('Successfully set to local storage')
|
| 60 |
+
})
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
const handleCancel = () => {
|
| 64 |
+
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
return (
|
| 68 |
+
<Layout className="main-layout" data-theme={isDarkMode ? 'dark': 'light'}>
|
| 69 |
+
<div className="header">
|
| 70 |
+
<h1>Settings</h1>
|
| 71 |
+
</div>
|
| 72 |
+
<Divider className="divider"/>
|
| 73 |
+
<Content className="content">
|
| 74 |
+
<Input
|
| 75 |
+
name="hostName"
|
| 76 |
+
addonBefore="Host Name"
|
| 77 |
+
value={hostName}
|
| 78 |
+
className="custom-input"
|
| 79 |
+
onChange={(e) => setHostName(e.target.value)}
|
| 80 |
+
/>
|
| 81 |
+
<Input
|
| 82 |
+
name="openaiKey"
|
| 83 |
+
addonBefore="OpenAI Key"
|
| 84 |
+
value={openaiKey}
|
| 85 |
+
className="custom-input"
|
| 86 |
+
onChange={(e) => setOpenaiKey(e.target.value)}
|
| 87 |
+
/>
|
| 88 |
+
<Input
|
| 89 |
+
name="pineconeKey"
|
| 90 |
+
addonBefore="Pinecone Key"
|
| 91 |
+
value={pineconeKey}
|
| 92 |
+
className="custom-input"
|
| 93 |
+
onChange={(e) => setPineconeKey(e.target.value)}
|
| 94 |
+
/>
|
| 95 |
+
<Input
|
| 96 |
+
name="pineconeEnv"
|
| 97 |
+
addonBefore="Pinecone Env"
|
| 98 |
+
value={pineconeEnv}
|
| 99 |
+
className="custom-input"
|
| 100 |
+
onChange={(e) => setPineconeEnv(e.target.value)}
|
| 101 |
+
/>
|
| 102 |
+
<Input
|
| 103 |
+
name="firebaseKey"
|
| 104 |
+
addonBefore="Firebase Key"
|
| 105 |
+
value={firebaseKey}
|
| 106 |
+
className="custom-input"
|
| 107 |
+
onChange={(e) => setFirebaseKey(e.target.value)}
|
| 108 |
+
/>
|
| 109 |
+
<Input
|
| 110 |
+
name="token"
|
| 111 |
+
addonBefore="Token"
|
| 112 |
+
value={token}
|
| 113 |
+
className="custom-input"
|
| 114 |
+
onChange={(e) => setToken(e.target.value)}
|
| 115 |
+
/>
|
| 116 |
+
<Input
|
| 117 |
+
name="uuid"
|
| 118 |
+
addonBefore="UUID"
|
| 119 |
+
value={uuid}
|
| 120 |
+
className="custom-input"
|
| 121 |
+
onChange={(e) => setUuid(e.target.value)}
|
| 122 |
+
/>
|
| 123 |
+
<Input
|
| 124 |
+
name="temperature"
|
| 125 |
+
addonBefore="Temperature"
|
| 126 |
+
type="number"
|
| 127 |
+
value={temperature}
|
| 128 |
+
step="0.1"
|
| 129 |
+
min="0"
|
| 130 |
+
max="1"
|
| 131 |
+
className="custom-input"
|
| 132 |
+
onChange={(e) => setTemperature(e.target.value)}
|
| 133 |
+
/>
|
| 134 |
+
</Content>
|
| 135 |
+
<Divider className="divider"/>
|
| 136 |
+
<Footer className="footer">
|
| 137 |
+
<Button className="footer-btn" onClick={handleSave}>Save</Button>
|
| 138 |
+
<Button className="footer-btn" onClick={handleCancel}>Cancel</Button>
|
| 139 |
+
</Footer>
|
| 140 |
+
</Layout>
|
| 141 |
);
|
| 142 |
};
|
| 143 |
|
Extension/src/pages/Popup/index.css
CHANGED
|
@@ -1,17 +1,3 @@
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
height: 100px;
|
| 4 |
-
margin: 0;
|
| 5 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
| 6 |
-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
| 7 |
-
sans-serif;
|
| 8 |
-
-webkit-font-smoothing: antialiased;
|
| 9 |
-
-moz-osx-font-smoothing: grayscale;
|
| 10 |
-
|
| 11 |
-
position: relative;
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
code {
|
| 15 |
-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
| 16 |
-
monospace;
|
| 17 |
}
|
|
|
|
| 1 |
body {
|
| 2 |
+
margin: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
}
|