Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to disable website keybindings for show/hide controller (Fixes: #526) #533

Conversation

thewheat
Copy link
Contributor

  • Adding the select dropdown to allow disabling website keybinds for the "Show/hide controller" option similar to the other keybindings
  • it only shows when clicking "show experimental features"
    image

Demo
Demo of it showing only after clicking "show experimental features" and of it being able to persist on saving
show-hide

@thrashbun
Copy link
Collaborator

This looks nice, thanks for the work. But I am left wondering why show/hide is treated differently from every other feature. I would prefer a small refactor from the original to just treat show/hide like everything else. It seems like this was explicitly not done in #350. Do you have any ideas why? @igrigorik @canarslan12

@igrigorik
Copy link
Owner

@jacobcolbert scratching my head as well, I think this was an oversight as I don't recall any specific reason why we decided to specifically omit this feature. Also, +1 to your recommendation on refactor.

@thewheat
Copy link
Contributor Author

Cool. By refactor just meaning to make it styled like the rest with

  • Show/hide controller as a form select input
  • And for the non customizable input to be disabled?

image

@thrashbun
Copy link
Collaborator

thrashbun commented Oct 17, 2019

In terms of external behavior, yes that is exactly what I mean.

In the code I mean that show/hide is treated by itself as an exceptional case while every other feature is treated uniformly. Specifically, in options.html it is implemented as <div class="row"> rather than <div class="row customs">` like all of the following features. And in the options.js it is not included as an option in the dropdown.

The code should treat all of these features the same, so that if we change things in the future it will automatically affect all of them equivalently.

@thewheat
Copy link
Contributor Author

I think I've got all that needs to be implemented but let me know if I missed anything!

I also tried to ensure that any custom bindings are carried across in the upgrade.

image

Can disable website bindings
image

@igrigorik
Copy link
Owner

Nice! I think this looks good now, nice touch on custom bindings carryover..

@jacobcolbert any feedback before we merge?

@thrashbun thrashbun merged commit ec9f3f6 into igrigorik:master Oct 20, 2019
@thrashbun
Copy link
Collaborator

Looks great to me. Gonna fix some indentation errors that were already there.

Very nice touch on carrying over the custom bindings. Would prolly have missed that myself. Can that code be removed in the next version after this is pushed live?

@thewheat
Copy link
Contributor Author

Hmmm that's a good question.

I think the part in inject.js should be kept

videospeed/inject.js

Lines 93 to 101 in 29788ba

if (tc.settings.keyBindings.filter(x => x.action == "display").length == 0) {
tc.settings.keyBindings.push({
action: "display",
key: Number(storage.displayKeyCode) || 86,
value: 0,
force: false,
predefined: true
}); // default V
}

It is similar to the current code to initialize the other shortcuts

videospeed/inject.js

Lines 26 to 71 in 29788ba

if (storage.keyBindings.length == 0) // if first initialization of 0.5.3
{
// UPDATE
tc.settings.keyBindings.push({
action: "slower",
key: Number(storage.slowerKeyCode) || 83,
value: Number(storage.speedStep) || 0.1,
force: false,
predefined: true
}); // default S
tc.settings.keyBindings.push({
action: "faster",
key: Number(storage.fasterKeyCode) || 68,
value: Number(storage.speedStep) || 0.1,
force: false,
predefined: true
}); // default: D
tc.settings.keyBindings.push({
action: "rewind",
key: Number(storage.rewindKeyCode) || 90,
value: Number(storage.rewindTime) || 10,
force: false,
predefined: true
}); // default: Z
tc.settings.keyBindings.push({
action: "advance",
key: Number(storage.advanceKeyCode) || 88,
value: Number(storage.advanceTime) || 10,
force: false,
predefined: true
}); // default: X
tc.settings.keyBindings.push({
action: "reset",
key: Number(storage.resetKeyCode) || 82,
value: 1.0,
force: false,
predefined: true
}); // default: R
tc.settings.keyBindings.push({
action: "fast",
key: Number(storage.fastKeyCode) || 71,
value: Number(storage.fastSpeed) || 1.8,
force: false,
predefined: true
}); // default: G
tc.settings.version = "0.5.3";


The options.js change is dependent if a storage.keyBindings has been saved after the update as that is when the new display action is set via save_options.

Then we can remove this line

videospeed/options.js

Lines 187 to 190 in 29788ba

// ensure that there is a "display" binding for upgrades from versions that had it as a separate binding
if(storage.keyBindings.filter(x => x.action == "display").length == 0){
storage.keyBindings.push({ action: "display", value: 0, force: false, predefined: true });
}

And also this following one as item["key"] would be defined

videospeed/options.js

Lines 197 to 199 in 29788ba

if (item["action"] == "display" && typeof (item["key"]) === "undefined"){
item["key"] = storage.displayKeyCode || tcDefaults.displayKeyCode; // V
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants