Skip to content

Instantly share code, notes, and snippets.

@LBBO
Last active March 6, 2021 22:21
Show Gist options
  • Save LBBO/6deeeb250d6e9c432f875b6781a3a2d1 to your computer and use it in GitHub Desktop.
Save LBBO/6deeeb250d6e9c432f875b6781a3a2d1 to your computer and use it in GitHub Desktop.
Bookmarklet to change the speed of any type of media such as voice messages in WhatsApp Web, videos on some web site, ...

How to use this bookmarklet

A bookmarklet is JavaScript code that has been "transformed" into a URL. You can set up a bookmark with the code as its URL and opening the bookmark will then execute the code.

To quickly create the Bookmark, just right-click the bookmarks bar and add a new one. Choose a name and then copy and paste the code from bookmarklet_URL.txt into the location of your new bookmark.

javascript:(function()%7Bconst%20audios%20%3D%20document.querySelectorAll('audio,video,media')%3Bif%20(audios.length)%20%7Bconst%20newSpeedStr%20%3D%20prompt('How%20fast%20do%20you%20want%20the%20media%20to%20be%3F',2)%3Bconst%20newSpeed%20%3D%20parseFloat(newSpeedStr)%3Bif%20(!Number.isNaN(newSpeed)%20%26%26%20newSpeed%20%3E%200)%20%7Baudios.forEach(audio%20%3D%3E%20%7B%20audio.playbackRate%20%3D%20newSpeed%20%7D)%3Bconsole.info(%60Successfully%20changed%20the%20speed%20of%20%24%7Baudios.length%7D%20media!%60)%3B%7D%20else%20%7Balert(%60%24%7BnewSpeedStr%7D%20not%20a%20valid%20speed!%20Please%20enter%20a%20positive%20number%20(preferably%20no%20larger%20than%205)!%60)%3Bconsole.log(%7B%20newSpeedStr%2C%20newSpeed%2C%20audios%20%7D)%3B%7D%7D%20else%20%7Balert('No%20media%20found!')%3B%7D%7D)()
const audios = document.querySelectorAll('audio,video,media');
if (audios.length) {
const newSpeedStr = prompt('How fast do you want the media to be?', 2);
const newSpeed = parseFloat(newSpeedStr);
if (!Number.isNaN(newSpeed) && newSpeed > 0) {
audios.forEach(audio => { audio.playbackRate = newSpeed });
console.info(`Successfully changed the speed of ${audios.length} media!`);
} else {
alert(`${newSpeedStr} not a valid speed! Please enter a positive number (preferably no larger than 5)!`);
console.log({ newSpeedStr, newSpeed, audios });
}
} else {
alert('No media found!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment