Greasy Fork is available in English.

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.

  1. // ==UserScript==
  2. // @name Audible Notification API
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.4
  5. // @license GNU AGPLv3
  6. // @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.
  7. // @author jcunews
  8. // @match *://thesite.com/*
  9. // @match *://othersite.com/*
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function(ntf, aud) {
  15.  
  16. //== CONFIGURATION BEGIN ===
  17.  
  18. var audioUrl = "https://soundbible.com/grab.php?id=1952&type=mp3";
  19.  
  20. //== CONFIGURATION BEGIN ===
  21.  
  22. ntf = window.Notification;
  23. Notification = function(title, options) {
  24. aud.pause();
  25. aud.autoplay = false;
  26. aud.muted = false;
  27. if (aud.fastSeek) {
  28. aud.fastSeek(0);
  29. } else aud.currentTime = 0;
  30. aud.play();
  31. return new ntf(title, options);
  32. };
  33. Notification.prototype = {
  34. onclick: {
  35. get: function() {
  36. return ntf.onclick;
  37. },
  38. set: function(f) {
  39. return ntf.onclick = f;
  40. }
  41. },
  42. onclose: {
  43. get: function() {
  44. return ntf.onclose;
  45. },
  46. set: function(f) {
  47. return ntf.onclose = f;
  48. }
  49. },
  50. onerror: {
  51. get: function() {
  52. return ntf.onerror;
  53. },
  54. set: function(f) {
  55. return ntf.onerror = f;
  56. }
  57. },
  58. onshow: {
  59. get: function() {
  60. return ntf.onshow;
  61. },
  62. set: function(f) {
  63. return ntf.onshow = f;
  64. }
  65. }
  66. };
  67. Notification.requestPermission = function() {
  68. return ntf.requestPermission.apply(ntf, arguments);
  69. };
  70.  
  71. aud = new Audio(audioUrl);
  72. aud.autoplay = true;
  73. aud.muted = true;
  74. aud.style.display = "none!important";
  75. addEventListener("load", function() {
  76. document.body.appendChild(aud);
  77. });
  78. })();