Skip to content

Commit

Permalink
Add kbd shortcut to toggle mute on ShowImages videos
Browse files Browse the repository at this point in the history
  • Loading branch information
FlaminSarge authored and larsjohnsen committed Jul 2, 2024
1 parent 1b99cb8 commit e804618
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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);
}

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

0 comments on commit e804618

Please sign in to comment.