Play Tone

Function to play a sound file by adding an HTML5 audio tag to the document. ver 1.0 2014-09-07.

  1. // ==UserScript==
  2. // @name Play Tone
  3. // @author Jefferson "jscher2000" Scher
  4. // @namespace JeffersonScher
  5. // @description Function to play a sound file by adding an HTML5 audio tag to the document. ver 1.0 2014-09-07.
  6. // @include *
  7. // @version 1.0
  8. // @copyright Copyright 2014 Jefferson Scher
  9. // @license BSD 3-clause
  10. // @grant GM_registerMenuCommand
  11. // ==/UserScript==
  12.  
  13. function playTone(e){
  14. // create audio tag for WAV file
  15. var el = document.createElement("audio");
  16. el.setAttribute("autoplay", "autoplay");
  17. // grab tone file from my site; to avoid mixed content, omit the protocol
  18. el.setAttribute("src", "//www.jeffersonscher.com/gm/snd/A-Tone-His_Self-1266414414.wav");
  19. // add to document body
  20. document.body.appendChild(el);
  21. }
  22. // Add menu item
  23. GM_registerMenuCommand("Play Tone", playTone);