Custom Message Tones

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Custom Message Tones
// @namespace    pxgamer
// @version      0.5
// @description  Adds options to load in custom tones when a message is received.
// @author       pxgamer
// @include      *kat.cr/*
// @grant        none
// ==/UserScript==

(function() {

    var AUDIO_FILE   = ""; // URL of audio file (MP3, WAV, OGG)
    var AUDIO_LENGTH = 5000;  // Length in Ticks

    // Do Not Edit Below Here
    var acMethod = jQuery.fn.addClass;
    var audio1;

    jQuery.fn.addClass = function() {
        var result = acMethod.apply(this, arguments);

        jQuery(this).trigger('cssClassChanged');

        return result;
    };

    $('body').append('<span id="chatMsgHandler"></span>');
    $('#chatMsgHandler').css('display', 'none');
    $(document).on('cssClassChanged', function() {
        var msgBarElem = $('.chat-bar-new');
        if (msgBarElem.length > 0) {
            audio1.play();
            setTimeout(function() { audio1.pause(); audio1.currentTime = 0; }, AUDIO_LENGTH);
        }
    });

    var audioTypes = {
        "mp3": "audio/mpeg",
        "ogg": "audio/ogg",
        "wav": "audio/wav"
    };

    function pxS(sound) {
        var audio_element = document.createElement('audio');
        if (audio_element.canPlayType) {
            for (var i = 0; i < arguments.length; i++) {
                var source_element = document.createElement('source');
                source_element.setAttribute('src', arguments[i]);
                if (arguments[i].match(/\.(\w+)$/i)) {
                    source_element.setAttribute('type', audioTypes[RegExp.$1]);
                }
                audio_element.appendChild(source_element);
            }
            audio_element.load();
            audio_element.pFunc = function() {
                audio_element.pause();
                audio_element.currentTime = 0;
                audio_element.play();
            };
            return audio_element;
        }
    }

    audio1 = pxS(AUDIO_FILE);

})();