diff --git a/lib/modules/keyboardNav.js b/lib/modules/keyboardNav.js index 87f960338d..8db31e0cf2 100644 --- a/lib/modules/keyboardNav.js +++ b/lib/modules/keyboardNav.js @@ -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 */], @@ -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(); diff --git a/lib/modules/showImages.js b/lib/modules/showImages.js index ae99e561b4..647243b69d 100644 --- a/lib/modules/showImages.js +++ b/lib/modules/showImages.js @@ -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; + } +} diff --git a/locales/locales/en.json b/locales/locales/en.json index ee83b04370..e6314155aa 100644 --- a/locales/locales/en.json +++ b/locales/locales/en.json @@ -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" },