(Obsolete) [UserScript] WaniKani Double Check

Is it possible to remove some of the buttons. For example, I never use “Last 10” and “Kana Chart”. Furthermore, I have “Item Marker,” which in V4.0 has 5 buttons. Even if I revert to V3.0 which has 1 button, it is still clunky…

Removal of Wrap-Up, Last 10, Kana Chart’s button will do.

I would (and do) have a separate userstyle for the session page; in that case you would only need to do

#option-wrap-up,
#option-last-items {
    display: none !important;}

I’m sure rfindley has a more elegant solution though.

I successfully did it, but the result is

What should I do with 14.21%?

Ideally, any script that modifies the existing interface should account for other scripts doing the same thing. For that reason, my script counts the number of buttons that were present before it started, and resizes the buttons to account for the ones it adds. If you can configure your other button-modifying scripts to run before mine, mine would normally automatically resize the remaining ones to fill the space… except I didn’t account for one thing: buttons that are present but not visible. So, the changes below will fix that.

Find this line in my script (around line 314):

var btn_count = $('#additional-content ul').children().length + 2;

Replace that with the following two lines:

$('#option-wrap-up, #option-last-items').css('display','none');
var btn_count = $('#additional-content ul').children(':visible').length + 2;

The first line hides the two unwanted buttons (as @Kumirei noted). The second line makes my script only count the visible buttons when deciding what width to use.

2 Likes

Although I created this script; neither this script, nor your code, works with Item Marker. It became like this:

40 PM

@polv,
In the Item Marker script, on line 1367, change this line:

var liCount = $('#additional-content ul').children().size();

to this:

var liCount = $('#additional-content ul').children(':visible').size();
1 Like

Thanks, it now works.

Maybe, because of // @run-at document-start ?

Reading your script on Three Submit Principle, any guideline on how to make a new No Cigar? (since the old one doesn’t work with Three Submit).

Actually, I am trying to create No Cigar, not only for near-miss, but also for Some-Default-Answers-I-Don’t-Want-To-Make-It-Right, here: https://www.dropbox.com/s/o238yjizxl17d1c/blacklist.js?dl=0

@polv,
Are you wanting to make the two scripts compatible? Or make a new script with features from both?

Adding ‘No Cigar’ to Double-Check

You can add a No-Cigar option to Double-Check in the [case 'first_submit'] section. The following line is where it sets the initial answer result (line 234):

	set_answer_state(answer, true);

When you give a close-but-no-cigar answer, the answer object looks like this:

{
	passed: true,
	accurate: false,
	multipleAnswers: false,
	exception: false
}

So, if it passed, but isn’t accurate, it’s a “No Cigar”.

Start by adding an option at the top of the script:

	// Mark answer wrong when slightly off.
	change_slightly_off_to_wrong: 1,

Then in the ‘first_submit’ section, change the set_answer_state() call to:

	// Close but no cigar
	if  (answer.passed && !answer.accurate && settings.change_slightly_off_to_wrong)
		answer.passed = false;
	set_answer_state(answer, true /* show_msgs */);

Adding Blacklist

In the same part of the code, you could check your exception_array, and again set answer.passed = false.

But No Cigar is a little less hardcore than that.

Slightly off answer is just not accepted, rather than wrong; with a shaking animation.

Ahh, ok. Then just set answer.exception = true instead.

	// Shake when slightly off.
	shake_when_slightly_off: 1,

[...]

	// Close but no cigar
	if  (answer.passed && !answer.accurate && settings.shake_when_slightly_off)
		answer.exception = true;
	set_answer_state(answer, true /* show_msgs */);

Actually, also in Line about 124:

// If answer is invalid for some reason, do the shake thing.
        if (answer.exception) {
            if (!$("#answer-form form").is(":animated")) {
                $("#reviews").css("overflow-x", "hidden");
                var xlat = {onyomi:"on'yomi", kunyomi:"kun'yomi", nanori:"nanori"};
                var emph = xlat[item.emph];
                var msg;
                $("#answer-form form").effect("shake", {}, 400, function() {
                    $("#reviews").css("overflow-x", "visible");
                    if (!answer.accurate) {
                        msg = 'Your answer was a bit off. Check the '+qtype+' to make sure you are correct';
                    } else {
                        msg = 'WaniKani is looking for the '+emph+' reading';
                    }
                    $("#answer-form form").append($('<div id="answer-exception" class="answer-exception-form"><span>'+msg+'</span></div>').addClass("animated fadeInUp"));
                }).find("input").focus();
            }
            if (!answer.reset)
                return;
        }
        
        // If user requested to retype answer, reset the question.
        if (answer.reset) {
            $.jStorage.set('wrongCount', wrong_cnt);
            $.jStorage.set('questionCount', question_cnt);
            $.jStorage.set('completedCount', completed_cnt);
            $.jStorage.set('currentItem', item);
            $("#answer-exception").remove();
            $('#option-double-check').addClass('disabled').find('span').attr('title','Mark Right').find('i').attr('class','icon-thumbs-up');
            $('#option-retype').addClass('disabled');
            Srs.remove();
            state = 'first_submit';
            return;
        }

and

// Close but no cigar
	if  (answer.passed && !answer.accurate && settings.shake_when_slightly_off) {
		answer.exception = true;
        answer.reset = true;
    }

I wonder if a script can be written to modify another script? I am looking for cross-script / different authors’ compatibility.

This doesn’t seem to work in my script…

if  (isException(word, $("#user-response").val()) ) {
            var answer = {
                 exception : true,
                 reset : true
             };
            set_answer_state(answer, true /* show_msgs */);
        }

Actually, I have done my script, and it works. But, I can’t avoid editing your script. Not sure if this will be viable to be uploaded to Greasyfork?

It should be done as an all-in-one script.

Almost done, but can you allow an external script to set: ?

state = 'first_submit';

and

var answer = {
   passed : false,
   exception : true,
   reset : true
};

and perhaps msg

Those variables are only visible inside the context of Double Check due to the anonymous function wrapper. But you could modify Double Check to make them visible, such as by adding a function inside the wrapper:

gobj.set_state = function(_state){
    state = _state;
}

And in your other script:

wkdoublecheck.set_state('first_submit');
1 Like

@rfindley

There seems to be a minor issue when you entered the kun’yomi reading instead of the on’yomi one or vice versa.

WaniKani notifies you that you entered the wrong reading and gives you another try.
But with this script, after entering the correct reading the second time, it immediately skips to the next item in the queue without showing you if the answer was correct or wrong.

I’m not even sure if it removes the item from the queue, because I remember seeing the items coming up again later.

More of an annoyance than anything.

:point_right: [v2.0.8] - Fix issue where wrong (on/kun)yomi reading still moves on to next answer.

@valeth, I’m not sure if this fixes the exact issue you described, but it does fix a related issue.

If this doesn’t fix it, let me know what settings you have at the top of the script. That may make a difference in whether I can replicate the problem.

Looks like it’s fixed now.

Thanks.

1 Like

@rfindley There are two minor issues with the new version of double check (version 2.0.9):

  1. When you type the wrong reading for a kanji (kun’yomi instead of on’yomi or vice versa) and have the shake_when_slightly_off setting enabled, it says “Hmm… that’s not quite right. Typo??” instead of the normal message.
  2. When you press enter after completing the last review to go to the review summary page (either no reviews are left or with “wrap up” selected) it shows the animation for the arrow up/down Apprentice/Guru/etc. message a second time.

@rfindley Just wanted to make sure you saw my previous post.