diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 0670b16d..47d226bd 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -400,9 +400,12 @@ "message": "SponsorBlock Server Address" }, "customServerAddressDescription": { - "message": "The address SponsorBlock uses to make calls to the server.\nIt must be formatted https://domain with no trailing forward slash (/).\nUnless you have your own server instance, this should not be changed." + "message": "The address SponsorBlock uses to make calls to the server.\nUnless you have your own server instance, this should not be changed." }, "saveCustomServerAddress": { "message": "Save" + }, + "customAddressError": { + "message": "This address is not in the right form. Make sure you have http:// or https:// at the begining and no slashes or sub-folders at the end." } } diff --git a/public/options/options.html b/public/options/options.html index b2a03ddc..d6a2062a 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -41,7 +41,7 @@

-
+
__MSG_addInvidiousInstance__
diff --git a/src/options.ts b/src/options.ts index 1b44d095..2400018f 100644 --- a/src/options.ts +++ b/src/options.ts @@ -63,6 +63,20 @@ async function init() { textInput.value = Config.config[textChangeOption]; setButton.addEventListener("click", () => { + // See if anything extra must be done + switch (textChangeOption) { + case "serverAddress": + let result = validateServerAddress(textInput.value); + + if (result !== null) { + textInput.value = result; + } else { + return; + } + + break; + } + Config.config[textChangeOption] = textInput.value; }); @@ -325,3 +339,27 @@ function activatePrivateTextChange(element: HTMLElement) { element.querySelector(".option-hidden-section").classList.remove("hidden"); } + +/** + * Validates the value used for the database server address. + * Returns null and alerts the user if there is an issue. + * + * @param input Input server address + */ +function validateServerAddress(input: string): string { + // Trim the last slash if needed + if (input.endsWith("/")) { + input = input.substring(0, input.length - 1); + } + + // Isn't HTTP protocol or has extra slashes + if ((!input.startsWith("https://") && !input.startsWith("http://")) + || input.replace("://", "").includes("/")) { + + alert(chrome.i18n.getMessage("customAddressError")); + + return null; + } + + return input; +} \ No newline at end of file