mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Added server address input validation.
This commit is contained in:
@@ -400,9 +400,12 @@
|
|||||||
"message": "SponsorBlock Server Address"
|
"message": "SponsorBlock Server Address"
|
||||||
},
|
},
|
||||||
"customServerAddressDescription": {
|
"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": {
|
"saveCustomServerAddress": {
|
||||||
"message": "Save"
|
"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."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<div option-type="text-change" sync-option="invidiousInstances">
|
<div option-type="private-text-change" sync-option="invidiousInstances">
|
||||||
<div class="option-button trigger-button">
|
<div class="option-button trigger-button">
|
||||||
__MSG_addInvidiousInstance__
|
__MSG_addInvidiousInstance__
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -63,6 +63,20 @@ async function init() {
|
|||||||
textInput.value = Config.config[textChangeOption];
|
textInput.value = Config.config[textChangeOption];
|
||||||
|
|
||||||
setButton.addEventListener("click", () => {
|
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;
|
Config.config[textChangeOption] = textInput.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -325,3 +339,27 @@ function activatePrivateTextChange(element: HTMLElement) {
|
|||||||
|
|
||||||
element.querySelector(".option-hidden-section").classList.remove("hidden");
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user