mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
Added spacing and separated code into a function
This commit is contained in:
@@ -318,18 +318,23 @@ function activateKeybindChange(element: HTMLElement) {
|
||||
*/
|
||||
function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) {
|
||||
var key = e.key;
|
||||
|
||||
if (["Shift", "Control", "Meta", "Alt", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Tab"].indexOf(key) !== -1) {
|
||||
|
||||
// Wait for more
|
||||
document.addEventListener("keydown", (e) => keybindKeyPressed(element, e), {once: true});
|
||||
} else {
|
||||
let button = element.querySelector(".trigger-button");
|
||||
let button: HTMLElement = element.querySelector(".trigger-button");
|
||||
let option = element.getAttribute("sync-option");
|
||||
|
||||
// Don't allow keys which are already listened for by youtube
|
||||
let restrictedKeys = "1234567890,.jklftcibmJKLFTCIBMNP/<> -+";
|
||||
if (restrictedKeys.indexOf(key) !== -1 ) {
|
||||
element.querySelector(".option-hidden-section").classList.add("hidden");
|
||||
button.classList.remove("disabled");
|
||||
closeKeybindOption(element, button);
|
||||
|
||||
// TODO: This should be localised
|
||||
alert("The key " + key + " is already used by youtube. Please select another key.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -337,20 +342,21 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) {
|
||||
// TODO: If other keybindings are going to be added, we need a better way to find the other keys used.
|
||||
let otherKeybind = (option === "startSponsorKeybind") ? Config.config['submitKeybind'] : Config.config['startSponsorKeybind'];
|
||||
if (key === otherKeybind) {
|
||||
element.querySelector(".option-hidden-section").classList.add("hidden");
|
||||
button.classList.remove("disabled");
|
||||
closeKeybindOption(element, button);
|
||||
|
||||
// TODO: This should be localised
|
||||
alert("The key " + key + " is bound to another action. Please select another key.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// cancel setting a keybind
|
||||
if (key === "Escape") {
|
||||
element.querySelector(".option-hidden-section").classList.add("hidden");
|
||||
button.classList.remove("disabled");
|
||||
closeKeybindOption(element, button);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Config.config[option] = key;
|
||||
|
||||
let status = <HTMLElement> element.querySelector(".option-hidden-section > .keybind-status");
|
||||
@@ -363,6 +369,17 @@ function keybindKeyPressed(element: HTMLElement, e: KeyboardEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the menu for editing the keybind
|
||||
*
|
||||
* @param element
|
||||
* @param button
|
||||
*/
|
||||
function closeKeybindOption(element: HTMLElement, button: HTMLElement) {
|
||||
element.querySelector(".option-hidden-section").classList.add("hidden");
|
||||
button.classList.remove("disabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Will trigger the textbox to appear to be able to change an option's text.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user