Commit ·
6b64675
1
Parent(s): 688f0b9
feature(#195): implement setting page
Browse files
Extension/src/pages/Background/index.js
CHANGED
|
@@ -20,7 +20,6 @@ chrome.contextMenus.onClicked.addListener(function(info) {
|
|
| 20 |
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
| 21 |
if (request.method === 'getLocalStorage') {
|
| 22 |
chrome.storage.local.get(function(result) {
|
| 23 |
-
console.log('background result--------->', result)
|
| 24 |
sendResponse({ data: result });
|
| 25 |
});
|
| 26 |
}
|
|
|
|
| 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 |
}
|
Extension/src/pages/Panel/Panel.jsx
CHANGED
|
@@ -20,11 +20,6 @@ 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 |
|
|
@@ -35,12 +30,24 @@ const Panel = () => {
|
|
| 35 |
const [messages, setMessages] = useState([]);
|
| 36 |
const [isLoading, setLoadingStatus] = useState(false);
|
| 37 |
const chat_box = useRef(null);
|
| 38 |
-
const [confs, setConfs] = useState(
|
|
|
|
| 39 |
|
| 40 |
useEffect(() => {
|
| 41 |
// Send a message to background script to get the storage value
|
| 42 |
chrome.runtime.sendMessage({ method: 'getLocalStorage' }, (response) => {
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
});
|
| 45 |
}, []);
|
| 46 |
|
|
@@ -101,7 +108,7 @@ const Panel = () => {
|
|
| 101 |
}
|
| 102 |
setQuestion("")
|
| 103 |
|
| 104 |
-
sendRequest(params,
|
| 105 |
if (data.result === undefined || data.result == null) {
|
| 106 |
return
|
| 107 |
}
|
|
@@ -192,7 +199,7 @@ const Panel = () => {
|
|
| 192 |
"prompt": prompt,
|
| 193 |
"items": scrapeATags()
|
| 194 |
}
|
| 195 |
-
sendRequest(params,
|
| 196 |
window.open(data.result.content, '_blank', 'noreferrer')
|
| 197 |
}).catch(err => {
|
| 198 |
console.error((err))
|
|
@@ -205,7 +212,7 @@ const Panel = () => {
|
|
| 205 |
"prompt": prompt,
|
| 206 |
"items": scrapeWebsites()
|
| 207 |
}
|
| 208 |
-
sendRequest(params,
|
| 209 |
addMessage(data.result.content, false)
|
| 210 |
}).catch(err => {
|
| 211 |
console.error((err))
|
|
@@ -220,7 +227,7 @@ const Panel = () => {
|
|
| 220 |
}
|
| 221 |
}
|
| 222 |
|
| 223 |
-
sendRequest(params,
|
| 224 |
console.log(data.result)
|
| 225 |
}).catch(err => {
|
| 226 |
console.error(err)
|
|
|
|
| 20 |
} from '@ant-design/icons'
|
| 21 |
|
| 22 |
const {Footer, Content} = Layout;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
let prompt = ""
|
| 25 |
|
|
|
|
| 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: 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 |
|
|
|
|
| 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
|
@@ -11,7 +11,7 @@
|
|
| 11 |
.main-layout {
|
| 12 |
display: flex;
|
| 13 |
flex-direction: column;
|
| 14 |
-
height:
|
| 15 |
width: 400px;
|
| 16 |
background-color: var(--theme-color);
|
| 17 |
color: var(--font-color);
|
|
@@ -69,4 +69,29 @@
|
|
| 69 |
border: 1px solid white !important;
|
| 70 |
color: var(--font-color) !important;
|
| 71 |
border-radius: 10px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
|
|
|
| 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);
|
|
|
|
| 69 |
border: 1px solid white !important;
|
| 70 |
color: var(--font-color) !important;
|
| 71 |
border-radius: 10px !important;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.custom-label {
|
| 75 |
+
width: 120px;
|
| 76 |
+
background-color: #202020 !important;
|
| 77 |
+
height: 33px;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.upload-file {
|
| 81 |
+
display: flex;
|
| 82 |
+
gap: 10px;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.ant-btn {
|
| 86 |
+
background-color: inherit;
|
| 87 |
+
border: 0;
|
| 88 |
+
color: var(--font-color);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.ant-upload-list-item-name {
|
| 92 |
+
color: var(--font-color);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.anticon {
|
| 96 |
+
color: var(--font-color) !important;
|
| 97 |
}
|
Extension/src/pages/Popup/Popup.jsx
CHANGED
|
@@ -1,9 +1,13 @@
|
|
| 1 |
-
import React, {useState} from 'react';
|
|
|
|
| 2 |
Divider,
|
| 3 |
Input,
|
| 4 |
Layout,
|
| 5 |
-
Button
|
|
|
|
|
|
|
| 6 |
} from 'antd';
|
|
|
|
| 7 |
import './Popup.css';
|
| 8 |
|
| 9 |
const {Footer, Content} = Layout;
|
|
@@ -16,11 +20,59 @@ const Popup = () => {
|
|
| 16 |
const [token,setToken] = useState("")
|
| 17 |
const [uuid,setUuid] = useState("")
|
| 18 |
const [temperature,setTemperature] = useState(0)
|
|
|
|
| 19 |
|
| 20 |
/// Check if the user's system is in dark mode
|
| 21 |
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
| 22 |
let isDarkMode = darkModeMediaQuery.matches;
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
const handleThemeChange = (e) => {
|
| 25 |
isDarkMode = e.matches;
|
| 26 |
};
|
|
@@ -48,7 +100,6 @@ const Popup = () => {
|
|
| 48 |
}
|
| 49 |
|
| 50 |
return (
|
| 51 |
-
|
| 52 |
<Layout className="main-layout" data-theme={isDarkMode ? 'dark': 'light'}>
|
| 53 |
<div className="header">
|
| 54 |
<h1>Settings</h1>
|
|
@@ -83,13 +134,6 @@ const Popup = () => {
|
|
| 83 |
className="custom-input"
|
| 84 |
onChange={(e) => setPineconeEnv(e.target.value)}
|
| 85 |
/>
|
| 86 |
-
<Input
|
| 87 |
-
name="firebaseKey"
|
| 88 |
-
addonBefore="Firebase Key"
|
| 89 |
-
value={firebaseKey}
|
| 90 |
-
className="custom-input"
|
| 91 |
-
onChange={(e) => setFirebaseKey(e.target.value)}
|
| 92 |
-
/>
|
| 93 |
<Input
|
| 94 |
name="token"
|
| 95 |
addonBefore="Token"
|
|
@@ -115,6 +159,12 @@ const Popup = () => {
|
|
| 115 |
className="custom-input"
|
| 116 |
onChange={(e) => setTemperature(e.target.value)}
|
| 117 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
</Content>
|
| 119 |
<Divider className="divider"/>
|
| 120 |
<Footer className="footer">
|
|
|
|
| 1 |
+
import React, {useState, useEffect} from 'react';
|
| 2 |
+
import {
|
| 3 |
Divider,
|
| 4 |
Input,
|
| 5 |
Layout,
|
| 6 |
+
Button,
|
| 7 |
+
Upload,
|
| 8 |
+
message
|
| 9 |
} from 'antd';
|
| 10 |
+
import { UploadOutlined } from '@ant-design/icons'
|
| 11 |
import './Popup.css';
|
| 12 |
|
| 13 |
const {Footer, Content} = Layout;
|
|
|
|
| 20 |
const [token,setToken] = useState("")
|
| 21 |
const [uuid,setUuid] = useState("")
|
| 22 |
const [temperature,setTemperature] = useState(0)
|
| 23 |
+
const [firebaseCred, setFirebaseCred] = useState([])
|
| 24 |
|
| 25 |
/// Check if the user's system is in dark mode
|
| 26 |
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
| 27 |
let isDarkMode = darkModeMediaQuery.matches;
|
| 28 |
|
| 29 |
+
useEffect(() => {
|
| 30 |
+
// Send a message to background script to get the storage value
|
| 31 |
+
chrome.runtime.sendMessage({ method: 'getLocalStorage' }, (response) => {
|
| 32 |
+
setOpenaiKey(response.data.openai_key);
|
| 33 |
+
setPineconeKey(response.data.pinecone_key)
|
| 34 |
+
setPineconeEnv(response.data.pinecone_env)
|
| 35 |
+
setFirebaseKey(response.data.firebase_key)
|
| 36 |
+
setToken(response.data.token)
|
| 37 |
+
setUuid(response.data.uuid)
|
| 38 |
+
setTemperature(response.data.temperature)
|
| 39 |
+
setHostName(response.data.host_name)
|
| 40 |
+
});
|
| 41 |
+
}, []);
|
| 42 |
+
|
| 43 |
+
const getBase64 = (file, callback) => {
|
| 44 |
+
const reader = new FileReader();
|
| 45 |
+
reader.readAsDataURL(file);
|
| 46 |
+
reader.onload = () => callback(reader.result);
|
| 47 |
+
reader.onerror = error => {
|
| 48 |
+
message.error('File reading was failed.', error);
|
| 49 |
+
};
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
const handleUploadChange = (info) => {
|
| 53 |
+
let fileList = [...info.fileList];
|
| 54 |
+
|
| 55 |
+
// Remove non-json and old files
|
| 56 |
+
fileList = fileList.filter(file => {
|
| 57 |
+
if (file.type.includes('json')) {
|
| 58 |
+
if (file.originFileObj) {
|
| 59 |
+
getBase64(file.originFileObj, result =>{
|
| 60 |
+
const firebaseCredInfo = result.split(',')
|
| 61 |
+
setFirebaseKey(firebaseCredInfo[1])
|
| 62 |
+
});
|
| 63 |
+
}
|
| 64 |
+
return true;
|
| 65 |
+
} else {
|
| 66 |
+
message.error(`${file.name} is not an json file.`);
|
| 67 |
+
return false;
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
fileList = fileList.slice(-1);
|
| 71 |
+
|
| 72 |
+
setFirebaseCred([...fileList]);
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
|
| 76 |
const handleThemeChange = (e) => {
|
| 77 |
isDarkMode = e.matches;
|
| 78 |
};
|
|
|
|
| 100 |
}
|
| 101 |
|
| 102 |
return (
|
|
|
|
| 103 |
<Layout className="main-layout" data-theme={isDarkMode ? 'dark': 'light'}>
|
| 104 |
<div className="header">
|
| 105 |
<h1>Settings</h1>
|
|
|
|
| 134 |
className="custom-input"
|
| 135 |
onChange={(e) => setPineconeEnv(e.target.value)}
|
| 136 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
<Input
|
| 138 |
name="token"
|
| 139 |
addonBefore="Token"
|
|
|
|
| 159 |
className="custom-input"
|
| 160 |
onChange={(e) => setTemperature(e.target.value)}
|
| 161 |
/>
|
| 162 |
+
<div className="upload-file">
|
| 163 |
+
<Input className="custom-label" value="Firebase Key" disabled />
|
| 164 |
+
<Upload fileList={firebaseCred} onChange={(info) =>handleUploadChange(info)}>
|
| 165 |
+
<Button icon={<UploadOutlined />}>Upload</Button>
|
| 166 |
+
</Upload>
|
| 167 |
+
</div>
|
| 168 |
</Content>
|
| 169 |
<Divider className="divider"/>
|
| 170 |
<Footer className="footer">
|