Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- 'use strict';
- function playSound() {
- 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
- audio.play();
- }
- function isLink(element) {
- return element.tagName === 'A';
- }
- function handleNewElements(elements) {
- elements.forEach(function(element) {
- if (isLink(element)) {
- element.addEventListener('mousedown', playSound);
- }
- });
- }
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.type === 'childList') {
- handleNewElements(mutation.addedNodes);
- }
- });
- });
- observer.observe(document.body, { childList: true, subtree: true });
- handleNewElements(document.querySelectorAll('a'));
- })();
Advertisement
Add Comment
Please, Sign In to add comment