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.

目前為 2018-12-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Audible Notification API
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @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) {
    if (!aud.parentNode) document.body.appendChild(aud);
    aud.pause();
    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);
})();