From 4d11ed49bcf8a2bc62e92194a43fc9d8940a16e7 Mon Sep 17 00:00:00 2001 From: Kajitsy Date: Fri, 23 Aug 2024 21:22:33 +0300 Subject: [PATCH] 2.2.7 Update --- chromium/_locales/en/messages.json | 17 +- chromium/_locales/es/messages.json | 17 +- chromium/_locales/ja/messages.json | 15 + chromium/_locales/ru/messages.json | 17 +- chromium/manifest.json | 2 +- chromium/popup.html | 1 - chromium/popup.js | 450 ++++++++++++++++++++++++----- firefox/_locales/en/messages.json | 17 +- firefox/_locales/es/messages.json | 17 +- firefox/_locales/ja/messages.json | 15 + firefox/_locales/ru/messages.json | 17 +- firefox/manifest.json | 2 +- firefox/popup.html | 1 - firefox/popup.js | 438 +++++++++++++++++++++++----- 14 files changed, 864 insertions(+), 162 deletions(-) diff --git a/chromium/_locales/en/messages.json b/chromium/_locales/en/messages.json index fcd7054..04ea366 100644 --- a/chromium/_locales/en/messages.json +++ b/chromium/_locales/en/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Quick input of promo codes for HoYoverse games | 2.2.6" + "message": "Quick input of promo codes for HoYoverse games | 2.2.7" }, "stgi": { "message": "Submit" @@ -100,5 +100,20 @@ }, "labelNotClickable": { "message": "This does not press" + }, + "success_all": { + "message": "The code has been successfully redeemed on all servers!" + }, + "fail_all": { + "message": "Failed to redeem the code on all servers." + }, + "partial_success": { + "message": "The code was redeemed on {successful} server(s), but errors occurred on {failed} server(s)." + }, + "account_data_error": { + "message": "Failed to retrieve account data." + }, + "api_request_error": { + "message": "Error occurred while making the API request." } } \ No newline at end of file diff --git a/chromium/_locales/es/messages.json b/chromium/_locales/es/messages.json index 00767c6..cde1739 100644 --- a/chromium/_locales/es/messages.json +++ b/chromium/_locales/es/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Entrada rápida de códigos promocionales para juegos de HoYoverse | 2.2.6" + "message": "Entrada rápida de códigos promocionales para juegos de HoYoverse | 2.2.7" }, "stgi": { "message": "Enviar" @@ -100,5 +100,20 @@ }, "labelNotClickable": { "message": "Esto no se presiona" + }, + "success_all": { + "message": "¡Código promocional activado exitosamente en todos los servidores!" + }, + "fail_all": { + "message": "No se pudo activar el código promocional en todos los servidores." + }, + "partial_success": { + "message": "Código promocional activado en {successful} servidor(es), pero hubo errores en {failed} servidor(es)." + }, + "account_data_error": { + "message": "No se pudieron obtener los datos de la cuenta." + }, + "api_request_error": { + "message": "Error al realizar la solicitud a la API." } } \ No newline at end of file diff --git a/chromium/_locales/ja/messages.json b/chromium/_locales/ja/messages.json index fa25c20..26a8149 100644 --- a/chromium/_locales/ja/messages.json +++ b/chromium/_locales/ja/messages.json @@ -97,5 +97,20 @@ }, "labelNotClickable":{ "message":"これは押されていません" + }, + "success_all": { + "message": "プロモコードがすべてのサーバーで正常にアクティブ化されました!" + }, + "fail_all": { + "message": "すべてのサーバーでプロモコードをアクティブ化できませんでした。" + }, + "partial_success": { + "message": "プロモコードが{successful}サーバーでアクティブ化されましたが、{failed}サーバーでエラーが発生しました。" + }, + "account_data_error": { + "message": "アカウントデータを取得できませんでした。" + }, + "api_request_error": { + "message": "APIリクエスト中にエラーが発生しました。" } } \ No newline at end of file diff --git a/chromium/_locales/ru/messages.json b/chromium/_locales/ru/messages.json index e4a9dc5..9e52011 100644 --- a/chromium/_locales/ru/messages.json +++ b/chromium/_locales/ru/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Быстрый ввод промокодов игр HoYoverse | 2.2.6" + "message": "Быстрый ввод промокодов игр HoYoverse | 2.2.7" }, "stgi": { "message": "Ввести" @@ -100,5 +100,20 @@ }, "labelNotClickable": { "message": "Это не нажимается" + }, + "success_all": { + "message": "Промокод успешно активирован на всех серверах!" + }, + "fail_all": { + "message": "Не удалось активировать промокод на всех серверах." + }, + "partial_success": { + "message": "Промокод активирован на {successful} сервер(ах), но возникли ошибки на {failed} сервер(ах)." + }, + "account_data_error": { + "message": "Не удалось получить данные об аккаунте." + }, + "api_request_error": { + "message": "Ошибка при запросе к API." } } \ No newline at end of file diff --git a/chromium/manifest.json b/chromium/manifest.json index 8614943..d2ad6da 100644 --- a/chromium/manifest.json +++ b/chromium/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "HoYoverse CodeEnter", - "version": "2.2.6", + "version": "2.2.7", "description": "__MSG_extensionDescription__", "default_locale": "en", "icons": { diff --git a/chromium/popup.html b/chromium/popup.html index 3988962..bd71077 100644 --- a/chromium/popup.html +++ b/chromium/popup.html @@ -177,7 +177,6 @@
- \ No newline at end of file diff --git a/chromium/popup.js b/chromium/popup.js index bef08a0..1fb30cc 100644 --- a/chromium/popup.js +++ b/chromium/popup.js @@ -24,7 +24,8 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result let url; switch (buttonId) { case 'sthsr': - url = `https://hsr.hoyoverse.com/gift?code=${code}`; + gameBiz = 'hkrpg_global'; + promoBaseUrl = 'https://sg-hkrpg-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; break; case 'sehsr': url = `https://hsr.hoyoverse.com/gift?code=${code}`; @@ -34,12 +35,85 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result default: break; } - if (buttonId === 'sthsr') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(chrome.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(chrome.i18n.getMessage("api_request_error")); + window.close(); }); } }); @@ -69,7 +143,8 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result let url; switch (buttonId) { case 'stzzz': - url = `https://zenless.hoyoverse.com/redemption?code=${code}`; + gameBiz = 'nap_global'; + promoBaseUrl = 'https://public-operation-nap.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; break; case 'sezzz': url = `https://zenless.hoyoverse.com/redemption?code=${code}`; @@ -79,12 +154,85 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result default: break; } - if (buttonId === 'stzzz') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(chrome.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(chrome.i18n.getMessage("api_request_error")); + window.close(); }); } }); @@ -113,7 +261,8 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result let url; switch (buttonId) { case 'stgi': - url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; + gameBiz = 'hk4e_global'; + promoBaseUrl = 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; break; case 'segi': url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; @@ -123,12 +272,85 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result default: break; } - if (buttonId === 'stgi') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(chrome.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(chrome.i18n.getMessage("api_request_error")); + window.close(); }); } }); @@ -198,11 +420,11 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result } const label = document.getElementById("labelBirthdayPopup"); var characterLANG = characterData.characterEN; - if (navigator.language === 'ru-RU' && characterData.characterRU) { + if (navigator.language === 'ru' && characterData.characterRU) { characterLANG = characterData.characterRU; - } else if (navigator.language === 'es-ES' && characterData.characterES) { + } else if (navigator.language === 'es' && characterData.characterES) { characterLANG = characterData.characterES; - } else if (navigator.language === 'ja-JP' && characterData.characterJA) { + } else if (navigator.language === 'ja' && characterData.characterJA) { characterLANG = characterData.characterJA; } label.textContent = chrome.i18n.getMessage("labelBirthdayPopup") + characterLANG + "!"; @@ -221,59 +443,129 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result } }); } else { - buttonIds.forEach((buttonId) => { - const buttonElement = document.getElementById(buttonId); + buttonIds.forEach((buttonId) => { + const buttonElement = document.getElementById(buttonId); + if (buttonElement) { buttonElement.textContent = chrome.i18n.getMessage(buttonId); - if (buttonElement) { - buttonElement.addEventListener('click', () => { - const code = codeElement.value; - const locales = navigator.language.slice(0, 2); - let url; - switch (buttonId) { - case 'submitGI': - document.body.style.backgroundImage = "url(/pictures/backgroundGI.webp)"; - url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; - break; - case 'submitHSR': - url = `https://hsr.hoyoverse.com/gift?code=${code}`; - document.body.style.backgroundImage = "url(/pictures/backgroundHSR.webp)"; - break; - case 'submitZZZ': - url = `https://zenless.hoyoverse.com/redemption?code=${code}`; - document.body.style.backgroundImage = "url(/pictures/backgroundZZZ.webp)"; - break; - case 'shareGI': - url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; - navigator.clipboard.writeText(url); - displayOverlay(); - break; - case 'shareHSR': - url = `https://hsr.hoyoverse.com/gift?code=${code}`; - navigator.clipboard.writeText(url); - displayOverlay(); - break; - case 'shareZZZ': - url = `https://zenless.hoyoverse.com/redemption?code=${code}`; - navigator.clipboard.writeText(url); - displayOverlay(); - break; - default: - break; - } - if (buttonId === 'submitGI' || buttonId === 'submitHSR' || buttonId === 'submitZZZ') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - document.getElementById("labelBirthdayPopup").style.display = 'none'; - effectVision = false; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; - }); - } - }); - } - }); - chrome.storage.local.get(['buttonColorMain', 'buttonTextColorMain']).then((result) => { + buttonElement.addEventListener('click', () => { + const code = codeElement.value; + let gameBiz; + switch (buttonId) { + case 'submitGI': + gameBiz = 'hk4e_global'; + promoBaseUrl = 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; + break; + case 'shareGI': + url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; + navigator.clipboard.writeText(url); + displayOverlay(); + break; + case 'submitHSR': + gameBiz = 'hkrpg_global'; + promoBaseUrl = 'https://sg-hkrpg-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; + break; + case 'shareHSR': + url = `https://hsr.hoyoverse.com/gift?code=${code}`; + navigator.clipboard.writeText(url); + displayOverlay(); + break; + case 'submitZZZ': + gameBiz = 'nap_global'; + promoBaseUrl = 'https://public-operation-nap.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; + break; + case 'shareZZZ': + url = `https://zenless.hoyoverse.com/redemption?code=${code}`; + navigator.clipboard.writeText(url); + displayOverlay(); + break; + default: + break; + } + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(chrome.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(chrome.i18n.getMessage("fail_all")); + } else { + alert(chrome.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(chrome.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(chrome.i18n.getMessage("api_request_error")); + window.close(); + }); + } + }); + } + }); + chrome.storage.local.get(['buttonColorMain', 'buttonTextColorMain']).then((result) => { if (result.buttonColorMain) { document.documentElement.style.setProperty('--button-color', result.buttonColorMain); } @@ -333,11 +625,11 @@ chrome.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (result } const label = document.getElementById("labelBirthdayPopup"); var characterLANG = characterData.characterEN; - if (navigator.language === 'ru-RU' && characterData.characterRU) { + if (navigator.language === 'ru' && characterData.characterRU) { characterLANG = characterData.characterRU; - } else if (navigator.language === 'es-ES' && characterData.characterES) { + } else if (navigator.language === 'es' && characterData.characterES) { characterLANG = characterData.characterES; - } else if (navigator.language === 'ja-JP' && characterData.characterJA) { + } else if (navigator.language === 'ja' && characterData.characterJA) { characterLANG = characterData.characterJA; } label.textContent = chrome.i18n.getMessage("labelBirthdayPopup") + characterLANG + "!"; diff --git a/firefox/_locales/en/messages.json b/firefox/_locales/en/messages.json index fcd7054..04ea366 100644 --- a/firefox/_locales/en/messages.json +++ b/firefox/_locales/en/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Quick input of promo codes for HoYoverse games | 2.2.6" + "message": "Quick input of promo codes for HoYoverse games | 2.2.7" }, "stgi": { "message": "Submit" @@ -100,5 +100,20 @@ }, "labelNotClickable": { "message": "This does not press" + }, + "success_all": { + "message": "The code has been successfully redeemed on all servers!" + }, + "fail_all": { + "message": "Failed to redeem the code on all servers." + }, + "partial_success": { + "message": "The code was redeemed on {successful} server(s), but errors occurred on {failed} server(s)." + }, + "account_data_error": { + "message": "Failed to retrieve account data." + }, + "api_request_error": { + "message": "Error occurred while making the API request." } } \ No newline at end of file diff --git a/firefox/_locales/es/messages.json b/firefox/_locales/es/messages.json index 00767c6..cde1739 100644 --- a/firefox/_locales/es/messages.json +++ b/firefox/_locales/es/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Entrada rápida de códigos promocionales para juegos de HoYoverse | 2.2.6" + "message": "Entrada rápida de códigos promocionales para juegos de HoYoverse | 2.2.7" }, "stgi": { "message": "Enviar" @@ -100,5 +100,20 @@ }, "labelNotClickable": { "message": "Esto no se presiona" + }, + "success_all": { + "message": "¡Código promocional activado exitosamente en todos los servidores!" + }, + "fail_all": { + "message": "No se pudo activar el código promocional en todos los servidores." + }, + "partial_success": { + "message": "Código promocional activado en {successful} servidor(es), pero hubo errores en {failed} servidor(es)." + }, + "account_data_error": { + "message": "No se pudieron obtener los datos de la cuenta." + }, + "api_request_error": { + "message": "Error al realizar la solicitud a la API." } } \ No newline at end of file diff --git a/firefox/_locales/ja/messages.json b/firefox/_locales/ja/messages.json index fa25c20..26a8149 100644 --- a/firefox/_locales/ja/messages.json +++ b/firefox/_locales/ja/messages.json @@ -97,5 +97,20 @@ }, "labelNotClickable":{ "message":"これは押されていません" + }, + "success_all": { + "message": "プロモコードがすべてのサーバーで正常にアクティブ化されました!" + }, + "fail_all": { + "message": "すべてのサーバーでプロモコードをアクティブ化できませんでした。" + }, + "partial_success": { + "message": "プロモコードが{successful}サーバーでアクティブ化されましたが、{failed}サーバーでエラーが発生しました。" + }, + "account_data_error": { + "message": "アカウントデータを取得できませんでした。" + }, + "api_request_error": { + "message": "APIリクエスト中にエラーが発生しました。" } } \ No newline at end of file diff --git a/firefox/_locales/ru/messages.json b/firefox/_locales/ru/messages.json index e4a9dc5..9e52011 100644 --- a/firefox/_locales/ru/messages.json +++ b/firefox/_locales/ru/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Быстрый ввод промокодов игр HoYoverse | 2.2.6" + "message": "Быстрый ввод промокодов игр HoYoverse | 2.2.7" }, "stgi": { "message": "Ввести" @@ -100,5 +100,20 @@ }, "labelNotClickable": { "message": "Это не нажимается" + }, + "success_all": { + "message": "Промокод успешно активирован на всех серверах!" + }, + "fail_all": { + "message": "Не удалось активировать промокод на всех серверах." + }, + "partial_success": { + "message": "Промокод активирован на {successful} сервер(ах), но возникли ошибки на {failed} сервер(ах)." + }, + "account_data_error": { + "message": "Не удалось получить данные об аккаунте." + }, + "api_request_error": { + "message": "Ошибка при запросе к API." } } \ No newline at end of file diff --git a/firefox/manifest.json b/firefox/manifest.json index be10aca..0e509bf 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "HoYoverse CodeEnter", - "version": "2.2.6", + "version": "2.2.7", "description": "__MSG_extensionDescription__", "default_locale": "en", "icons": { diff --git a/firefox/popup.html b/firefox/popup.html index 3988962..bd71077 100644 --- a/firefox/popup.html +++ b/firefox/popup.html @@ -177,7 +177,6 @@
- \ No newline at end of file diff --git a/firefox/popup.js b/firefox/popup.js index 8035eeb..9a77e07 100644 --- a/firefox/popup.js +++ b/firefox/popup.js @@ -24,7 +24,8 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul let url; switch (buttonId) { case 'sthsr': - url = `https://hsr.hoyoverse.com/gift?code=${code}`; + gameBiz = 'hkrpg_global'; + promoBaseUrl = 'https://sg-hkrpg-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; break; case 'sehsr': url = `https://hsr.hoyoverse.com/gift?code=${code}`; @@ -34,12 +35,85 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul default: break; } - if (buttonId === 'sthsr') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(browser.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(browser.i18n.getMessage("api_request_error")); + window.close(); }); } }); @@ -69,7 +143,8 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul let url; switch (buttonId) { case 'stzzz': - url = `https://zenless.hoyoverse.com/redemption?code=${code}`; + gameBiz = 'nap_global'; + promoBaseUrl = 'https://public-operation-nap.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; break; case 'sezzz': url = `https://zenless.hoyoverse.com/redemption?code=${code}`; @@ -79,12 +154,85 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul default: break; } - if (buttonId === 'stzzz') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(browser.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(browser.i18n.getMessage("api_request_error")); + window.close(); }); } }); @@ -113,7 +261,8 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul let url; switch (buttonId) { case 'stgi': - url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; + gameBiz = 'hk4e_global'; + promoBaseUrl = 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; break; case 'segi': url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; @@ -123,12 +272,85 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul default: break; } - if (buttonId === 'stgi') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(browser.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(browser.i18n.getMessage("api_request_error")); + window.close(); }); } }); @@ -221,59 +443,129 @@ browser.storage.local.get(['onlyHsr', 'onlyGi', 'onlyZzz']).then(function (resul } }); } else { - buttonIds.forEach((buttonId) => { - const buttonElement = document.getElementById(buttonId); + buttonIds.forEach((buttonId) => { + const buttonElement = document.getElementById(buttonId); + if (buttonElement) { buttonElement.textContent = browser.i18n.getMessage(buttonId); - if (buttonElement) { - buttonElement.addEventListener('click', () => { - const code = codeElement.value; - const locales = navigator.language.slice(0, 2); - let url; - switch (buttonId) { - case 'submitGI': - document.body.style.backgroundImage = "url(/pictures/backgroundGI.webp)"; - url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; - break; - case 'submitHSR': - url = `https://hsr.hoyoverse.com/gift?code=${code}`; - document.body.style.backgroundImage = "url(/pictures/backgroundHSR.webp)"; - break; - case 'submitZZZ': - url = `https://zenless.hoyoverse.com/redemption?code=${code}`; - document.body.style.backgroundImage = "url(/pictures/backgroundZZZ.webp)"; - break; - case 'shareGI': - url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; - navigator.clipboard.writeText(url); - displayOverlay(); - break; - case 'shareHSR': - url = `https://hsr.hoyoverse.com/gift?code=${code}`; - navigator.clipboard.writeText(url); - displayOverlay(); - break; - case 'shareZZZ': - url = `https://zenless.hoyoverse.com/redemption?code=${code}`; - navigator.clipboard.writeText(url); - displayOverlay(); - break; - default: - break; - } - if (buttonId === 'submitGI' || buttonId === 'submitHSR' || buttonId === 'submitZZZ') { - frame.src = url; - frame.style.display = 'block'; - codeElement.style.display = 'none'; - document.getElementById("labelBirthdayPopup").style.display = 'none'; - effectVision = false; - buttonIds.forEach((id) => { - document.getElementById(id).style.display = 'none'; - }); - } - }); - } - }); - browser.storage.local.get(['buttonColorMain', 'buttonTextColorMain']).then((result) => { + buttonElement.addEventListener('click', () => { + const code = codeElement.value; + let gameBiz; + switch (buttonId) { + case 'submitGI': + gameBiz = 'hk4e_global'; + promoBaseUrl = 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; + break; + case 'shareGI': + url = `https://genshin.hoyoverse.com/${locales}/gift?code=${code}`; + navigator.clipboard.writeText(url); + displayOverlay(); + break; + case 'submitHSR': + gameBiz = 'hkrpg_global'; + promoBaseUrl = 'https://sg-hkrpg-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; + break; + case 'shareHSR': + url = `https://hsr.hoyoverse.com/gift?code=${code}`; + navigator.clipboard.writeText(url); + displayOverlay(); + break; + case 'submitZZZ': + gameBiz = 'nap_global'; + promoBaseUrl = 'https://public-operation-nap.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'; + break; + case 'shareZZZ': + url = `https://zenless.hoyoverse.com/redemption?code=${code}`; + navigator.clipboard.writeText(url); + displayOverlay(); + break; + default: + break; + } + if (gameBiz && promoBaseUrl && code) { + const apiUrl = `https://api-account-os.hoyoverse.com/account/binding/api/getUserGameRolesByCookieToken?game_biz=${gameBiz}`; + + fetch(apiUrl, { + method: 'GET', + credentials: 'include' + }) + + .then(response => response.json()) + .then(data => { + if (data.retcode === 0 && data.data && data.data.list && data.data.list.length > 0) { + const results = []; + let successful = 0; + let failed = 0; + + data.data.list.forEach((userData, index) => { + const uid = userData.game_uid; + const region = userData.region; + const lang = navigator.language || navigator.userLanguage; + + const promoUrl = `${promoBaseUrl}?game_biz=${gameBiz}&uid=${uid}®ion=${region}&lang=${lang}&cdkey=${code}`; + + fetch(promoUrl, { + method: 'GET', + credentials: 'include' + }) + .then(response => response.json()) + .then(promoData => { + if (promoData.retcode === 0) { + successful++; + } else { + failed++; + } + + results.push({ + region: userData.region_name, + success: promoData.retcode === 0, + message: promoData.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }) + .catch(error => { + failed++; + results.push({ + region: userData.region_name, + success: false, + message: error.message + }); + + if (index === data.data.list.length - 1) { + if (successful > 0 && failed === 0) { + alert(browser.i18n.getMessage("success_all")); + } else if (successful === 0 && failed > 0) { + alert(browser.i18n.getMessage("fail_all")); + } else { + alert(browser.i18n.getMessage("partial_success", [successful, failed])); + } + window.close(); + } + }); + }); + } else { + alert(browser.i18n.getMessage("account_data_error")); + window.close(); + } + }) + .catch(error => { + alert(browser.i18n.getMessage("api_request_error")); + window.close(); + }); + } + }); + } + }); + browser.storage.local.get(['buttonColorMain', 'buttonTextColorMain']).then((result) => { if (result.buttonColorMain) { document.documentElement.style.setProperty('--button-color', result.buttonColorMain); }