Custom Message Tones

Adds options to load in custom tones when a message is received.

当前为 2016-05-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Custom Message Tones
  3. // @namespace PXgamer
  4. // @version 0.3
  5. // @description Adds options to load in custom tones when a message is received.
  6. // @author PXgamer
  7. // @include *kat.cr/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.  
  13. var AUDIO_FILE = "";
  14.  
  15. // Do Not Edit Below Here
  16. var acMethod = jQuery.fn.addClass;
  17. var audio1;
  18.  
  19. jQuery.fn.addClass = function() {
  20. var result = acMethod.apply(this, arguments);
  21.  
  22. jQuery(this).trigger('cssClassChanged');
  23.  
  24. return result;
  25. };
  26.  
  27. $('body').append('<span id="chatMsgHandler"></span>');
  28. $('#chatMsgHandler').css('display', 'none');
  29. $(document).on('cssClassChanged', function() {
  30. var msgBarElem = $('.chat-bar-new');
  31. if (msgBarElem.length > 0) {
  32. audio1.play();
  33. }
  34. });
  35.  
  36. var audioTypes = {
  37. "mp3": "audio/mpeg",
  38. "ogg": "audio/ogg",
  39. "wav": "audio/wav"
  40. };
  41.  
  42. function pxS(sound) {
  43. var audio_element = document.createElement('audio');
  44. if (audio_element.canPlayType) {
  45. for (var i = 0; i < arguments.length; i++) {
  46. var source_element = document.createElement('source');
  47. source_element.setAttribute('src', arguments[i]);
  48. if (arguments[i].match(/\.(\w+)$/i)) {
  49. source_element.setAttribute('type', audioTypes[RegExp.$1]);
  50. }
  51. audio_element.appendChild(source_element);
  52. }
  53. audio_element.load();
  54. audio_element.pFunc = function() {
  55. audio_element.pause();
  56. audio_element.currentTime = 0;
  57. audio_element.play();
  58. };
  59. return audio_element;
  60. }
  61. }
  62.  
  63. audio1 = pxS(AUDIO_FILE);
  64.  
  65. })();