1document.addEventListener("DOMContentLoaded", function() { 2 // Select all video elements with the class 'autoplay-video' 3 const videos = document.querySelectorAll('.autoplay-video'); 4 5 // Check if the user prefers reduced motion 6 const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; 7 8 if (localStorage.getItem('videoAutoPlay') === null) { 9 localStorage.setItem('videoAutoPlay', "true"); 10 } 11 12 if (!prefersReducedMotion) { 13 videos.forEach(video => { 14 const playPauseBtn = document.getElementById(video.getAttribute('data-lcu-playpause')); 15 // Try to autoplay each video 16 if(localStorage.getItem('videoAutoPlay') == "true"){ 17 video.play().then(() => { 18 playPauseBtn.classList.add('pause'); 19 document.getElementById(playPauseBtn.getAttribute('data-lcu-textchange')).textContent = 'Pause'; 20 playPauseBtn.setAttribute('aria-label', 'Pause video'); 21 }).catch(error => { 22 console.error('Autoplay was prevented. User interaction is required.', error); 23 }); 24 } 25 26 function togglePlayPause() { 27 if (video.paused || video.ended) { 28 video.play(); 29 playPauseBtn.classList.add('pause'); // Switch icon to pause 30 document.getElementById(playPauseBtn.getAttribute('data-lcu-textchange')).textContent = 'Pause'; 31 playPauseBtn.setAttribute('aria-label', 'Pause video'); 32 localStorage.setItem('videoAutoPlay', "true"); 33 } else { 34 video.pause(); 35 playPauseBtn.classList.remove('pause'); 36 document.getElementById(playPauseBtn.getAttribute('data-lcu-textchange')).textContent = 'Play'; 37 playPauseBtn.setAttribute('aria-label', 'Play video'); 38 localStorage.setItem('videoAutoPlay', "false"); 39 } 40 } 41 42 // Attach event listener to the button 43 playPauseBtn.addEventListener('click', togglePlayPause); 44 45 // Ensure button is accessible via keyboard 46 playPauseBtn.addEventListener('keydown', function(event) { 47 if (event.key === 'Enter' || event.key === ' ') { 48 event.preventDefault(); // Prevent default behavior of space bar scrolling 49 togglePlayPause(); 50 } 51 }); 52 53 // Reset button text when video is paused or ends 54 video.addEventListener('pause', () => { 55 playPauseBtn.classList.remove('pause'); 56 document.getElementById(playPauseBtn.getAttribute('data-lcu-textchange')).textContent = 'Play'; 57 playPauseBtn.setAttribute('aria-label', 'Play video'); 58 }); 59 }); 60 } else { 61 62 } 63 });
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.