-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename AudioPlaybackSpeed to MediaPlaybackSpeed, add Tooltip
- Loading branch information
Showing
7 changed files
with
105 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# AudioPlaybackSpeed | ||
# MediaPlaybackSpeed | ||
|
||
Adds an icon to change the playback speed of voice message and audio embeds | ||
Adds an icon to change the playback speed of media embeds | ||
|
||
![New icon with menu to change the playback speed](https://github.com/Vendicated/Vencord/assets/24937357/21792b09-8d6a-45be-a6e8-916cdd67a477) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Vencord, a Discord client mod | ||
* Copyright (c) 2024 Vendicated and contributors | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import "./styles.css"; | ||
|
||
import { classNameFactory } from "@api/Styles"; | ||
import { makeRange } from "@components/PluginSettings/components"; | ||
import { Devs } from "@utils/constants"; | ||
import definePlugin from "@utils/types"; | ||
import { ContextMenuApi, FluxDispatcher, Menu, React, Tooltip } from "@webpack/common"; | ||
import { RefObject } from "react"; | ||
|
||
import SpeedIcon from "./components/SpeedIcon"; | ||
|
||
const cl = classNameFactory("vc-media-playback-speed-"); | ||
|
||
const speeds = makeRange(0.25, 3.5, 0.25); | ||
|
||
export default definePlugin({ | ||
name: "MediaPlaybackSpeed", | ||
description: "Adds an icon to change the playback speed of media embeds", | ||
authors: [Devs.D3SOX], | ||
|
||
playbackSpeedComponent(mediaRef: RefObject<HTMLMediaElement>) { | ||
const changeSpeed = (speed: number) => { | ||
const media = mediaRef.current; | ||
if (media) { | ||
media.playbackRate = speed; | ||
} | ||
}; | ||
|
||
return ( | ||
<Tooltip text="Playback speed"> | ||
{({ onMouseEnter, onMouseLeave }) => ( | ||
<button | ||
className={cl("icon")} | ||
onMouseEnter={onMouseEnter} | ||
onMouseLeave={onMouseLeave} | ||
onClick={e => { | ||
ContextMenuApi.openContextMenu(e, () => | ||
<Menu.Menu | ||
navId="playback-speed" | ||
onClose={() => FluxDispatcher.dispatch({ type: "CONTEXT_MENU_CLOSE" })} | ||
aria-label="Playback speed control" | ||
> | ||
<Menu.MenuGroup | ||
label="Playback speed" | ||
> | ||
{speeds.map(speed => ( | ||
<Menu.MenuItem | ||
key={speed} | ||
id={"speed-" + speed} | ||
label={`${speed}x`} | ||
action={() => changeSpeed(speed)} | ||
/> | ||
))} | ||
</Menu.MenuGroup> | ||
</Menu.Menu> | ||
); | ||
}}> | ||
<SpeedIcon/> | ||
</button> | ||
)} | ||
</Tooltip> | ||
); | ||
}, | ||
|
||
patches: [ | ||
// voice message embeds | ||
{ | ||
find: "ComponentActions.VOICE_MESSAGE_PLAYBACK_STARTED", | ||
replacement: { | ||
match: /useCallback\(\(\)=>\{let \i=(\i).current;.{2300,3000}onVolumeShow:\i,onVolumeHide:\i\}\)/, | ||
replace: "$&,$self.playbackSpeedComponent($1)" | ||
} | ||
}, | ||
// audio & video embeds | ||
{ | ||
// need to pass media ref via props to make it easily accessible from inside controls | ||
find: "renderControls(){", | ||
replacement: { | ||
match: /onToggleMuted:this.toggleMuted,/, | ||
replace: "$&mediaRef:this.mediaRef," | ||
} | ||
}, | ||
{ | ||
find: "AUDIO:\"AUDIO\"", | ||
replacement: { | ||
match: /onVolumeHide:\i,iconClassName:\i.controlIcon,sliderWrapperClassName:\i.volumeSliderWrapper\}\)\}\),/, | ||
replace: "$&$self.playbackSpeedComponent(this.props.mediaRef)," | ||
} | ||
} | ||
] | ||
}); |
4 changes: 2 additions & 2 deletions
4
audioPlaybackSpeed/styles.css → mediaPlaybackSpeed/styles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
.vc-audio-playback-speed-icon { | ||
.vc-media-playback-speed-icon { | ||
background-color: transparent; | ||
height: 100%; | ||
z-index: 2; | ||
color: var(--interactive-normal); | ||
} | ||
|
||
.vc-audio-playback-speed-icon:hover { | ||
.vc-media-playback-speed-icon:hover { | ||
color: var(--interactive-active); | ||
} |