diff --git a/manifest.json b/manifest.json index 6ab8d53..1bad8cd 100644 --- a/manifest.json +++ b/manifest.json @@ -24,16 +24,6 @@ "extension_pages": "script-src 'self'; object-src 'self'; connect-src 'self' http://localhost:5000" }, - "web_accessible_resources": [ - { - "resources": [ - "update_id.html", - "update_id.js" - ], - "matches": [""] - } - ], - "content_scripts": [ { "matches": ["*://*/*"], diff --git a/options.html b/options.html index 69288a3..0168652 100644 --- a/options.html +++ b/options.html @@ -29,6 +29,7 @@

+

\ No newline at end of file diff --git a/options.js b/options.js index f31240e..e0f2d1e 100644 --- a/options.js +++ b/options.js @@ -49,6 +49,7 @@ function restoreOptions() { } else { updateFormFields(result); } + checkClientIdFromURL(); }); } } @@ -68,5 +69,46 @@ function showStatus(message, isError = false) { }, 2000); } +function getQueryParams() { + const params = new URLSearchParams(window.location.search); + if (params.has("clientId")) { + return params.get("clientId").trim(); + } + return null; +} + +function updateClientId(newId) { + return new Promise((resolve, reject) => { + if (!newId) return reject("Пустой clientId"); + + browserAPI.storage.local.set({ clientId: newId }, () => { + if (chrome.runtime?.lastError) { + reject(chrome.runtime.lastError); + } else { + resolve(newId); + } + }); + }); +} + + +async function checkClientIdFromURL() { + const newId = getQueryParams(); + const msgBox = document.getElementById("client-id-status"); + + if (!newId) return; + + try { + const saved = await updateClientId(newId); + msgBox.textContent = `clientId обновлён: ${saved}`; + msgBox.style.color = "blue"; + console.log("[OPTIONS] clientId обновлён через URL:", saved); + } catch (err) { + msgBox.textContent = "Ошибка: " + err; + msgBox.style.color = "red"; + console.error("[OPTIONS] Ошибка обновления clientId:", err); + } +} + document.addEventListener("DOMContentLoaded", restoreOptions); document.querySelector("#settings-form").addEventListener("submit", saveOptions); \ No newline at end of file diff --git a/update_id.html b/update_id.html deleted file mode 100644 index d593815..0000000 --- a/update_id.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - Установка ID - - - -
-

Установка идентификатора клиента

-
Обработка...
-
- - - - \ No newline at end of file diff --git a/update_id.js b/update_id.js deleted file mode 100644 index ba1b3c4..0000000 --- a/update_id.js +++ /dev/null @@ -1,51 +0,0 @@ -const browserAPI = globalThis.browser ?? globalThis.chrome; -const statusEl = document.getElementById("status"); - -function getQueryParams() { - const params = new URLSearchParams(window.location.search); - const entries = {}; - for (const [key, value] of params.entries()) { - entries[key] = value; - } - return entries; -} - -async function updateClientId(newId) { - if (!newId || !newId.trim()) { - throw new Error("Пустой ID"); - } - - await browserAPI.storage.local.set({ clientId: newId }); - console.log("[UI] clientId установлен:", newId); - return newId; -} - -async function processUrlParams() { - try { - const params = getQueryParams(); - - if (!params.clientId) { - statusEl.innerHTML = `
Ошибка: отсутствует параметр clientId
-

Используйте: ?clientId=your ID

`; - return; - } - - console.log("[UI] Получен clientId из URL:", params.clientId); - - const savedId = await updateClientId(params.clientId); - - statusEl.innerHTML = `
ID успешно установлен!
-

Новый идентификатор: ${savedId}

-

Страница закроется через 5 секунд...

`; - - setTimeout(() => { - window.close(); - }, 5000); - - } catch (error) { - console.error("[UI] Ошибка:", error); - statusEl.innerHTML = `
Ошибка: ${error.message}
`; - } -} - -document.addEventListener("DOMContentLoaded", processUrlParams); \ No newline at end of file