vlff李飞飞 commited on
Commit
eb10065
1 Parent(s): 92bc940

优化chrome 插件

Browse files
chrome_agent/_locales/de/messages.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "optionsTitle": {
3
+ "message": "Einstellungen",
4
+ "description": "Titel der Einstellungen-Seite"
5
+ },
6
+ "apiTitle": {
7
+ "message": "Gib deinen OpenAI API Schlüssel ein, um die Erweiterung zu nutzen:",
8
+ "description": "Titel der API-Schlüssel-Eingabe"
9
+ },
10
+ "apiModelTitle": {
11
+ "message": "Wähle ein API Model aus:",
12
+ "description": "Titel der API-Model-Auswahl"
13
+ },
14
+ "lastMessagesTitle": {
15
+ "message": "Letzte Nachrichten",
16
+ "description": "Titel der letzten Nachrichten"
17
+ },
18
+ "optionsInputPlaceholder": {
19
+ "message": "Hier Access Schlüssel eingeben",
20
+ "description": "Platzhalter für API Schlüssel Eingabe"
21
+ },
22
+ "optionsAccessTokenNote": {
23
+ "message": "Dein Access Schlüssel wird nur lokal gespeichert und nicht an Dritte weitergegeben.",
24
+ "description": "Hinweis zum API Schlüssel"
25
+ },
26
+ "optionsSaveButtonText": {
27
+ "message": "Speichern",
28
+ "description": "Text für den Button zum Speichern des Access Schlüssels"
29
+ },
30
+ "optionsDeleteButtonText": {
31
+ "message": "API Schlüssel löschen",
32
+ "description": "Text für den Button zum Löschen des Access Schlüssels"
33
+ }
34
+ }
chrome_agent/_locales/en/messages.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "optionsTitle": {
3
+ "message": "Options",
4
+ "description": "Title of the options page"
5
+ },
6
+ "apiTitle": {
7
+ "message": "Enter your Access token below to get started.",
8
+ "description": "Title of the Access-token section"
9
+ },
10
+ "apiModelTitle": {
11
+ "message": "Choose API-Model:",
12
+ "description": "Title of the API-Model section"
13
+ },
14
+ "lastMessagesTitle": {
15
+ "message": "Last Messages:",
16
+ "description": "Title of the last messages section"
17
+ },
18
+ "optionsInputPlaceholder": {
19
+ "message": "Enter your Access token here",
20
+ "description": "Placeholder of the Access-Token input"
21
+ },
22
+ "optionsAccessTokenNote": {
23
+ "message": "Note: Your Access token will only be stored locally on your computer and nowhere else.",
24
+ "description": "Note about the Access-Token"
25
+ },
26
+ "optionsSaveButtonText": {
27
+ "message": "Save",
28
+ "description": "Text of the save button"
29
+ },
30
+ "optionsDeleteButtonText": {
31
+ "message": "Delete Access token",
32
+ "description": "Text of the delete button"
33
+ }
34
+ }
chrome_agent/background.js CHANGED
@@ -66,3 +66,16 @@ chrome.runtime.onMessage.addListener(async (msg, sender) => {
66
  // }
67
  // }
68
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  // }
67
  // }
68
  });
69
+
70
+ // Listen for when the extension is installed
71
+ chrome.runtime.onInstalled.addListener(function () {
72
+ // Set default API model
73
+ let defaultModel = "gpt-35-turbo";
74
+ chrome.storage.local.set({ apiModel: defaultModel });
75
+
76
+ // Set empty chat history
77
+ chrome.storage.local.set({ chatHistory: [] });
78
+
79
+ // Open the options page
80
+ chrome.runtime.openOptionsPage();
81
+ });
chrome_agent/manifest.json CHANGED
@@ -3,13 +3,13 @@
3
  "description" : "An Extension Driven by LLM",
4
  "version": "1.0",
5
  "manifest_version": 3,
6
-
7
  "background": {
8
  "service_worker": "background.js"
9
  },
10
-
11
  "action": {
12
- "default_popup": "src/popup.html",
13
  "default_icon": "img/popup.png",
14
  "default_title": "BrowserLLMBB"
15
  },
