mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-09-20 04:53:43 +02:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into typescript
# Conflicts: # public/_locales/en/messages.json # src/config.ts
This commit is contained in:
commit
6159605afd
6 changed files with 132 additions and 20 deletions
|
@ -401,5 +401,23 @@
|
||||||
},
|
},
|
||||||
"whatUploadButton": {
|
"whatUploadButton": {
|
||||||
"message": "This button appears on the YouTube player after you have selected a timestamp and are ready to submit."
|
"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?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,11 @@ body {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-label-container {
|
||||||
|
font-size: 14px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
.switch {
|
.switch {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
|
@ -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>
|
||||||
|
@ -93,7 +93,8 @@
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
|
||||||
<div option-type="keybind-change" sync-option="startSponsorKeybind">
|
<div option-type="keybind-change" sync-option="startSponsorKeybind">
|
||||||
<div class="option-button trigger-button">
|
<div class="option-button trigger-button">
|
||||||
__MSG_setStartSponsorShortcut__
|
__MSG_setStartSponsorShortcut__
|
||||||
|
@ -146,6 +147,18 @@
|
||||||
|
|
||||||
<div class="small-description">__MSG_minDurationDescription__</div>
|
<div class="small-description">__MSG_minDurationDescription__</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div option-type="toggle" toggle-type="reverse" sync-option="dontShowNotice">
|
||||||
|
<label class="switch-container" label-name="__MSG_showSkipNotice__">
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" checked>
|
||||||
|
<span class="slider round"></span>
|
||||||
|
</label>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -252,7 +265,7 @@
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<div option-type="text-change" sync-option="userID" confirm-message="userIDChangeWarning">
|
<div option-type="private-text-change" sync-option="userID" confirm-message="userIDChangeWarning">
|
||||||
<div class="option-button trigger-button">
|
<div class="option-button trigger-button">
|
||||||
__MSG_changeUserID__
|
__MSG_changeUserID__
|
||||||
</div>
|
</div>
|
||||||
|
@ -274,19 +287,31 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<div option-type="toggle" toggle-type="reverse" sync-option="dontShowNotice">
|
<div option-type="text-change" sync-option="serverAddress">
|
||||||
<label class="switch-container" label-name="__MSG_showSkipNotice__">
|
<label class="text-label-container">
|
||||||
<label class="switch">
|
<div>__MSG_customServerAddress__</div>
|
||||||
<input type="checkbox" checked>
|
|
||||||
<span class="slider round"></span>
|
<input class="option-text-box" type="text">
|
||||||
</label>
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<div class="option-button text-change-set inline">
|
||||||
|
__MSG_save__
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="option-button text-change-reset inline">
|
||||||
|
__MSG_reset__
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<div class="small-description">__MSG_customServerAddressDescription__</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import * as CompileConfig from "../config.json";
|
||||||
|
|
||||||
interface SBConfig {
|
interface SBConfig {
|
||||||
userID: string,
|
userID: string,
|
||||||
sponsorTimes: SBMap<string, any>,
|
sponsorTimes: SBMap<string, any>,
|
||||||
|
@ -21,6 +23,7 @@ interface SBConfig {
|
||||||
invidiousUpdateInfoShowCount: number,
|
invidiousUpdateInfoShowCount: number,
|
||||||
autoUpvote: boolean,
|
autoUpvote: boolean,
|
||||||
supportInvidious: boolean,
|
supportInvidious: boolean,
|
||||||
|
serverAddress: string,
|
||||||
minDuration: number
|
minDuration: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +118,7 @@ var Config: SBObject = {
|
||||||
invidiousUpdateInfoShowCount: 0,
|
invidiousUpdateInfoShowCount: 0,
|
||||||
autoUpvote: true,
|
autoUpvote: true,
|
||||||
supportInvidious: false,
|
supportInvidious: false,
|
||||||
|
serverAddress: CompileConfig.serverAddress,
|
||||||
minDuration: 0
|
minDuration: 0
|
||||||
},
|
},
|
||||||
localConfig: null,
|
localConfig: null,
|
||||||
|
|
|
@ -55,14 +55,51 @@ async function init() {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "text-change":
|
case "text-change":
|
||||||
let button = optionsElements[i].querySelector(".trigger-button");
|
|
||||||
button.addEventListener("click", () => activateTextChange(<HTMLElement> optionsElements[i]));
|
|
||||||
|
|
||||||
let textChangeOption = optionsElements[i].getAttribute("sync-option");
|
let textChangeOption = optionsElements[i].getAttribute("sync-option");
|
||||||
|
let textChangeInput = <HTMLInputElement> optionsElements[i].querySelector(".option-text-box");
|
||||||
|
|
||||||
|
let textChangeSetButton = <HTMLElement> 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 = <HTMLElement> 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(<HTMLElement> optionsElements[i]));
|
||||||
|
|
||||||
|
let privateTextChangeOption = optionsElements[i].getAttribute("sync-option");
|
||||||
// See if anything extra must be done
|
// See if anything extra must be done
|
||||||
switch (textChangeOption) {
|
switch (privateTextChangeOption) {
|
||||||
case "invidiousInstances":
|
case "invidiousInstances":
|
||||||
invidiousInstanceAddInit(<HTMLElement> optionsElements[i], textChangeOption);
|
invidiousInstanceAddInit(<HTMLElement> optionsElements[i], privateTextChangeOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -283,7 +320,7 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) {
|
||||||
*
|
*
|
||||||
* @param element
|
* @param element
|
||||||
*/
|
*/
|
||||||
function activateTextChange(element: HTMLElement) {
|
function activatePrivateTextChange(element: HTMLElement) {
|
||||||
let button = element.querySelector(".trigger-button");
|
let button = element.querySelector(".trigger-button");
|
||||||
if (button.classList.contains("disabled")) return;
|
if (button.classList.contains("disabled")) return;
|
||||||
|
|
||||||
|
@ -312,3 +349,27 @@ function activateTextChange(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;
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
import * as CompileConfig from "../config.json";
|
|
||||||
import Config from "./config";
|
import Config from "./config";
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
@ -241,7 +240,7 @@ class Utils {
|
||||||
sendRequestToServer(type: string, address: string, callback?: (xmlhttp: XMLHttpRequest, err: boolean) => any) {
|
sendRequestToServer(type: string, address: string, callback?: (xmlhttp: XMLHttpRequest, err: boolean) => any) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
xmlhttp.open(type, CompileConfig.serverAddress + address, true);
|
xmlhttp.open(type, Config.config.serverAddress + address, true);
|
||||||
|
|
||||||
if (callback != undefined) {
|
if (callback != undefined) {
|
||||||
xmlhttp.onreadystatechange = function () {
|
xmlhttp.onreadystatechange = function () {
|
||||||
|
|
Loading…
Reference in a new issue