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

Feature: Add keyboard shortcut to toggle mute on expando videos #5500

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/modules/keyboardNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ module.options = {
title: 'keyboardNavToggleViewImagesTitle',
callback() { ShowImages.viewImagesButton().click(); },
},
toggleMuteVideo: {
type: 'keycode',
requiresModules: [ShowImages],
value: [77, false, false, false, false], // m
description: 'keyboardNavToggleMuteVideoDesc',
title: 'keyboardNavToggleMuteVideoTitle',
callback() { videoToggleMute(); },
},
toggleChildren: {
type: 'keycode',
include: ['comments', 'inbox'/* mostly modmail */],
Expand Down Expand Up @@ -1172,6 +1180,11 @@ function imageMove(deltaX, deltaY) {
ShowImages.move(mostVisible, deltaX, deltaY);
}

function videoToggleMute() {
const mostVisible = getMostVisibleElementInThingByQuery('.res-video-container', ASSERT);
ShowImages.toggleMute(mostVisible);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be preferable to inline toggleMute. Also we might as well allow toggling mute on any video objects, not only RES's.

Probably something like this:

const video = downcast(getMostVisibleElementInThingByQuery('video', ASSERT), 'video');
video.muted = !video.muted;

Copy link
Contributor Author

@FlaminSarge FlaminSarge Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do the mute-any-video handling in my initial impl but ran into a few hurdles involving how RES determines which entity is in focus; I wasn't too sure how to handle it, so if you have any further details that would be appreciated.

Also, would there be any benefit to leaving toggleMute in ShowImages rather than pulling it out to here? I was under the impression (from the rest of the file) that we tried to limit the amount of logic happening in keyboardNav.js and instead defer logic to the ShowImages module/etc, which is why my impl has it like that, but if it isn't needed, I'll pull the toggleMute logic up to here.

}

function navigateGallery(direction: 'previous' | 'next') {
const gallery = getMostVisibleElementInThingByQuery('.res-gallery', ASSERT);
assertElement(gallery.querySelector(`.res-step-${direction}`)).click();
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/showImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2297,3 +2297,10 @@ export function resize(ele: HTMLElement, newWidth: number, newHeight?: number):
ele.style.width = `${newWidth}px`;
ele.style.maxWidth = ele.style.maxHeight = 'none';
}

export function toggleMute(ele: HTMLElement): void {
const video = downcast(ele.querySelector('video'), HTMLVideoElement);
if (video) {
video.muted = !video.muted;
}
}
6 changes: 6 additions & 0 deletions locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,12 @@
"keyboardNavToggleViewImagesDesc": {
"message": "Toggle \"show images\" button."
},
"keyboardNavToggleMuteVideoTitle": {
"message": "Toggle Mute Video"
},
"keyboardNavToggleMuteVideoDesc": {
"message": "Toggle mute/unmute for a video."
},
"keyboardNavToggleChildrenTitle": {
"message": "Toggle Children"
},
Expand Down