Skip to content

Instantly share code, notes, and snippets.

@s-gbz
Forked from LBBO/README.md
Created October 19, 2020 08:20
Show Gist options
  • Save s-gbz/9a9b76e15fd422d30bb595c74eab87c9 to your computer and use it in GitHub Desktop.
Save s-gbz/9a9b76e15fd422d30bb595c74eab87c9 to your computer and use it in GitHub Desktop.
Bookmarklet to change the speed of voice messages in WhatsApp Web (or any website, really...)

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 past the code from bookmarklet_URL.txt into the location of your new bookmark.

javascript:(function()%7Bconst%20audios%20%3D%20document.querySelectorAll('audio')%3Bif%20(audios.length)%20%7Bconst%20newSpeedStr%20%3D%20prompt('How%20fast%20do%20you%20want%20the%20voice%20message%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%20voice%20messages!%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%20voice%20messages%20found!')%3B%7D%7D)()
const audios = document.querySelectorAll('audio');
if (audios.length) {
const newSpeedStr = prompt('How fast do you want the voice message 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} voice messages!`);
} 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 voice messages found!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment