[Userscript] Community Mnemonics 2 (WKCM2)

It seems that this script uses the global wkItemInfo object created by my library script WaniKani Item Info Injector, but does not include

// @require https://greasyfork.org/scripts/430565-wanikani-item-info-injector/code/WaniKani%20Item%20Info%20Injector.user.js?version=985948

to make sure that the library script is running, leading to these error messages.

@Dakes Aside from the missing @require, you are not using wkItemInfo the way it was intended. This line adds a new “event listener” every time getItem() is called, and they are never deleted:

// No need to go scraping the HTML
        .notify((i) => item = i.characters);

EDIT: Since you are running this code only on item pages I assume your getItem() function is only called once? In that case this is not really a problem. But I think the method suggested below is still clearer.

Alternatively, you could use item = wkItemInfo.currentState.characters. Or fall back to scraping the HTML and remove the wkItemInfo dependency (in WK Item Info Injector, I’m using document.querySelector(".radical-icon, .kanji-icon, .vocabulary-icon").textContent.trim() to get the characters from the webpage; on item pages of radicals that are images instead of characters, this results in an empty string).