WK Percent unifier

Make the percentage appearing during and after reviews the same

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 or Violentmonkey 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         WK Percent unifier
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Make the percentage appearing during and after reviews the same
// @author       Gorbit99
// @include      https://*wanikani.com/review/session
// @icon         https://www.google.com/s2/favicons?domain=wanikani.com
// @grant        none
// @license MIT
// ==/UserScript==

'use strict';

(function() {
    let correct = 0;
    let incorrect = 0;
    const correctPercent = document.querySelector("#correct-rate");
    $.jStorage.listenKeyChange("reviewQueue", () => {
        const current = $.jStorage.get("currentItem");
        if (!current) {
            return;
        }
        const type = current.type === "Radical" ? "r" : (current.type === "Kanji" ? "k" : "v");
        const stats = $.jStorage.get(`${type}${current.id}`);

        if (!stats) {
            return;
        }

        if (stats.mi > 0 || stats.ri > 0) {
            incorrect++;
        } else {
            correct++;
        }
    });

    const percentObserver = new MutationObserver(() => {
        let percent = Math.ceil(correct / (correct + incorrect) * 100);
        if (correct + incorrect == 0) {
            percent = 100;
        }
        correctPercent.textContent = percent;
    });

    percentObserver.observe(correctPercent, {
        characterData: true,
        childList: true,
    });
})();