-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSounds.js
More file actions
27 lines (22 loc) · 886 Bytes
/
Copy pathSounds.js
File metadata and controls
27 lines (22 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const clickSound = new Audio("Sounds/Click_WindowsMediaCenter.wav"); // path to your sound
clickSound.volume = 0.5; // adjust if too loud or quiet
// Play sound for every click on the page
document.addEventListener("click", (event) => {
// Ignore clicks on audio or video elements
if (event.target.closest("audio") || event.target.closest("video")) return;
clickSound.currentTime = 0;
clickSound.play().catch(() => {});
});
// Add a small delay for links so the sound plays before the page changes
document.addEventListener("click", (event) => {
const link = event.target.closest("a");
if (link && link.href && !link.target) {
event.preventDefault();
const href = link.href;
clickSound.currentTime = 0;
clickSound.play();
setTimeout(() => {
window.location.href = href;
}, 200); // adjust timing if needed
}
});