From dd08ff1507b154a9190f4ee348134c1a66374cc2 Mon Sep 17 00:00:00 2001 From: Joe Dowd Date: Fri, 7 Feb 2020 00:40:01 +0000 Subject: [PATCH 1/9] add custom server address --- public/_locales/en/messages.json | 9 +++++++++ public/options/options.css | 5 +++++ public/options/options.html | 19 +++++++++++++++++++ src/config.ts | 6 ++++-- src/options.ts | 30 ++++++++++++++++++++++++++++++ src/utils.ts | 4 +++- 6 files changed, 70 insertions(+), 3 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 51017402..712c577f 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -213,6 +213,15 @@ "whatDeleteButton": { "message": "This is the button that allows you to clear all sponsors on the YouTube player." }, + "customServerAddress": { + "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." + }, + "saveCustomServerAddress": { + "message": "Save" + }, "disableViewTracking": { "message": "Disable Sponsor Skip Count Tracking" }, diff --git a/public/options/options.css b/public/options/options.css index 7cfa094e..411dce58 100644 --- a/public/options/options.css +++ b/public/options/options.css @@ -76,6 +76,11 @@ body { color: white; } +.string-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 0e7c155f..1fc7a8a1 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -93,6 +93,25 @@

+ +
+ +
+ __MSG_saveCustomServerAddress__ +
+ +
+
+ +
__MSG_customServerAddressDescription__
+
+ +
+
+
diff --git a/src/config.ts b/src/config.ts index a77a3807..486bfdb0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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 diff --git a/src/options.ts b/src/options.ts index 437373f1..4cd37e12 100644 --- a/src/options.ts +++ b/src/options.ts @@ -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( optionsElements[i], textChangeOption); } + break; + case "string-change": + let stringChangeOption = optionsElements[i].getAttribute("sync-option"); + let stringInput = optionsElements[i].querySelector(".string-container").querySelector(".option-text-box"); + let saveButton = 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 * diff --git a/src/utils.ts b/src/utils.ts index e19e4ca9..29240dd0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 () { From 3455a79298623887056154cb76f79a50a84cb8e3 Mon Sep 17 00:00:00 2001 From: Joe Dowd Date: Fri, 7 Feb 2020 00:57:24 +0000 Subject: [PATCH 2/9] Removed console.log calls --- src/options.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/options.ts b/src/options.ts index 4cd37e12..14f5c942 100644 --- a/src/options.ts +++ b/src/options.ts @@ -105,8 +105,6 @@ async function init() { * @param option */ function setStringConfigOption(value: string, option: string) { - console.log(value); - console.log(option); Config.config[option] = value; } From 62653705ff786a32b3ef01519b271a3c451d67c7 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 8 Feb 2020 21:27:55 -0500 Subject: [PATCH 3/9] Improved custom instance message --- public/_locales/en/messages.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index 260cde5d..0670b16d 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -213,15 +213,6 @@ "whatDeleteButton": { "message": "This is the button that allows you to clear all sponsors on the YouTube player." }, - "customServerAddress": { - "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." - }, - "saveCustomServerAddress": { - "message": "Save" - }, "disableViewTracking": { "message": "Disable Sponsor Skip Count Tracking" }, @@ -404,5 +395,14 @@ }, "shortCheck": { "message": "The following submission is shorter than your minimum duration option. This could mean that this is already submitted, and just being ignored due to this option. Are you sure you would like to submit?" + }, + "customServerAddress": { + "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." + }, + "saveCustomServerAddress": { + "message": "Save" } } From 6f03c68fdc0ebf7e839b2c064344210068471a0b Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 8 Feb 2020 21:30:57 -0500 Subject: [PATCH 4/9] Change the way server address defaults are handled. --- src/config.ts | 6 ++++-- src/options.ts | 6 ------ src/utils.ts | 5 +---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/config.ts b/src/config.ts index 63c482ff..d9ef6d57 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, @@ -20,7 +22,7 @@ interface SBConfig { invidiousUpdateInfoShowCount: number, autoUpvote: boolean, supportInvidious: false, - customServerAddress: string, + serverAddress: string, minDuration: number } @@ -114,7 +116,7 @@ var Config: SBObject = { invidiousUpdateInfoShowCount: 0, autoUpvote: true, supportInvidious: false, - customServerAddress: null, + serverAddress: CompileConfig.serverAddress, minDuration: 0 }, localConfig: null, diff --git a/src/options.ts b/src/options.ts index 8d96f4f0..06528a02 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,5 +1,4 @@ import Config from "./config"; -import * as CompileConfig from "../config.json"; import Utils from "./utils"; var utils = new Utils(); @@ -73,11 +72,6 @@ async function init() { let saveButton = 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); diff --git a/src/utils.ts b/src/utils.ts index 29240dd0..b4d4e639 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 { @@ -240,9 +239,7 @@ class Utils { sendRequestToServer(type: string, address: string, callback?: (xmlhttp: XMLHttpRequest, err: boolean) => any) { let xmlhttp = new XMLHttpRequest(); - let serverAddress = (Config.config.customServerAddress) ? Config.config.customServerAddress : CompileConfig.serverAddress; - - xmlhttp.open(type, serverAddress + address, true); + xmlhttp.open(type, Config.config.serverAddress + address, true); if (callback != undefined) { xmlhttp.onreadystatechange = function () { From 4e7bfa5ed318a1fe3661bb5d410066d10c424bcb Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 8 Feb 2020 21:32:46 -0500 Subject: [PATCH 5/9] Changed server address config name --- public/options/options.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/options/options.html b/public/options/options.html index 196dfc79..1a2e1e7f 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -94,7 +94,7 @@

-
+
- +

- -
-
From be6cd62fbebc0a00fb8b4e17189ce3e179950534 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 8 Feb 2020 21:42:15 -0500 Subject: [PATCH 7/9] Rename string change option to more fitting name. --- public/options/options.css | 2 +- public/options/options.html | 14 ++++++----- src/options.ts | 47 +++++++++++++++---------------------- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/public/options/options.css b/public/options/options.css index 0b10a3f9..b80bf116 100644 --- a/public/options/options.css +++ b/public/options/options.css @@ -76,7 +76,7 @@ body { color: white; } -.string-container { +.text-label-container { font-size: 14px; color: white; } diff --git a/public/options/options.html b/public/options/options.html index b778acad..b2a03ddc 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -248,7 +248,7 @@

-
+
__MSG_changeUserID__
@@ -274,13 +274,15 @@

-
-