New version of KunOn script: WK Custom Review Question (KunOn+)

Hello

I made a new version of the WaniKani KunOn script originally written by Rui Pinheiro (/t/Wanikani-KunOn-101-Kunyomi-or-Onyomi-instead-of-Reading-No-longer-supported/3883/1) because that one is not supported any more.

This one doesn’t import its own version of jQuery and doesn’t depend on the Grant None shim that was added to the old one. It uses some MutationObserver code to detect changes in the DOM and then checks the jStorage currentItem object to see if it is that which has changed. If it is it replaces the content of the question-type DIV. The MutationObserver code is from Stack Overflow (http://stackoverflow.com/questions/3219758/detect-changes-in-the-dom/14570614#14570614)

I got the idea to use MutationObserver from Ethan’s “Close, but no cigar” script (https://www.wanikani.com/chat/api-and-third-party-apps/7333).

A while ago I made an addition to my local copy of the original script because I wanted to have the question text in Japanese, so I have kept that option in this version. If you feel like having the question in Japanese edit the source in your Greasemonkey/Tampermonkey setting and change this line:

var strLang = “en”;

To this:

var strLang = “ja”;

The Japanese questions look like this.



The English questions are the same as the old version, the only thing that changes from standard is that it specifies on’yomi and kun’yomi for kanji instead of saying “Reading”.



==============================================================================

Please note:

This is a userscript which needs either Greasemonkey (Firefox) or Tampermonkey (Chrome) to run, it isn’t a browser extension or add on.


Greasemonkey: https://addons.mozilla.org/en-Us/firefox/addon/greasemonkey/

Tampermonkey: https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo

Tested on the following:
Firefox 35.0.1 and Chrome 39.0.2171.95 (64-bit), Linux Mint 17.1 Cinnamon 64-bit
Firefox 35.0.1 and Chrome 40.0.2214.115 m, Windows 8.1 64-bit

==============================================================================

I don’t have an Apple or Windows 7 so I can’t test it on those.

UPDATE Feb 25 2015

Now applies to Lesson Quizzes as well as Reviews.

v 0.4.3 on Greasy Fork

https://greasyfork.org/en/scripts/8193-wk-custom-review-question-kunon


10 Likes

Looks great, thank you!

(especially since I always get the 意味  of 意味 wrong… shhhh)

There was an error in it where I was overwriting the green pop-up that tells you the level that the item has been promoted or demoted to. It is ok now.

Kazumi said... Looks great, thank you!

(especially since I always get the 意味  of 意味 wrong.. shhhh)
 You are welcome.

Please get a new version from here. The first one was removing the the green level announcement pop-up. Sorry about that.

https://greasyfork.org/en/scripts/8193-wk-custom-review-question-kunon

I have updated this so that it applies to Lesson Quiz questions as well as Reviews

QUESTIONS IN ENGLISH
https://greasyfork.org/en/scripts/8193-wk-custom-review-question-kunon

Also, if you fancy having the questions in Japanese but don’t like the idea of poking about in source code I have uploaded a version that has the language set to Japanese by default.

QUESTIONS IN JAPANESE
https://greasyfork.org/en/scripts/8266-wk-custom-review-question-kunon

You can switch between these as you wish, installing one replaces the other.

HI, I just tried to install this, but Chrome won’t allow me to use it since it’s not in the Google shop?? I’m using Windows 7 home with the most recent Chrome. The support page says use an older version (nope) or to contact the author and have it added to the store. :< Assist?

Sherunatto said... HI, I just tried to install this, but Chrome won't allow me to use it since it's not in the Google shop?? I'm using Windows 7 home with the most recent Chrome. The support page says use an older version (nope) or to contact the author and have it added to the store. :< Assist?
it's not an extension so that shouldn't be an issue. do you have tampermonkey installed? 
ShotgunLagoon said...
Sherunatto said... HI, I just tried to install this, but Chrome won't allow me to use it since it's not in the Google shop?? I'm using Windows 7 home with the most recent Chrome. The support page says use an older version (nope) or to contact the author and have it added to the store. :< Assist?
it's not an extension so that shouldn't be an issue. do you have tampermonkey installed? 
 I have no idea what that is, so no. <_<
Sherunatto said... HI, I just tried to install this, but Chrome won't allow me to use it since it's not in the Google shop?? I'm using Windows 7 home with the most recent Chrome. The support page says use an older version (nope) or to contact the author and have it added to the store. :< Assist?
 Hello

As Shotgun correctly says, this is not a Chrome extension but a user script which needs Tampermonkey to run.

Tampermonkey is an extension for Chrome which enables Javacript code like this to safely run in your browser in the same way as Greasemonkey does for Firefox.

Go the the Tampermonkey link HERE and add it to Chrome, then go to the Greasy Fork link and the script will install and run in Tampermonkey.

Thanks

H

Well what I see is that for vocabulary it doesn’t fix completely the issue I have with WK when it comes to kun/on: the different meanings a vocab element can have associated with different reading (which would be mostly sorted out).
To give some low level examples:
 金 will be fixed for the reading (I know I messed it once putting かね there) but not for the meaning
何人 won’t be fixed at all since the two interpretations are both on’yomi (to be honest I don’t even remember which one WK had now)

It doesn’t even attempt to do anything for vocabulary. It only tells you whether WaniKani is expecting Kun or On READING for a KANJI review or lesson quiz.

I don’t quite understand what you are talking about with the vocabulary thing. 何人 = なんにん.

Is this still supported?

It does not show “Nanori”. There are some words that emphasize Nanori, for example WaniKani / Kanji / 輔. It just says Kunyomi, if I remember correctly.

1 Like

In line 131, add to if-clause

if(objCurItem.emph == "nanori")
   strReadingType = "名乗り"
1 Like

I can’t seem to get this script to work. Is it still supported?

I’m on Windows 10, Chrome Version 74.0.3729.169 using Tampermonkey.

It works for me right now, Windows 10, Chrome 77, Tampermonkey.
It only shows Onyomi/Kunyomi for Kanji though, not vocabulary.
image

That’s what initially got me thinking it didn’t work.
Of course, single-kanji vocabulary is almost always Kunyomi, and the reading is part of learning the vocabulary anyways.

Btw, an alternative to this script is Katakana madness,
which writes all Onyomi readings in Katakana.

That way, if you want to know which reading it asks for, you just type
a letter (a), and if it’s Katakana, it asks for Onyomi.
I found that always telling me Kunyomi or Onyomi is a bit of a distraction for me.
Also, this is good Katakana practice.

@hoovard are you still maintaining this? If so, I have a patch I would like to try upstreaming that makes it work during lessons and integrates support for nanori readings based on @polv’s comment

why don’t you post the patch here first? that way other users can patch themselves, and the maintainer doesn’t first have to ask you again for the code before applying the patch.

I didn’t post it originally because the kind of patch I would post if a maintainer is considering up streaming would try to minimize the number of lines changed to make their life easier. I’ve posted the version I use below, which does not attempt to do that. (No diff because the indentation level changed on ~half the code.)

// ==UserScript==
// @name        WK Custom Review Question (KunOn+)
// @namespace   WK_CustomQuestion
// @description Changes the text of the Review or Lesson Quiz question. Specifies ON or KUN reading for Kanji. Options to have the text in English or Japanese.
// @author      hoovard
// @include     https://www.wanikani.com/review/session*
// @include     http://www.wanikani.com/review/session*
// @include     https://www.wanikani.com/lesson/session*
// @include     http://www.wanikani.com/lesson/session*
// @version     0.4.3
// @license     Do what you want with it (Preferably improve it).
// @grant       none
// ==/UserScript==
// Version 0.4.3 applies to Reviews and Lesson Quizzes.

// Language options
// English "en", Japanese "ja"
var strLang = "en";


// Tested on the following:
// Firefox 35.0.1 and Chrome 39.0.2171.95 (64-bit), Linux Mint 17.1 Cinnamon 64-bit
// Firefox 35.0.1 and Chrome 40.0.2214.115 m, Windows 8.1 64-bit

// Thanks to Rui Pinheiro (LordGravewish) for the original script 
// and to Ethan for the idea to use MutationObserver to detect changes in the DOM.

// Vars to compose the replacement question string
var strKanji;
var strRadical;
var strVocab;
var strMeaning;
var strReading;
var strVocabReading;
var strOn;
var strKun;
var strNan;
var strName;

// Translations
switch (strLang)
{
	case "en":
		strKanji = "kanji";
		strRadical = "radical";
		strVocab = "vocabulary";
		strMeaning = "meaning";
		//strReading = "yomi";
		strVocabReading = "reading";
		strOn = "on'yomi";
		strKun = "kun'yomi";
        strNan = "nanori";
		strName = "name";
		break;
	case "ja":
		strKanji = "漢字";
		strRadical = "部首";
		strVocab = "単語";
		strMeaning = "意味";
		//strReading = "読み";
		strVocabReading = "読み";
		strOn = "音読み";
		strKun = "訓読み";
        strNan = "名乗り";
		strName = "名前";
		break;
}

// Variable to save and check against the previous contents of the jStorage item
var objSavedCurrentItem;

// Review or Lesson Quiz. jStorage objects are different.
bIsReview = ($(location).attr('href').indexOf("review") != -1);

// Code based on Stack Overflow to detect changes in the DOM.
// (http://stackoverflow.com/questions/3219758/detect-changes-in-the-dom/14570614#14570614)
var observeDOM = (function(){
    var MutationObserver = window.MutationObserver;

    return function(obj, callback){
        if( MutationObserver ){
            // define a new observer
            var obs = new MutationObserver(function(mutations, observer){
                    callback();
            });
            // have the observer observe for changes in children
            // need to observe attributes because after we alter the question, wanikani will
            // not update the question text in certain circumstances and instead only changes the class
            // because WK uses regex to do a replacement on the text which results in no change if the
            // text does not have the string WK is searching for (this behavior occurs in lesson quiz)
            obs.observe( obj, { childList: true, attributes: true, subtree:true });
        }
    }
})();

// Callback function observing the 'question-type' div 'h1' element
var selector = '#question-type h1';
var observeMe = $(selector); // on review page
if (observeMe.length == 0) {
    // on lesson quiz page
    selector = '#question-type'
    observeMe = $(document); // on lessons page, selector isn't in dom on page load
}
observeMe = observeMe[0];
let in_call = false;
observeDOM( observeMe ,function(){
    let el = $(selector);
    if (el.length==0)
        return;


    var objCurItem;
    if (bIsReview) {
        objCurItem = $.jStorage.get("currentItem");
    } else {
        objCurItem = $.jStorage.get("l/currentQuizItem");
    }



    var strQuestionType;
    if (bIsReview) {
        strQuestionType = $.jStorage.get("questionType");
    } else {
        strQuestionType = $.jStorage.get("l/questionType");
    }

    var strItemType = "";
    var strReadingType = "Reading";

    // Compose the string elements to be sent into the h1 element
    if ("kan" in objCurItem)
    {
        // Kanji
        strItemType = strKanji;
        if (strQuestionType == "reading") {
            if(objCurItem.emph == "onyomi")
                strReadingType = strOn;
            else if(objCurItem.emph == "kunyomi")
                strReadingType = strKun;
            else if(objCurItem.emph == "nanori")
                strReadingType = strNan;
        } else {
            strReadingType = strMeaning;
        }
    }
    else if ("voc" in objCurItem)
    {
        // Vocabulary
        strItemType = strVocab;
        if (strQuestionType == "reading") {
            strReadingType = strVocabReading;
        } else {
            strReadingType = strMeaning;
        }
    }
    else if ("rad" in objCurItem)
    {
        // Radical
        strItemType = strRadical;
        strReadingType = strName;
    }

    // replace the contents of #question-type h1
    let newContents;
    switch (strLang)
    {
        case "en":
            newContents = strItemType + ' <strong>' + strReadingType + '</strong>';
            break;
        case "ja":
            newContents = strReadingType;
            break;
    }

    // Prevent responding to own DOM changes
    // triggers fewer mutationobservers compared to
    // previous way of doing this
    if (newContents != el.html()) {
        $(selector).html(newContents);
    }
});
1 Like

Marking this script as outdated in the list. If you guys want to maintain it I suggest starting a new thread and adding it to the list

2 Likes