adding password
parent
7021c0b1eb
commit
e9a5d6bbf9
|
@ -22,6 +22,10 @@
|
|||
URL сервера:
|
||||
<input type="text" id="server-url" placeholder="Введите URL сервера" />
|
||||
</label>
|
||||
<label>
|
||||
Пароль:
|
||||
<input type="text" id="password" placeholder="Введите пароль" />
|
||||
</label>
|
||||
<button type="submit">Сохранить</button>
|
||||
</form>
|
||||
<p id="status" style="color: green;"></p>
|
||||
|
|
11
options.js
11
options.js
|
@ -1,13 +1,14 @@
|
|||
function saveOptions(event) {
|
||||
event.preventDefault();
|
||||
const serverUrl = document.querySelector("#server-url").value;
|
||||
const password = document.querySelector("#password").value;
|
||||
|
||||
if (serverUrl.trim() === "") {
|
||||
alert("URL сервера не может быть пустым!");
|
||||
if (serverUrl.trim() === "" || password.trim() === "") {
|
||||
alert("URL сервера и пароль не могут быть пустыми!");
|
||||
return;
|
||||
}
|
||||
|
||||
browser.storage.sync.set({ serverUrl }).then(() => {
|
||||
browser.storage.sync.set({ serverUrl, password }).then(() => {
|
||||
const status = document.querySelector("#status");
|
||||
status.textContent = "Настройки сохранены!";
|
||||
setTimeout(() => (status.textContent = ""), 2000);
|
||||
|
@ -15,9 +16,11 @@ function saveOptions(event) {
|
|||
}
|
||||
|
||||
function restoreOptions() {
|
||||
browser.storage.sync.get("serverUrl").then((result) => {
|
||||
browser.storage.sync.get(["serverUrl", "password"]).then((result) => {
|
||||
const serverUrl = result.serverUrl || "http://localhost:5000/submit";
|
||||
const password = result.password || "";
|
||||
document.querySelector("#server-url").value = serverUrl;
|
||||
document.querySelector("#password").value = password;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
let serverUrl = "http://localhost:5000/submit";
|
||||
let password = "";
|
||||
|
||||
function loadServerUrl() {
|
||||
return browser.storage.sync.get("serverUrl").then((result) => {
|
||||
function loadSettings() {
|
||||
return browser.storage.sync.get(["serverUrl", "password"]).then((result) => {
|
||||
if (result.serverUrl) {
|
||||
serverUrl = result.serverUrl;
|
||||
console.log("URL сервера загружен из настроек:", serverUrl);
|
||||
}
|
||||
if (result.password) {
|
||||
password = result.password;
|
||||
console.log("Пароль загружен из настроек.");
|
||||
} else {
|
||||
return fetch(browser.runtime.getURL("config.json"))
|
||||
.then(response => {
|
||||
|
@ -15,6 +20,7 @@ function loadServerUrl() {
|
|||
})
|
||||
.then(config => {
|
||||
serverUrl = config.FLASK_SERVER_URL;
|
||||
password = config.PASSWORD || password;
|
||||
console.log("URL сервера успешно загружен:", serverUrl);
|
||||
});
|
||||
}
|
||||
|
@ -23,7 +29,7 @@ function loadServerUrl() {
|
|||
});
|
||||
}
|
||||
|
||||
loadServerUrl();
|
||||
loadSettings();
|
||||
|
||||
|
||||
let clientId = null;
|
||||
|
@ -64,14 +70,17 @@ function createEventJSON(eventType, data) {
|
|||
|
||||
|
||||
async function sendDataToServer(eventData) {
|
||||
if (!serverUrl) {
|
||||
console.error("URL сервера не задан. Проверьте настройки.");
|
||||
if (!serverUrl || !password) {
|
||||
console.error("URL сервера или пароль не заданы. Проверьте настройки.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(serverUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Password': password,
|
||||
},
|
||||
body: JSON.stringify(eventData),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue