Jitai (字体): The font randomizer that fits

Note: This post is a fix for Jitai v2 (which is a different version of this script)
See above for the current fix for Jitai v3 managed by marciska.

Found a fix for this. Pretty much the same issue.

Following the same steps above, replace lines 132-160 (most likely different based on what fonts you have) with the following code:

Image for reference

Replace the code under // ----

const ele = document.getElementsByClassName("character-header__characters")[0];
const default_font = getComputedStyle(ele).fontFamily;
let current_font = default_font;

let style = document.createElement("style");
ele.style.fontFamily = current_font;
document.head.appendChild(style);

function applyRandomizedFont() {
    ele.style.fontFamily = current_font;
}

function revertToDefaultFont() {
    ele.style.fontFamily = default_font;
}

ele.addEventListener('mouseenter', revertToDefaultFont);
ele.addEventListener('mouseleave', applyRandomizedFont);

// On Submit
window.addEventListener("didAnswerQuestion", function()
{
    ele.style.fontFamily = default_font;
});

// On Next
window.addEventListener("willShowNextQuestion", function(event)
{
    const characters = event.detail.subject.characters;
    if (typeof(characters) == "string")
    {
        do current_font = existingFonts[Math.floor(Math.random() * existingFonts.length)];
        while (!canRepresentGlyphs(current_font, characters));

        ele.style.fontFamily = current_font;
    }
});

Let me know if that works!

3 Likes