diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 7daaea3b..12625d80 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -401,5 +401,23 @@ }, "whatUploadButton": { "message": "This button appears on the YouTube player after you have selected a timestamp and are ready to submit." + }, + "customServerAddress": { + "message": "SponsorBlock Server Address" + }, + "customServerAddressDescription": { + "message": "The address SponsorBlock uses to make calls to the server.\nUnless you have your own server instance, this should not be changed." + }, + "save": { + "message": "Save" + }, + "reset": { + "message": "Reset" + }, + "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." + }, + "areYouSureReset": { + "message": "Are you sure you would like to reset this?" } } diff --git a/public/options/options.css b/public/options/options.css index bc8e2f92..b80bf116 100644 --- a/public/options/options.css +++ b/public/options/options.css @@ -76,6 +76,11 @@ body { color: white; } +.text-label-container { + font-size: 14px; + color: white; +} + .switch { position: relative; display: inline-block; diff --git a/public/options/options.html b/public/options/options.html index e537ae29..52530d36 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -41,7 +41,7 @@

-
+
__MSG_addInvidiousInstance__
@@ -93,7 +93,8 @@

- + +
__MSG_setStartSponsorShortcut__ @@ -146,6 +147,18 @@
__MSG_minDurationDescription__
+ +
+
+ +
+ +


@@ -252,7 +265,7 @@

-
+
__MSG_changeUserID__
@@ -274,19 +287,31 @@
- +

- -
-
diff --git a/src/config.ts b/src/config.ts index 1e56d5d6..cbb8d40f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,3 +1,5 @@ +import * as CompileConfig from "../config.json"; + interface SBConfig { userID: string, sponsorTimes: SBMap, @@ -21,6 +23,7 @@ interface SBConfig { invidiousUpdateInfoShowCount: number, autoUpvote: boolean, supportInvidious: boolean, + serverAddress: string, minDuration: number } @@ -115,6 +118,7 @@ var Config: SBObject = { invidiousUpdateInfoShowCount: 0, autoUpvote: true, supportInvidious: false, + serverAddress: CompileConfig.serverAddress, minDuration: 0 }, localConfig: null, diff --git a/src/options.ts b/src/options.ts index a4b2cf18..00a71bb9 100644 --- a/src/options.ts +++ b/src/options.ts @@ -55,14 +55,51 @@ async function init() { }); break; case "text-change": - let button = optionsElements[i].querySelector(".trigger-button"); - button.addEventListener("click", () => activateTextChange( optionsElements[i])); - let textChangeOption = optionsElements[i].getAttribute("sync-option"); + let textChangeInput = optionsElements[i].querySelector(".option-text-box"); + + let textChangeSetButton = optionsElements[i].querySelector(".text-change-set"); + + textChangeInput.value = Config.config[textChangeOption]; + + textChangeSetButton.addEventListener("click", () => { + // See if anything extra must be done + switch (textChangeOption) { + case "serverAddress": + let result = validateServerAddress(textChangeInput.value); + + if (result !== null) { + textChangeInput.value = result; + } else { + return; + } + + break; + } + + Config.config[textChangeOption] = textChangeInput.value; + }); + + // Reset to the default if needed + let textChangeResetButton = optionsElements[i].querySelector(".text-change-reset"); + textChangeResetButton.addEventListener("click", () => { + if (!confirm(chrome.i18n.getMessage("areYouSureReset"))) return; + + Config.config[textChangeOption] = Config.defaults[textChangeOption]; + + textChangeInput.value = Config.config[textChangeOption]; + }); + + break; + case "private-text-change": + let button = optionsElements[i].querySelector(".trigger-button"); + button.addEventListener("click", () => activatePrivateTextChange( optionsElements[i])); + + let privateTextChangeOption = optionsElements[i].getAttribute("sync-option"); // See if anything extra must be done - switch (textChangeOption) { + switch (privateTextChangeOption) { case "invidiousInstances": - invidiousInstanceAddInit( optionsElements[i], textChangeOption); + invidiousInstanceAddInit( optionsElements[i], privateTextChangeOption); } break; @@ -283,7 +320,7 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) { * * @param element */ -function activateTextChange(element: HTMLElement) { +function activatePrivateTextChange(element: HTMLElement) { let button = element.querySelector(".trigger-button"); if (button.classList.contains("disabled")) return; @@ -312,3 +349,27 @@ function activateTextChange(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 diff --git a/src/utils.ts b/src/utils.ts index 7e156469..2134c6d7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,3 @@ -import * as CompileConfig from "../config.json"; import Config from "./config"; class Utils { @@ -241,7 +240,7 @@ class Utils { sendRequestToServer(type: string, address: string, callback?: (xmlhttp: XMLHttpRequest, err: boolean) => any) { let xmlhttp = new XMLHttpRequest(); - xmlhttp.open(type, CompileConfig.serverAddress + address, true); + xmlhttp.open(type, Config.config.serverAddress + address, true); if (callback != undefined) { xmlhttp.onreadystatechange = function () {