Last active
March 7, 2025 16:20
-
-
Save Pakirava-Datsuma/e1bedebc3dbfa5c04442089e5fff74ee to your computer and use it in GitHub Desktop.
beep browser when a new DOM element appears
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
[ | |
["li pre.log-line", "Error", 440], | |
["li pre.log-line", "Warning", 523] | |
].forEach(([selector, targetText, frequency]) => { | |
new MutationObserver(mutations => | |
mutations.forEach(({ addedNodes }) => | |
addedNodes.forEach(node => { | |
if (node.nodeType === 1 && | |
(node.matches?.(selector) || node.querySelector?.(selector)) && | |
node.textContent.includes(targetText)) { | |
console.log(`Matched: "${node.textContent.trim()}"`); | |
const ctx = new (AudioContext || webkitAudioContext)(); | |
const osc = ctx.createOscillator(); | |
osc.type = "sine"; | |
osc.frequency.setValueAtTime(frequency, ctx.currentTime); | |
osc.connect(ctx.destination); | |
osc.start(); | |
setTimeout(() => osc.stop(), 200); | |
} | |
}) | |
) | |
).observe(document.body, { childList: true, subtree: true }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment