[Userscript]: Double-Check (Version 2.x)

hmm :thinking: apparently, the process should be the same
if you go to the Visual Guide on How to Install a Userscript thread, install section, the images show the buttons i’m talking about, they’ll just say update instead
so you’re saying you don’t get taken to the second one after clicking the green button?

edit: oh, someone says tampermonkey is just not working?

The simplest fix when the script won’t update is to remove it from the TamperMonkey dashboard, then go back to the Install link and do a fresh install of the new version of the script.

Thanks for the help! I got it working by deleting and reinstalling :blush:

Is anyone else having issues with double-check again? I noticed some fonts looked different today and it seems user scripts are having trouble for mine and my partners computer

can you show a screenshot? I just made some changes, but I don’t expect it to affect this script.

@tofugu-scott The issue actually appears to be that the WKOF broke with a recent change. Specifically the menu module is no longer able to find the wk-icon svg due to it being hidden within a shadow-dom. That JS error causes WKOF to not load which in turn breaks a number of scripts.

Thanks Ben for pointing that out. It is a shame that the WKOF is so tightly coupled to the markup. I will leave it to the script author to find an alternative approach.

@rfindley :backhand_index_pointing_up:

Is there a workaround for at least the one issue that I can’t figure out any way around: whenever there are multiple readings I try all of them and if I get any wrong I mark it wrong.

Similarly, I demote a Burned item back down by marking it wrong if I find I have anything wrong with my understanding (like mistaking a noun for a na-adjective, or getting transitivity wrong). “Resurrect” is too heavy-handed for this, I don’t want to start it over from zilch, I want to give myself more time to internalize it.

I’m burning about 30 items a day right now, so I just put myself in vacation mode so at least the reviews won’t pile up in the meantime…

Is there an API for the menu system that could allow decoupling?

which menu system are you referring to? Sorry I am not familiar with how WKOF works.

If you install this vibe-coded TaperMonkey script (a new script, don’t overwrite Double-Check or WKOF), it repairs the functionality. It won’t affect anything once the real issue is fixed, at which point you can safely delete it.

// ==UserScript==
// @name        WaniKani legacy icon sprite shim
// @namespace   local.wk-legacy-icon-shim
// @description Re-creates the old <symbol id="wk-icon__*"> SVG sprite (built from WK's wkIcons template) so WKOF's Menu module and Double-Check don't crash.
// @match       https://www.wanikani.com/*
// @run-at      document-start
// @grant       none
// @version     1.0.0
// ==/UserScript==

(function () {
    'use strict';

    const SPRITE_ID = 'wk-legacy-icon-sprite';
    const NS = 'http://www.w3.org/2000/svg';

    // Zero-specificity fallback sizing, in case WK's old ".wk-icon" CSS was removed.
    // Any real stylesheet rule will override this.
    const style = document.createElement('style');
    style.textContent = ':where(svg.wk-icon){width:1.25em;height:1.25em;fill:currentColor;}';
    (document.head || document.documentElement).appendChild(style);

    function buildSprite() {
        const tpl = document.querySelector('template[data-template-name="wkIcons"]');
        if (!tpl) return null;
        const root = tpl.content || tpl;

        const svg = document.createElementNS(NS, 'svg');
        svg.id = SPRITE_ID;
        svg.setAttribute('aria-hidden', 'true');
        svg.style.cssText = 'position:absolute;width:0;height:0;overflow:hidden;';

        for (const src of root.querySelectorAll('svg[id]')) {
            const sym = document.createElementNS(NS, 'symbol');
            sym.id = 'wk-icon__' + src.id;
            const vb = src.getAttribute('viewBox');
            if (vb) sym.setAttribute('viewBox', vb);
            sym.innerHTML = src.innerHTML;
            svg.appendChild(sym);
        }
        return svg;
    }

    function ensureSprite() {
        try {
            if (!document.body) return;
            // Already present (ours, or WK/WKOF's own)? Nothing to do.
            if (document.querySelector('svg symbol[id^="wk-icon"]')) return;
            const svg = buildSprite();
            if (svg) document.body.prepend(svg);
        } catch (e) {
            console.warn('[wk-legacy-icon-shim]', e);
        }
    }

    // Turbo replaces <body> on navigation, which wipes the sprite. Re-add it immediately
    // (microtask timing) when <html>'s children change, plus on the usual lifecycle events.
    new MutationObserver(ensureSprite).observe(document.documentElement, { childList: true });
    document.addEventListener('DOMContentLoaded', ensureSprite);
    document.addEventListener('turbo:render', ensureSprite);
    document.addEventListener('turbo:load', ensureSprite);
    ensureSprite();
})();

I mean the WaniKani site dropdown menu (now called the Account menu, I think).

Before WKOF, every script had its own quirky way of accessing its own settings or opening its features, etc. Many scripters added things to the WK Account menu, and scripts tended to trample over each other. So, when I built WKOF, I included a Menu API that offers a unified and cooperative way for scripts to add their own menu commands under the WK Accounts menu:

(sorrry, old example, but this conveys the idea)

[WKOF Menu API]

It’s basically just a single function:
insert_script_link(config)
where config has parameters that let you specify a submenu (such as ‘Settings’), a link title (‘Self-Study Quiz’), and a function to call when the user clicks the menu link.

There was never a clean way to integrate it into the WK menu, but it has been remarkably stable over the last 10 years or so. I’ve only had to update it significantly about two or three times.

I’m not asking for one, but if WK’s codebase has an API for adding things to the menu system, I would gladly use it.

[edit:] On the ‘Lessons’ and ‘Reviews’ pages, the same insert_script_link() adds a gear icon in the top-left of the window next to the Home button, like this:

Thank you for building this one so quickly, I really wish I didn’t need to rely on WKOF scripts to get the reviews done, but I’m still finding it really hard to understand why features such as pressing backspace when doing reviews, that Bunpro and MaruMori do without userscripts, warrant so much resistance from the platform.

I was able to do my reviews today thanks to this vibe coded script, I appreciate you putting it out so quickly!

I see what you mean. I was a little confused as my original comment related to the coupling of wk-icon svgs in custom scripts. On that note, I would have thought script devs would have brought their own icon code.

As for an API to tap into the WaniKani UI, there is no such api sorry.


Note from your edit:
I think I see what your code is doing. You are looking for the first icon on the page so that you can add more icons to the page?!
I know it isn’t as pretty, but why not add your own menu bar to the top of the body outside of the WaniKani markup? That way any changes to the markup wouldn’t break the scripts as you would just be injecting a DOM node that you control to the top of the page outside any changes that I might make.

That’s certainly doable, and maybe I’ll add that as a graceful fallback. The philosophy has always been to fit scripts into the WK aesthetic as much as practical, so it feels like part of the WK experience. I always knew it would break occasionally, of course, but as long as breaking changes are relatively infrequent (which has mostly been true), it’s worth the effort to integrate seamlessly.

That fixed it for me, thanks.

Double-Check 3.2.9 (Greasy Fork /35063/), Tampermonkey, Brave on Windows 11. WKoF is loaded and Double-Check appears in Scripts → Settings. No errors in the console. During reviews nothing changes: [describe what happens after a wrong answer]. Object.keys(wkof.settings) returns [] on /subjects/review. Other scripts work.

Script stopped working here. Both on Firefox and Chrome I desinstal/resinstalled

Can confirm that the script is no longer working. Checked console logs and it looks like the DOM changed so the script can no longer look for the anchor element to insert the custom icons.