Lichess Sound Pack chesscom

chesscom sound

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Для установки этого скрипта вам необходимо установить расширение, такое как Tampermonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name        Lichess Sound Pack chesscom
// @namespace   jwapobie
// @description chesscom sound
// @match       https://*.lichess.org/*
// @match       https://lichess.org/*
// @version     1.5
// @grant GM_xmlhttpRequest
// @connect images.chesscomfiles.com
// @license MIT
// ==/UserScript==



// this function makes the request and puts it in an decoded audio buffer
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
function loadSound(url) {
    return new Promise(function(resolve, reject) {
        // This will get around the CORS issue
        //      http://wiki.greasespot.net/GM_xmlhttpRequest
        var req = GM_xmlhttpRequest({
            method: "GET",
            url: url,
            responseType: 'arraybuffer',
            onload: function(response) {
                try {
                    context.decodeAudioData(response.response, function(buffer) {
                        resolve(buffer)
                    }, function(e) {
                        reject(e);
                    });
                }
                catch(e) {
                    reject(e);
                }
            }
        });
    })
}

// adjust volume
var volNode;
if( context.createGain instanceof Function ) {
    volNode = context.createGain();
} else if( context.createGainNode instanceof Function ) {
    volNode = context.createGainNode();
}

// Connect the volume control the the speaker
volNode.connect( context.destination );


// allocate buffers for sounds
var customSndList = new Map([
    ['move','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default//move-self.mp3'],
    ['capture','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/capture.mp3'],
    ['check','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/move-check.mp3'],
    ['victory','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/game-win.mp3'],
    ['defeat','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/game-end.mp3'],
    ['draw','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/game-draw.mp3'],
    ['genericNotify','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/dong.mp3'],
    ['lowTime','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/lowtime.mp3'],
    ['castle','https://images.chesscomfiles.com/chess-themes/sounds/_MP3_/default/castle.mp3'],
])
var customSnds = {};
customSndList.forEach(function(element, index) {
    loadSound(element).then(function(buffer) {customSnds[index] = buffer;}, function(e) {console.log(e);})
});

// use this later in the script
function playSound(buffer, volume) {
    // creates a sound source
    var source = context.createBufferSource();
    // tell the source which sound to play
    source.buffer = buffer;
    // connect the source to the context's destination (the speakers)
    volNode.gain.value = volume;
    source.connect(volNode);
    // play the source now
    // note: on older systems, may have to use deprecated noteOn(time);
    source.start(0);
}

site.sound.origPlay = site.sound.play;

function Suite(name,volume)
{
    var move =""
    if (document.getElementsByClassName('a1t')[0] != undefined){ move = document.getElementsByClassName('a1t')[0].innerText }
    if (move == "O-O"){ name = "castle"}
    if (move == "O-O-O"){ name = "castle"}

    if (customSnds[name]) {
        if (!volume) volume = site.sound.getVolume();
        playSound(customSnds[name], volume / 2);
    } else {
        site.sound.origPlay(name, volume);
    }
}

function customPlay(name, volume) {
   setTimeout(Suite,100,name,volume);
}

site.sound.play = customPlay;

console.log("Applied UminekoSoundPack");