[Script] Item Info AutoExpander

Update 2017-04-29: version 0.21

New

  • now will also expand item info in lesson reviews.

Description

This is a very simple script for reviews that always expands the Item Info section. I use it because I realized I was clicking Item Info all the time, either because I got an answer wrong, or to review a mnemonic when I just foggily remembered the answer but not the mnemonic, or to review the stroke order (which WaniKani doesn’t quiz me on). That’s all it does, but it saves a bunch of clicks on every review.

It is based on Wanikani Review Wrong Info Click by Takuya Kobayashi, and I couldn’t have done it without the directions of @Mempo and @rfindley, who took me 95% there. Thank you!

Installation


Current version

0.21 (2017-04-29)

New

  • now will also expand item info in lesson reviews.

Code

// ==UserScript==
// @name        WaniKani Item Info Expander
// @namespace   mvi
// @description Expands item info automatically without scrolling. Based on script by Takuya Kobayashi, with help from Mempo and rfindley.
// @include     https://www.wanikani.com/review/session
// @include     https://www.wanikani.com/lesson/session
// @version     0.21
// @run-at      document-end
// @grant       none
// ==/UserScript==

(function () {
    'use strict';
    
    function noscroll() {
        window.scrollTo( 0, 0 );
    }

    var oldEvaluate = answerChecker.evaluate;
    answerChecker.evaluate = function(e,t) {
      
        // add listener to disable scroll
        window.addEventListener('scroll', noscroll);

        // expand item info
        setTimeout(function () {
          $('#option-item-info').click();
        }, 100);

        // Remove listener to disable scroll
        setTimeout(function () {
          window.removeEventListener('scroll', noscroll);
        }, 1000);
      
        return oldEvaluate(e,t);
    };
  
 
    console.log('WaniKani Item Info Expander: script load end');
}());

Old versions

[details=click to expand]

0.2 (2017-04-25)

New

  • now with scroll blocker! stays on top of the page when expanding.

Other

  • Refactor. much cleaner code, based on @rfindley’s suggestion to use answerChecker.
// ==UserScript==
// @name        WaniKani Item Info Expander
// @namespace   mvi. Thanks to Takuya Kobayashi, Mempo and rfindley
// @description Expands item info automatically without scrolling
// @include     https://www.wanikani.com/review/session
// @version     0.20
// @run-at      document-end
// @grant       none
// ==/UserScript==

(function () {
    'use strict';
    
    function noscroll() {
        window.scrollTo( 0, 0 );
    }

    var oldEvaluate = answerChecker.evaluate;
    answerChecker.evaluate = function(e,t) {
      
        // add listener to disable scroll
        window.addEventListener('scroll', noscroll);

        // expand item info
        setTimeout(function () {
          $('#option-item-info').click();
        }, 100);

        // Remove listener to disable scroll
        setTimeout(function () {
          window.removeEventListener('scroll', noscroll);
        }, 1000);
      
        return oldEvaluate(e,t);
    };
  
 
    console.log('WaniKani Item Info Expander: script load end');
}());

0.1

// ==UserScript==
// @name        WaniKani Item Info Expander
// @namespace   mvi, based on script by Takuya Kobayashi, with help from Mempo
// @include     https://www.wanikani.com/review/session
// @version     0.1
// @run-at      document-end
// @grant       none
// ==/UserScript==

(function () {
'use strict';

$.jStorage.listenKeyChange('questionCount', function (key, action) {
    if (action === 'updated') {
        setTimeout(function () {
                $('#option-item-info').click();
            }, 100);
    }
});

$.jStorage.listenKeyChange('wrongCount', function (key, action) {
    
    if (action === 'updated') {
            setTimeout(function () {
                $('#option-item-info').click();
            }, 100);
    }
});
console.log('WaniKani Item Info Expander: script load end');
}());
```[/details]
6 Likes

How do you use it ? Greasemonkey ?

yea, just make a new script and paste the code in. Or install from the link below.

@mvi you probably don’t have a greasyfork account? I’ve put it on mine here: WaniKani Item Info Expander

thanks a lot for the link ^^

FYI, you may have unexpected script behavior if someone is using a script that modifies wrongCount or questionCount, which would trigger multiple keyChange events. I think Override and maybe DoubleCheck do that. The result would probably be two clicks, causing the item info to close immediately after opening. You could prevent it by checking whether the item info is already visible

2 Likes

You are right, I do not. Perfectly fine to put it under yours. Thanks for making that easier!

If I end up refactoring I may paste it as a gist to allow new versions with @rfindley’s much cleaner suggestion or to support the edge case they point out. Unless you don’t mind updating greasyfork.

I saw your suggestion in the main thread. It looks much much cleaner. Thank you so much.

This works for me well enough, but I’ll think about refactoring and addressing your point even if just to leave it proper.

I don’t mind updating greasyfork.

Great script, thanks for sharing. Would it be possible to prevent the automatic scroll down from happening after expanding? In other words: would still like it to automatic expand but the view to stay at the top of the page, after which I can decide for myself to scroll down or not.

it bothered me as well, so I’ve gone ahead and added it. Maintaining the position at the top means that you won’t be able to scroll for 1 second after sending your answer. In my tests I don’t even notice it, but let me know how that works for you.

// ==UserScript==
// @name        WaniKani Item Info Expander
// @namespace   mvi, based on script by Takuya Kobayashi, with help from Mempo and rfindley
// @description Expands item info automatically without scrolling
// @include     https://www.wanikani.com/review/session
// @version     0.20
// @run-at      document-end
// @grant       none
// ==/UserScript==

(function () {
    'use strict';
    
    function noscroll() {
        window.scrollTo( 0, 0 );
    }

    var oldEvaluate = answerChecker.evaluate;
    answerChecker.evaluate = function(e,t) {
      
        // add listener to disable scroll
        window.addEventListener('scroll', noscroll);

        // expand item info
        setTimeout(function () {
          $('#option-item-info').click();
        }, 100);

        // Remove listener to disable scroll
        setTimeout(function () {
          window.removeEventListener('scroll', noscroll);
        }, 1000);
      
        return oldEvaluate(e,t);
    };
  
 
    console.log('WaniKani Item Info Expander: script load end');
}());
1 Like

Thank you kindly. I’ve posted a new version if you want to update it.

There’s a new version that uses your answerChecker suggestion. Much cleaner. Many thanks.

I changed it on greasyfork too.

A couple of tips:

  1. put the link (WaniKani Item Info Expander) somewhere visible in your OP (nobody has installed it from greasyfork yet because they might not have known it was there in the first place)

  2. Keep your namespace attribute consistent in all versions. This is essentially the attribute that makes automatic updates to scripts possible (it checks the namespace of the installed version, so if you change it in the online version with an update, that update will not be noticed). I changed it on greasyfork to your username (so just ‘mvi’). Any credit should go in the description.

Thank you! Works really well.

New update just to include the script in the review of the lessons as well.

I’ve also edited the top post to include the link to greasemonkey to install the script directly from there.

Thanks for the help and for keeping it up to date on greasyfork. I didn’t know about the namespace attribute affecting the updates: I’ve reflected your suggested change and will keep it consistent from here on. Thanks!

@mvi,

Someone in another thread requested a version of your script that only opens the info when the answer was correct. I wrote a one-line fix for them, but thought I’d mention it here if you want to add it as an option or something.

Here’s the link to the other thread. (click through to view the demangled code):
[deleted – see below]

3 Likes

I don’t know if this script is currently slightly broken for everyone or just for me.

I made a tiny change and posted the script to greasyfork, feel free to reuse if you want: WaniKani Always Show Item Info

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.