-
-
Save git2358/7a4e4c774f1f1d4cb2da6804e26334c0 to your computer and use it in GitHub Desktop.
Listen to your web pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const audioCtx = new window.AudioContext(); | |
| const oscillator = audioCtx.createOscillator(); | |
| oscillator.connect(audioCtx.destination); | |
| oscillator.type = "sine"; | |
| let numItems = 0 | |
| oscillator.frequency.setValueAtTime( | |
| 1, | |
| audioCtx.currentTime | |
| ); | |
| oscillator.start(); | |
| const observer = new MutationObserver(function (mutationsList) { | |
| numItems += mutationsList.length | |
| oscillator.frequency.setValueAtTime( | |
| Math.log(numItems + 1) * 440, | |
| audioCtx.currentTime | |
| ); | |
| setTimeout(() => { | |
| numItems -= mutationsList.length | |
| if (numItems === 0) { | |
| oscillator.frequency.setValueAtTime( | |
| 1, | |
| audioCtx.currentTime | |
| ) | |
| } else { | |
| oscillator.frequency.setValueAtTime( | |
| Math.log(numItems + 1) * 440, | |
| audioCtx.currentTime | |
| ) | |
| } | |
| }, 100) | |
| }); | |
| observer.observe(document, { | |
| attributes: true, | |
| childList: true, | |
| subtree: true, | |
| characterData: true | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment