Wanikani: Random voice actor

Randomizes the preferred voice actor

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Wanikani: Random voice actor
// @description Randomizes the preferred voice actor
// @match       https://www.wanikani.com/*
// @match       https://preview.wanikani.com/*
// @require     https://greasyfork.org/scripts/462049-wanikani-queue-manipulator/code/WaniKani%20Queue%20Manipulator.user.js?version=1340063
// @version     1.2.4
// @author      Kumirei
// @license     MIT; http://opensource.org/licenses/MIT
// @grant       none
// @namespace   https://greasyfork.org/users/105717
// ==/UserScript==

;(function () {
    // Set up randomized voice actor
    window.wkQueue.addPostprocessing((queue) => {
        for (let item of queue) {
            if (!('readings' in item.subject)) continue // Only vocab items
            for (let reading of item.subject.readings || []) {
                if (!reading.pronunciations.length) continue // Only items with audio
                // Pick random pronunciation and then set all actors' audio to be that pronunciation
                const random_index = Math.floor(Math.random() * reading.pronunciations.length)
                const sources = reading.pronunciations[random_index]?.sources
                if (!sources.length) continue
                for (let pronunciation of reading.pronunciations) pronunciation.sources = sources
            }
        }
    })
})()