lukewt1017

play sounds when navigating in firefox

Mar 1st, 2024 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | Source Code | 0 0
  1. (function() {
  2. 'use strict';
  3.  
  4. function playSound() {
  5. var audio = new Audio('https://archive.org/download/windows-7-windows-media-Default-Sound/Media/Windows%20Navigation%20Start.wav'); // you can use this script anywhere, just change the url of the sound above
  6. audio.play();
  7. }
  8.  
  9. function isLink(element) {
  10. return element.tagName === 'A';
  11. }
  12.  
  13. function handleNewElements(elements) {
  14. elements.forEach(function(element) {
  15. if (isLink(element)) {
  16. element.addEventListener('mousedown', playSound);
  17. }
  18. });
  19. }
  20.  
  21. var observer = new MutationObserver(function(mutations) {
  22. mutations.forEach(function(mutation) {
  23. if (mutation.type === 'childList') {
  24. handleNewElements(mutation.addedNodes);
  25. }
  26. });
  27. });
  28.  
  29. observer.observe(document.body, { childList: true, subtree: true });
  30.  
  31. handleNewElements(document.querySelectorAll('a'));
  32. })();
  33.  
Advertisement
Add Comment
Please, Sign In to add comment