forked from iSegaro/Gemini-Translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
64 lines (57 loc) · 2.23 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// config.js
const CONFIG = {
USE_MOCK: false,
API_URL:
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-lite-preview-02-05:generateContent",
PROMPT_ENGLISH:
"Please translate the following text into English, preserving the sentence structure (like new lines) and displaying only the output:",
PROMPT_PERSIAN:
"لطفاً متن زیر را به فارسی ترجمه کنید، ساختار جمله (مانند خطوط جدید) را حفظ کرده و فقط خروجی را نمایش دهید:",
HIGHLIGHT_STYLE: "2px solid red",
DEBUG_TRANSLATED_ENGLISH: "This is a mock translation to English.",
DEBUG_TRANSLATED_PERSIAN: "این یک ترجمه آزمایشی به فارسی است.",
DEBUG_TRANSLATED_ENGLISH_With_NewLine:
"This is a mock \ntranslation to English with \nnew lines.",
DEBUG_TRANSLATED_PERSIAN_With_NewLine:
"این یک ترجمه آزمایشی \nبرای ترجمه به فارسی \nبا خطوط جدید است.",
HIGHTLIH_NEW_ELEMETN_RED: "2px solid red",
TRANSLATION_ICON_TITLE: "Translate Text",
ICON_TRANSLATION: "🌐",
ICON_ERROR: "❌ ",
ICON_SECCESS: "✅ ",
ICON_STATUS: "🔄 ",
ICON_WARNING: "⚠️ ",
ICON_INFO: "💠 ",
};
// Helper function to retrieve the API_KEY from chrome.storage
async function getApiKeyAsync() {
return new Promise((resolve, reject) => {
try {
if (!isExtensionContextValid()) {
reject(new Error("Extension context invalid"));
return;
}
// Check if chrome.storage exists
if (!chrome?.storage?.sync) {
throw new Error("Error: The extension has not loaded correctly");
}
chrome.storage.sync.get(["apiKey"], (result) => {
if (chrome.runtime.lastError) {
reject(
new Error(`System error: ${chrome.runtime.lastError.message}`)
);
return;
}
if (!result.apiKey) {
reject(
new Error("Please enter the API key in the extension settings")
);
return;
}
resolve(result.apiKey);
});
} catch (error) {
reject(new Error(`Access error: ${error.message}`));
}
});
}