add custom server address

This commit is contained in:
Joe Dowd
2020-02-07 00:40:01 +00:00
parent feda7fd1a0
commit dd08ff1507
6 changed files with 70 additions and 3 deletions

View File

@@ -19,7 +19,8 @@ interface SBConfig {
invidiousInstances: string[],
invidiousUpdateInfoShowCount: number,
autoUpvote: boolean,
supportInvidious: false
supportInvidious: false,
customServerAddress: string
}
interface SBObject {
@@ -111,7 +112,8 @@ var Config: SBObject = {
invidiousInstances: ["invidio.us", "invidiou.sh", "invidious.snopyta.org"],
invidiousUpdateInfoShowCount: 0,
autoUpvote: true,
supportInvidious: false
supportInvidious: false,
customServerAddress: null
},
localConfig: null,
config: null

View File

@@ -1,4 +1,5 @@
import Config from "./config";
import * as CompileConfig from "../config.json";
import Utils from "./utils";
var utils = new Utils();
@@ -65,6 +66,23 @@ async function init() {
invidiousInstanceAddInit(<HTMLElement> optionsElements[i], textChangeOption);
}
break;
case "string-change":
let stringChangeOption = optionsElements[i].getAttribute("sync-option");
let stringInput = <HTMLInputElement> optionsElements[i].querySelector(".string-container").querySelector(".option-text-box");
let saveButton = <HTMLElement> optionsElements[i].querySelector(".option-button");
stringInput.value = Config.config[stringChangeOption];
// Devs can use config.json to set server address
if (stringChangeOption === "customServerAddress") {
stringInput.value = (Config.config.customServerAddress) ? Config.config.customServerAddress : CompileConfig.serverAddress;
}
saveButton.addEventListener("click", () => {
setStringConfigOption(stringInput.value, stringChangeOption);
});
break;
case "keybind-change":
let keybindButton = optionsElements[i].querySelector(".trigger-button");
@@ -80,6 +98,18 @@ async function init() {
optionsContainer.classList.add("animated");
}
/**
* Set the value in the string input the the defined config option
*
* @param element
* @param option
*/
function setStringConfigOption(value: string, option: string) {
console.log(value);
console.log(option);
Config.config[option] = value;
}
/**
* Called when the config is updated
*

View File

@@ -240,7 +240,9 @@ class Utils {
sendRequestToServer(type: string, address: string, callback?: (xmlhttp: XMLHttpRequest, err: boolean) => any) {
let xmlhttp = new XMLHttpRequest();
xmlhttp.open(type, CompileConfig.serverAddress + address, true);
let serverAddress = (Config.config.customServerAddress) ? Config.config.customServerAddress : CompileConfig.serverAddress;
xmlhttp.open(type, serverAddress + address, true);
if (callback != undefined) {
xmlhttp.onreadystatechange = function () {