Advertisement
Guest User

Ye Olde Autoplayer - hosma

a guest
Mar 17th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Should probably make sure that everything has been loaded.
  2. window.addEventListener('load', () => {
  3.   // Now then, when the user clicks anywhere on the page...
  4.   document.addEventListener('click', () => {
  5.     // We go through all the <audio autoplay> elements...
  6.     for (const audio of document.querySelectorAll('[autoplay]')) {
  7.       audio.volume = .5 // We don't kill the user... (optional)
  8.       audio.play() // And finally bless their ears!
  9.     }
  10.   }, { passive: true, once: true }) // `once` for making this only fire once.
  11. }, { passive: true }) // `passive` for some slight optimisation magic.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement