From 1d263ef45ac57f1d1c69b449a7dc77745c0f8ef2 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 25 May 2023 10:42:19 +0200 Subject: [PATCH] Configurable API-location --- Website/apiConnector.js | 21 ++++++++++++++++++++- Website/index.html | 4 +++- Website/interaction.js | 23 +++++++++++++++++------ Website/style.css | 15 ++++++++------- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Website/apiConnector.js b/Website/apiConnector.js index 29cddaa..a6635dc 100644 --- a/Website/apiConnector.js +++ b/Website/apiConnector.js @@ -1,4 +1,23 @@ -const apiUri = "http://localhost:6531"; +let apiUri = `http://${window.location.host.split(':')[0]}:6531` + +if(getCookie("apiUri") != ""){ + apiUri = getCookie("apiUri"); +} +function getCookie(cname) { + let name = cname + "="; + let decodedCookie = decodeURIComponent(document.cookie); + let ca = decodedCookie.split(';'); + for(let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; +} async function GetData(uri){ let request = await fetch(uri, { diff --git a/Website/index.html b/Website/index.html index 002a74c..2987717 100644 --- a/Website/index.html +++ b/Website/index.html @@ -82,6 +82,8 @@ Download Location: + API-URI + Komga
Configured: ✅❌
@@ -89,7 +91,7 @@
- +
diff --git a/Website/interaction.js b/Website/interaction.js index 45dc5b5..cbb1172 100644 --- a/Website/interaction.js +++ b/Website/interaction.js @@ -45,6 +45,7 @@ const settingKomgaUser = document.querySelector("#komgaUsername"); const settingKomgaPass = document.querySelector("#komgaPassword"); const settingKomgaTime = document.querySelector("#komgaUpdateTime"); const settingKomgaConfigured = document.querySelector("#komgaConfigured"); +const settingApiUri = document.querySelector("#settingApiUri"); settingsCog.addEventListener("click", () => OpenSettings()); @@ -53,6 +54,18 @@ document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", () document.querySelector("#blurBackgroundPublicationPopup").addEventListener("click", () => HidePublicationPopup()); publicationDelete.addEventListener("click", () => DeleteTaskClick()); publicationAdd.addEventListener("click", () => AddTaskClick()); +settingApiUri.addEventListener("keypress", (event) => { + if(event.key === "Enter"){ + apiUri = settingApiUri.value; + setTimeout(() => GetSettingsClick(), 100); + document.cookie = `apiUri=${apiUri};`; + } +}); +searchPublicationQuery.addEventListener("keypress", (event) => { + if(event.key === "Enter"){ + NewSearch(); + } +}); let availableConnectors; GetAvailableControllers() @@ -66,11 +79,6 @@ GetAvailableControllers() }) ); -searchPublicationQuery.addEventListener("keypress", (event) => { - if(event.key === "Enter"){ - NewSearch(); - } -}); function NewSearch(){ //Disable inputs @@ -210,10 +218,13 @@ function OpenSettings(){ } function GetSettingsClick(){ + settingApiUri.value = ""; settingKomgaUrl.value = ""; settingKomgaUser.value = ""; settingKomgaPass.value = ""; + settingApiUri.placeholder = apiUri; + GetSettings().then(json => { settingDownloadLocation.innerText = json.downloadLocation; if(json.komga != null) @@ -228,7 +239,7 @@ function GetSettingsClick(){ }); } -function UpdateSettingsClick(){ +function UpdateKomgaSettings(){ var auth = utf8_to_b64(`${settingKomgaUser.value}:${settingKomgaPass.value}`); console.log(auth); UpdateSettings("", settingKomgaUrl.value, auth); diff --git a/Website/style.css b/Website/style.css index 70a2604..0ed75cf 100644 --- a/Website/style.css +++ b/Website/style.css @@ -132,6 +132,13 @@ settingstab > * { margin: 0 20px; } +settingstab input { + padding: 3px; + border-radius: 3px; + border: 0; + margin: 2px 20px; +} + settingstab .title { font-size: 14pt; font-weight: bolder; @@ -145,14 +152,8 @@ komga-settings { flex-wrap: nowrap; } -komga-settings > * { - margin: 2px 0; -} - komga-settings input { - padding: 3px; - border-radius: 3px; - border: 0; + margin: 2px 0; } #addPublication {