Wanikani: Random voice actor

Randomizes the preferred voice actor

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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
            }
        }
    })
})()