From af32de688a3cdcdd359d7fe9b5b134d0cc7950b1 Mon Sep 17 00:00:00 2001 From: Kajitsy Date: Tue, 16 Jan 2024 19:32:03 +0300 Subject: [PATCH] Copy notification improved This update does not carry a new version of the extension --- chromium/_locales/en/messages.json | 7 ++- chromium/_locales/es/messages.json | 7 ++- chromium/_locales/jp/messages.json | 8 +-- chromium/_locales/ru/messages.json | 7 ++- chromium/dailychecker.js | 88 +++++++++++------------------- chromium/onlyGi.html | 21 ++++++- chromium/onlyGi.js | 16 +----- chromium/onlyHsr.html | 21 ++++++- chromium/onlyHsr.js | 16 +----- chromium/options.js | 5 +- chromium/popup.html | 23 ++++++-- chromium/popup.js | 17 +----- 12 files changed, 114 insertions(+), 122 deletions(-) diff --git a/chromium/_locales/en/messages.json b/chromium/_locales/en/messages.json index 6325025..52b5f54 100644 --- a/chromium/_locales/en/messages.json +++ b/chromium/_locales/en/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "With Genshin/Star Rail CodeEntter, you can quickly input promo codes for Genshin Impact and Honkai Star Rail, and also share a link to this tool :) ChromiumVersion 2.2.2" + "message": "Quick entry of Genshin Impact/Honkai: Star Rail promo codes | 2.2.2.1" }, "submit": { "message": "Submit" @@ -43,5 +43,8 @@ }, "labelBackgroundColor": { "message": "Background Color (if enabled)" + }, + "displayOverlay" :{ + "message": "Link copied" } -} +} \ No newline at end of file diff --git a/chromium/_locales/es/messages.json b/chromium/_locales/es/messages.json index d4d42e2..c59b209 100644 --- a/chromium/_locales/es/messages.json +++ b/chromium/_locales/es/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Con Genshin/Star Rail CodeEntter, puedes ingresar rápidamente códigos promocionales para Genshin Impact y Honkai Star Rail, ¡y también compartir un enlace a esta herramienta :) ChromiumVersion 2.2.2" + "message": "Entrada rápida de los códigos promocionales de Genshin Impact/Honkai: Star Rail | 2.2.2.1" }, "submit": { "message": "Enviar" @@ -43,5 +43,8 @@ }, "labelBackgroundColor": { "message": "Color de fondo (si está habilitado)" + }, + "displayOverlay" :{ + "message": "Enlace copiado" } -} +} \ No newline at end of file diff --git a/chromium/_locales/jp/messages.json b/chromium/_locales/jp/messages.json index d4d8833..c8cf934 100644 --- a/chromium/_locales/jp/messages.json +++ b/chromium/_locales/jp/messages.json @@ -1,7 +1,4 @@ { - "extensionDescription": { - "message": "Genshin/Star Rail CodeEntterを使用すると、Genshin ImpactおよびHonkai Star Railのプロモコードを素早く入力でき、またこのツールのリンクを共有することもできます :) ChromiumVersion 2.2.2" - }, "submit": { "message": "送信" }, @@ -43,5 +40,8 @@ }, "labelBackgroundColor": { "message": "背景の色(有効になっている場合)" + }, + "displayOverlay" :{ + "message": "コピーされたリンク" } -} +} \ No newline at end of file diff --git a/chromium/_locales/ru/messages.json b/chromium/_locales/ru/messages.json index bc4cb27..7fa1baf 100644 --- a/chromium/_locales/ru/messages.json +++ b/chromium/_locales/ru/messages.json @@ -1,6 +1,6 @@ { "extensionDescription": { - "message": "Благодаря Genshin/Star Rail CodeEntter вы сможете быстро вводить промокоды для Genshin Impact и Honkai Star Rail, a также можете поделиться ссылкой на этот кодик :) ChromiumVersion 2.2.2" + "message": "Быстрый ввод промокодов Genshin Impact/Honkai: Star Rail | 2.2.2.1" }, "submit": { "message": "Ввести" @@ -43,5 +43,8 @@ }, "labelBackgroundColor": { "message": "Цвет фона (если включено)" + }, + "displayOverlay" :{ + "message": "Ссылка скопирована" } -} +} \ No newline at end of file diff --git a/chromium/dailychecker.js b/chromium/dailychecker.js index 9f708b9..4e87950 100644 --- a/chromium/dailychecker.js +++ b/chromium/dailychecker.js @@ -1,47 +1,36 @@ -const HSRHOSTS = [ - { - apiHost: "sg-public-api.hoyolab.com", - page: "act.hoyolab.com/bbs/event/signin/hkrpg/index.html" - } -]; -const HOSTS = [ - { - apiHost: "sg-hk4e-api.hoyolab.com", - page: "act.hoyolab.com/ys/event/signin-sea-v3/index.html" - }, - { - apiHost: "hk4e-api-os.mihoyo.com", - page: "webstatic-sea.mihoyo.com/ys/event/signin-sea/index.html" - } -]; -var currentHSRHosts = HSRHOSTS; -var currentHosts = HOSTS; -var dcwork; +if (typeof browser === "undefined") { + browser = chrome; +} function getCurrDay() { var now = new Date(); now.setMinutes(now.getMinutes() + now.getTimezoneOffset()); now.setHours(now.getHours() + 8); return Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0); } -function request(i, currDay) { - var host = currentHosts[i]; - if (typeof host === "undefined") { - currentHosts = HOSTS; - return; - } - var hsrhost = currentHSRHosts[i]; - if (typeof hsrhost === "undefined") { - currentHSRHosts = HSRHOSTS; - return; - } - fetch("https://" + host.apiHost + "/event/sol/sign?act_id=e202102251931481", { +function GIrequest() { + var currDay = getCurrDay(); + fetch("https://sg-hk4e-api.hoyolab.com/event/sol/sign?act_id=e202102251931481", { method : "POST", headers: { "Content-Type": "application/json" }, credentials: "include" }) - fetch("https://" + hsrhost.apiHost + "/event/luna/os/sign?act_id=e202303301540311", { + .then(response => response.json()) + .then(data => { + if (data.retcode == 0 || data.retcode == -5003) { + console.log("GIsuccess", data); + browser.storage.local.set({dc_lastCheked: currDay}); + } else if (data.retcode == -10002) { + console.log("GIbadrequest", data); + } else { + console.log("GIwarning", data); + } + }) +} +function HSRrequest() { + var currDay = getCurrDay(); + fetch("https://sg-public-api.hoyolab.com/event/luna/os/sign?act_id=e202303301540311", { method : "POST", headers: { "Content-Type": "application/json" @@ -50,41 +39,28 @@ function request(i, currDay) { }) .then(response => response.json()) .then(data => { - if(data.retcode == 0 || data.retcode == -5003) { - chrome.storage.local.set({dc_lastCheked: currDay}); - dcwork = true; - currentHosts = [host]; - currentHSRHosts = [hsrhost]; - console.log("success", data); - } else if(data.retcode == -10002) { - dcwork = false; - console.log("badrequest", data); - request(i + 1); + if (data.retcode == 0 || data.retcode == -5003) { + console.log("HSRsuccess", data); + browser.storage.local.set({dc_lastCheked: currDay}); + } else if (data.retcode == -10002) { + console.log("HSRbadrequest", data); } else { - console.log("warning", data); - request(i + 1); + console.log("HSRwarning", data); } }) - .catch(error => { - dcwork = false; - console.log("error", error); - request(i + 1); - }); } - function check() { - chrome.storage.local.get({dc_lastCheked: null}).then(storage => { + browser.storage.local.get({dc_lastCheked: null}).then(storage => { var currDay = getCurrDay(); if (storage.dc_lastCheked != currDay) { - request(0, currDay); + HSRrequest(); + GIrequest(); } }); } - -chrome.alarms.onAlarm.addListener(alarm => { +browser.alarms.onAlarm.addListener(alarm => { if (alarm.name == "daily_checker") { check(); } }); - -chrome.alarms.create("daily_checker", {when: Date.now(), periodInMinutes: 1}); \ No newline at end of file +browser.alarms.create("daily_checker", {when: Date.now(), periodInMinutes: 1}); \ No newline at end of file diff --git a/chromium/onlyGi.html b/chromium/onlyGi.html index 1843ae0..7bc1e64 100644 --- a/chromium/onlyGi.html +++ b/chromium/onlyGi.html @@ -43,8 +43,8 @@ justify-content: space-between; } #submit, #share { - width: 140px; - margin: 5px; + width: 48%; + margin-top: 10px; } button { cursor: pointer; @@ -72,17 +72,32 @@ border: none; z-index: 2; } + #displayOverlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + color: white; + display: none; + justify-content: center; + align-items: center; + z-index: 2; + font-family: 'SDK_SC_Web'; + }
- +
+
\ No newline at end of file diff --git a/chromium/onlyGi.js b/chromium/onlyGi.js index f5450c5..ff88255 100644 --- a/chromium/onlyGi.js +++ b/chromium/onlyGi.js @@ -40,22 +40,10 @@ if (typeof browser === "undefined") { }); function displayOverlay() { - const overlay = document.createElement('div'); - overlay.style.position = 'fixed'; - overlay.style.top = 0; - overlay.style.left = 0; - overlay.style.width = '100%'; - overlay.style.height = '100%'; - overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; - overlay.style.color = 'white'; - overlay.style.display = 'flex'; - overlay.style.justifyContent = 'center'; - overlay.style.alignItems = 'center'; - overlay.style.fontSize = '1em'; - overlay.textContent = 'The Link Has Been Copied'; + const overlay = document.getElementById('displayOverlay'); + overlay.textContent = browser.i18n.getMessage("displayOverlay") overlay.style.display = 'flex'; document.body.appendChild(overlay); - setTimeout(function () { overlay.style.display = 'none'; }, 2000); diff --git a/chromium/onlyHsr.html b/chromium/onlyHsr.html index 0757230..90be258 100644 --- a/chromium/onlyHsr.html +++ b/chromium/onlyHsr.html @@ -44,8 +44,8 @@ font-family: 'SDK_SC_Web'; } #submit, #share { - width: 140px; - margin: 5px; + width: 48%; + margin-top: 10px; } button { cursor: pointer; @@ -73,17 +73,32 @@ border: none; z-index: 2; } + #displayOverlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + color: white; + display: none; + justify-content: center; + align-items: center; + z-index: 2; + font-family: 'SDK_SC_Web'; + }
- +
+
\ No newline at end of file diff --git a/chromium/onlyHsr.js b/chromium/onlyHsr.js index 80617ed..01fd509 100644 --- a/chromium/onlyHsr.js +++ b/chromium/onlyHsr.js @@ -38,22 +38,10 @@ if (typeof browser === "undefined") { }); function displayOverlay() { - const overlay = document.createElement('div'); - overlay.style.position = 'fixed'; - overlay.style.top = 0; - overlay.style.left = 0; - overlay.style.width = '100%'; - overlay.style.height = '100%'; - overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; - overlay.style.color = 'white'; - overlay.style.display = 'flex'; - overlay.style.justifyContent = 'center'; - overlay.style.alignItems = 'center'; - overlay.style.fontSize = '1em'; - overlay.textContent = 'The Link Has Been Copied'; + const overlay = document.getElementById('displayOverlay'); + overlay.textContent = browser.i18n.getMessage("displayOverlay") overlay.style.display = 'flex'; document.body.appendChild(overlay); - setTimeout(function () { overlay.style.display = 'none'; }, 2000); diff --git a/chromium/options.js b/chromium/options.js index 6984b03..7eb61f2 100644 --- a/chromium/options.js +++ b/chromium/options.js @@ -57,10 +57,9 @@ function showSettingsSection(section) { function updateDcWorkIconColor() { if (dcwork = true) { dcWorkIcon.style.backgroundColor = 'green'; - } else if (dcwork = false) { + } + else { dcWorkIcon.style.backgroundColor = 'red'; - } else { - dcWorkIcon.style.backgroundColor = 'yellow'; } } function updateIconColorOnChange() { diff --git a/chromium/popup.html b/chromium/popup.html index 736da77..96fa8ed 100644 --- a/chromium/popup.html +++ b/chromium/popup.html @@ -14,7 +14,7 @@ src: url('GIfont.woff2') format('woff2'); } body { - font-family: 'SDK_SC_Web'; + font-family: var(--); padding: 10px; background-size: cover; background-repeat: no-repeat; @@ -44,8 +44,8 @@ justify-content: space-between; } #submitGI, #submitHSR, #shareGI, #shareHSR { - width: 140px; - margin: 5px; + width: 48%; + margin-top: 10px; } button { cursor: pointer; @@ -73,11 +73,25 @@ border: none; z-index: 2; } + #displayOverlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: rgba(0, 0, 0, 0.5); + color: white; + display: none; + justify-content: center; + align-items: center; + z-index: 2; + font-family: 'SDK_SC_Web'; + }
- +
@@ -88,6 +102,7 @@
+
\ No newline at end of file diff --git a/chromium/popup.js b/chromium/popup.js index e04d0f0..d5514f5 100644 --- a/chromium/popup.js +++ b/chromium/popup.js @@ -56,23 +56,10 @@ document.body.style.backgroundImage = "url(/pictures/background.png)"; }); function displayOverlay() { - const overlay = document.createElement('div'); - overlay.style.position = 'fixed'; - overlay.style.top = 0; - overlay.style.left = 0; - overlay.style.width = '100%'; - overlay.style.height = '100%'; - overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; - overlay.style.color = 'white'; + const overlay = document.getElementById('displayOverlay'); + overlay.textContent = browser.i18n.getMessage("displayOverlay") overlay.style.display = 'flex'; - overlay.style.justifyContent = 'center'; - overlay.style.alignItems = 'center'; - overlay.style.fontSize = '1em'; - overlay.textContent = 'The Link Has Been Copied'; - overlay.style.display = 'flex'; - overlay.style.zIndex ='2'; document.body.appendChild(overlay); - setTimeout(function () { overlay.style.display = 'none'; }, 2000);