Inject script to play audio file if InnerText does not match string

132 views Asked by At

I need to monitor a webpage for new events. The page shows a string ("No events") if no events are available. This page reloads automatically every minute. This page will often be in the background, but I wan't to be notified events are available, because I need to respond to them.

This is what I've come up with so far, and this works. I use the Chrome "Custom JavaScript for websites" to run the below code.

var element = document.getElementById('queue').innerText;
if (element !== "No events") {
    window.alert("ALARM!ALARM!");
}

However, instead of a alert popup, I would like a local audio file to play.

1

There are 1 answers

0
Saravana Kumar On BEST ANSWER

Use This.

var element = document.getElementById('queue').innerText;
if (element != "No events") 
{
    var audio = new Audio('AAA.mp3');
    audio.play();
}

Note:

The extension of your audio(.mp3) and the associated content types must be added in MIME types in IIS