Audible Notification API

Plays an audio when a browser notification is shown. This script should be applied only for specific sites, since some sites may already have an audible notification. So, once the script is installed, change the @match metadata.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Audible Notification API
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @license      GNU AGPLv3
// @description  Plays an audio when a browser notification is shown. This script should be applied only for specific sites, since some sites may already have an audible notification. So, once the script is installed, change the @match metadata.
// @author       jcunews
// @match        *://thesite.com/*
// @match        *://othersite.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function(ntf, aud) {

  //== CONFIGURATION BEGIN ===

  var audioUrl = "https://soundbible.com/grab.php?id=1952&type=mp3";

  //== CONFIGURATION BEGIN ===

  ntf = window.Notification;
  Notification = function(title, options) {
    aud.pause();
    aud.autoplay = false;
    aud.muted = false;
    if (aud.fastSeek) {
      aud.fastSeek(0);
    } else aud.currentTime = 0;
    aud.play();
    return new ntf(title, options);
  };
  Notification.prototype = {
    onclick: {
      get: function() {
        return ntf.onclick;
      },
      set: function(f) {
        return ntf.onclick = f;
      }
    },
    onclose: {
      get: function() {
        return ntf.onclose;
      },
      set: function(f) {
        return ntf.onclose = f;
      }
    },
    onerror: {
      get: function() {
        return ntf.onerror;
      },
      set: function(f) {
        return ntf.onerror = f;
      }
    },
    onshow: {
      get: function() {
        return ntf.onshow;
      },
      set: function(f) {
        return ntf.onshow = f;
      }
    }
  };
  Notification.requestPermission = function() {
    return ntf.requestPermission.apply(ntf, arguments);
  };

  aud = new Audio(audioUrl);
  aud.autoplay = true;
  aud.muted = true;
  aud.style.display = "none!important";
  addEventListener("load", function() {
    document.body.appendChild(aud);
  });
})();