Wanikani Sounds

Adds sounds for correct and incorrect on WaniKani reviews.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Wanikani Sounds
// @namespace   wksounds
// @description Adds sounds for correct and incorrect on WaniKani reviews.
// @include     https://www.wanikani.com/review/session*
// @include     https://www.wanikani.com/lesson/session*
// @version     1.0.1
// @author      Jeremy Short
// @copyright   -
// @license     MIT; http://opensource.org/licenses/MIT
// @run-at      document-end
// @grant       none
// ==/UserScript==

// Audio by: https://www.freesound.org/people/Bertrof/

$(document).ready(function(){
    var o;(o=new MutationObserver(function(ms) {
        ms.forEach(function(m) {
            (function(s){s?(function(_){_.volume=0.5;_.play();})(new Audio('https://www.freesound.org/data/previews/131/1316'+(57+(~~(s[0]=='c')*5))+'_2398403-lq.mp3')):null;})(m.target.className[0]);
        });
    })).observe(document.querySelector('#answer-form fieldset'), {attributes: true, subtree: true, attributeFilter: ['class']});
    var so;(so=new MutationObserver(function(ms){
        ms.forEach(function(m){
            var a=document.querySelector('audio');
            var p=a?a.getAttribute('autoplay')=='autoplay'?(a.removeAttribute('autoplay'),true):false:null;
            if(p)setTimeout(function(){if(p)a.play();}, 1000);
        });
    })).observe(document.querySelector('#option-audio'), {attributes: true, subtree: true, attributeFilter: ['class']});
});