@@ -33,8 +33,8 @@
33
  "content_scripts": [
34
  {
35
  "js": [
36
- "src/content.js",
37
- "src/md5.js"
38
  ],
39
  "matches": [
40
  "https://www.jianshu.com/p/*",
 
3
  "description" : "An Extension Driven by LLM",
4
  "version": "1.0",
5
  "manifest_version": 3,
6
+ "default_locale": "en",
7
  "background": {
8
  "service_worker": "background.js"
9
  },
10
+ "options_page": "options/options.html",
11
  "action": {
12
+ "default_popup": "popup/popup.html",
13
  "default_icon": "img/popup.png",
14
  "default_title": "BrowserLLMBB"
15
  },
 
33
  "content_scripts": [
34
  {
35
  "js": [
36
+ "popup/content.js",
37
+ "popup/md5.js"
38
  ],
39
  "matches": [
40
  "https://www.jianshu.com/p/*",
chrome_agent/options/options.css ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: 'Arial', sans-serif;
3
+ background-color: #343541;
4
+ margin: 0;
5
+ display: flex;
6
+ justify-content: center;
7
+ align-items: center;
8
+ height: 100vh;
9
+ }
10
+
11
+ * {
12
+ box-sizing: border-box;
13
+ }
14
+
15
+ .container {
16
+ display: flex;
17
+ flex-direction: column;
18
+ text-align: center;
19
+ background-color: #fff;
20
+ padding: 20px;
21
+ border-radius: 8px;
22
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
23
+ }
24
+
25
+ label {
26
+ display: block;
27
+ margin-bottom: 10px;
28
+ }
29
+
30
+ #input-container {
31
+ display: flex;
32
+ flex-direction: row;
33
+ gap: 10px;
34
+ }
35
+
36
+ input {
37
+ width: 100%;
38
+ padding: 8px;
39
+ box-sizing: border-box;
40
+ }
41
+
42
+ button {
43
+ background-color: #4caf50;
44
+ color: #fff;
45
+ padding: 10px 15px;
46
+ border: none;
47
+ border-radius: 4px;
48
+ cursor: pointer;
49
+ }
50
+
51
+ button:hover {
52
+ background-color: #45a049;
53
+ }
54
+
55
+ button i {
56
+ margin-right: 5px;
57
+ }
58
+
59
+ #save-button {
60
+ display: flex;
61
+ align-items: center;
62
+ }
63
+
64
+ #delete-container {
65
+ display: flex;
66
+ flex-direction: row;
67
+ justify-content: space-between;
68
+ gap: 10px;
69
+ margin-top: 10px;
70
+ }
71
+
72
+ #delete-button {
73
+ background-color: #f44336;
74
+ padding: 10px 15px;
75
+ }
76
+
77
+ #delete-button:hover {
78
+ background-color: #d32f2f;
79
+ }
80
+
81
+ #status-message {
82
+ margin-top: 10px;
83
+ color: #333;
84
+ }
chrome_agent/options/options.html ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Options</title>
8
+ <link rel="stylesheet" href="options.css">
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
10
+ </head>
11
+
12
+ <body>
13
+ <div class="container">
14
+ <h1 id="optionsTitle"></h1>
15
+ <p id="apiTitle"></p>
16
+ <div id="input-container">
17
+ <input type="text" id="accessToken">
18
+ <button id="save-button" title="Save Access token">
19
+ <i class="fa fa-save"></i>
20
+ <span id="save-button-text"></span>
21
+ </button>
22
+ </div>
23
+ <div id="delete-container">
24
+ <button id="delete-button" title="Delete Access token">
25
+ <i class="fa fa-trash"></i>
26
+ <span id="delete-button-text"></span>
27
+ </button>
28
+ <p id="status-message"></p>
29
+ </div>
30
+ <p id="access-token-note" class="note"></p>
31
+ </div>
32
+ <script src="options.js"></script>
33
+ </body>
34
+
35
+ </html>
chrome_agent/options/options.js ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', function () {
2
+ // Fetch the elements
3
+ const accessTokenInput = document.getElementById('accessToken');
4
+ const saveButton = document.getElementById('save-button');
5
+ const deleteButton = document.getElementById('delete-button');
6
+ const statusMessage = document.getElementById('status-message');
7
+
8
+ // Retrieve the saved Access token from local storage
9
+ chrome.storage.local.get(['access_token'], function (result) {
10
+ if (result.access_token) {
11
+ accessTokenInput.value = result.access_token;
12
+ }
13
+ });
14
+
15
+ // Add event listener to the save button
16
+ saveButton.addEventListener('click', function () {
17
+ // Get the entered Access token
18
+ const accessToken = accessTokenInput.value.trim();
19
+
20
+ // Check if the Access token is not empty
21
+ if (accessToken !== '' && accessToken.length > 1 && accessToken.length < 100) {
22
+ // Save the Access token to local storage
23
+ chrome.storage.local.set({ access_token: accessToken }, function () {
24
+ // Update the status message
25
+ statusMessage.textContent = 'Access token saved successfully!';
26
+ setTimeout(function () {
27
+ // Clear the status message after 2 seconds
28
+ statusMessage.textContent = '';
29
+ }, 2000);
30
+ });
31
+ } else {
32
+ // Display an error message if the Access token is empty
33
+ statusMessage.textContent = 'Please enter a valid Access token.';
34
+ }
35
+ });
36
+
37
+ // Add event listener to the delete button
38
+ deleteButton.addEventListener('click', function () {
39
+ // Remove the Access token from local storage
40
+ chrome.storage.local.remove(['access_token'], function () {
41
+ // Update the status message
42
+ statusMessage.textContent = 'Access token deleted successfully!';
43
+ accessTokenInput.value = '';
44
+ setTimeout(function () {
45
+ // Clear the status message after 2 seconds
46
+ statusMessage.textContent = '';
47
+ }, 2000);
48
+ });
49
+ });
50
+ });
51
+
52
+ // localize title optionsTitle
53
+ document.getElementById('optionsTitle').innerHTML = chrome.i18n.getMessage("optionsTitle");
54
+
55
+ // localize api title apiTitle
56
+ document.getElementById('apiTitle').innerHTML = chrome.i18n.getMessage("apiTitle");
57
+
58
+ // localize the Access token input placeholder
59
+ document.getElementById('accessToken').placeholder = chrome.i18n.getMessage("optionsInputPlaceholder");
60
+
61
+ // localize access-token-note
62
+ document.getElementById('access-token-note').innerHTML = chrome.i18n.getMessage("optionsAccessTokenNote");
63
+
64
+ // localize save button text
65
+ document.getElementById('save-button-text').innerText = chrome.i18n.getMessage("optionsSaveButtonText");
66
+
67
+ // localize delete button text
68
+ document.getElementById('delete-button-text').innerText = chrome.i18n.getMessage("optionsDeleteButtonText");
69
+
chrome_agent/{src → popup}/content.js RENAMED
File without changes
chrome_agent/{src → popup}/md5.js RENAMED
File without changes
chrome_agent/{src → popup}/popup.html RENAMED
@@ -112,10 +112,11 @@
112
  <!-- <iframe src=$popup_url style="height: 550px"></iframe>-->
113
  <div id="iframe_area" style="height: 570px"></div>
114
 
 
115
  <h3>Customize Token:</h3>
116
  <input type="text" id="access_token" name="access_token" class="input-text" placeholder="input and chick change button, then reopen this">
117
  <button id="set_access_token" class="upload_btn">Change</button>
118
-
119
  <script src="popup.js"></script>
120
  <script src="md5.js"></script>
121
  </body>
 
112
  <!-- <iframe src=$popup_url style="height: 550px"></iframe>-->
113
  <div id="iframe_area" style="height: 570px"></div>
114
 
115
+ <div style="display:none">
116
  <h3>Customize Token:</h3>
117
  <input type="text" id="access_token" name="access_token" class="input-text" placeholder="input and chick change button, then reopen this">
118
  <button id="set_access_token" class="upload_btn">Change</button>
119
+ </div>
120
  <script src="popup.js"></script>
121
  <script src="md5.js"></script>
122
  </body>
chrome_agent/{src → popup}/popup.js RENAMED
File without changes