[UserScript] WaniKani Lightning Mode

#10

Hey! Thanks a bunch for making this first of all :D 

I seem to be having a problem and I dont know how to fix it. When I activate Lightning mode, Every time I get an answer correct it reloads the page. 

Its probably something on my end but iIhave no idea why this is happening so if you have any incite let me know.


0 Likes

#11
revolutnine said... Hey! Thanks a bunch for making this first of all :D 

I seem to be having a problem and I dont know how to fix it. When I activate Lightning mode, Every time I get an answer correct it reloads the page. 

Its probably something on my end but iIhave no idea why this is happening so if you have any incite let me know.


 If you have other scripts active, disable them and see if the error persists.
0 Likes

#12
rfindley said...
Frouzich said... I've been using this script every day, I can't do without it. If you feel like it, it would be nice however to add a feature that indicates when you didn't type the answer 100% correct... *stares intently at rfindley*
That's a good idea.  I only have reviews about once every 5 days, but I'll see what I can do when the next round comes up.
 photo ohokgif

And I have reviews about 5 times every day...
0 Likes

#13

v1.0.1 - Added option to not auto-advance if answer is slightly off.
               Added option to not auto-advance if item has multiple answers.

To enable either of these settings, follow the instructions in the [Settings] portion of the script code.

0 Likes

#14
Frouzich said...
revolutnine said... Hey! Thanks a bunch for making this first of all :D 

I seem to be having a problem and I dont know how to fix it. When I activate Lightning mode, Every time I get an answer correct it reloads the page. 

Its probably something on my end but iIhave no idea why this is happening so if you have any incite let me know.


 If you have other scripts active, disable them and see if the error persists.
 You were right! For some reason this and wanikani augmenter dont play nice together. I have no idea why but when I disable augmenter lightning mode works without a hitch. Its a shame I cant use both at the same time though. Since i mainly use augmenter for cancelling mistypes il see if i can find another script that does that. 

0 Likes

#15
revolutnine said... You were right! For some reason this and wanikani augmenter dont play nice together. I have no idea why but when I disable augmenter lightning mode works without a hitch. Its a shame I cant use both at the same time though. Since i mainly use augmenter for cancelling mistypes il see if i can find another script that does that. 
 Augmenter is pretty ancient, and I think everything it does is supported by newer scripts.

Try one of these for mistypes:

Double Check:
/t/UserScript-WaniKani-Double-Check/8396/1
It allows you to change answers from Correct to Incorrect, or Incorrect to Correct.

Override:
/t/WK-Override-fixed-for-Greasemonkey/7428/1
It only allows you to change from Incorrect to Correct.

As always, use responsibly and with caution.
0 Likes

#16

Doesn’t work at all in latest Firefox

0 Likes

#17
BlueRaja said... Doesn't work at all in latest Firefox
 I just updated Firefox to latest.  Works fine for me.
Any errors in your Javascript console?  (press F12, then click Console tab, then reload the page)

EDIT:  Does the lightning bolt icon appear in the upper-left corner?  If so, is highlighted yellow?
0 Likes

#18

That was it, guess I need to learn how to read.

Could you possibly make the lightning-bolt enabled by default after installing the script?  If people install the script I expect they want to use it. Always make the common case the default, etc.

0 Likes

#19
BlueRaja said...Could you possibly make the lightning-bolt enabled by default after installing the script?
 I thought it was, but you're right... it wasn't.

v1.0.2 - Enable lightning mode by default for new installs.
0 Likes

#20

Hey, I have a problem with this script. It worked well for some reviews and then stopped to work, I have no idea why. I tried to deactivate all the scripts but this one with no success.

EDIT: Ok, I turned the lightning mode off, didn’t know what that button was for ^^’

0 Likes

#21

it would be nice to still see the level up box.
could you make a setting for this?

0 Likes

#22

Hey guys! Since I like it when the audio plays after I type a correct answer, I wanted to know if there is a way/line to enable a 1,5 seconds pause before the script moves on to the next unit.

0 Likes

#23

Second this. @rfindley can it be implemented? If possible then I may try to do it, but with minimum JS experience, I really doubt that.

0 Likes

#24

Since the animations that control that box are deep inside some anonymous functions, I’m not sure whether you could change it cleanly. You’d have to detect if the box is supposed to display, then attempt to abort any animations scheduled for it (if they were scheduled with jquery), and create your own delayed animation to make the box disappear after a second or two since you’d already be displaying the next item by that time.

It’s not something I’d want to tackle myself at this point. I’m trying hard not to get distracted from my current project. :sweat_smile:

1 Like

#25

It’s a dirty hack, but you can set line 113 to this

setTimeout(()=>{$('#answer-form button').click();},1500);

You may need to adjust line 128 to match, but I didn’t think about it until after I ran out of reviews. I really don’t recommend doing this, as it makes it “delayed auto-click” instead of lightning mode. Edit: forgot this also hits all answers, not just the ones that played audio. So more like “really slow lazy mode”

Aaaaand the man himself replied when I was typing this… fml

0 Likes

#26

@ccookf, it looks like you were replying to the question about audio, which I apparently missed back when it was posted. I haven’t looked at the audio at all, so I’m not sure why it doesn’t still autoplay. I’m wondering if WK runs a pause() on the audio when the second click() is sent, or whether something about timing just prevents the autoplay from happening.

0 Likes

#27

So after resetting the script I noticed the audio does play, but that might be because I have the settings ticked in my profile to autoplay audio. I can’t read minified js to save my life, but I don’t think it does anything to the audio other than replace the element + sources when getting a reading correct. If there’s an audio problem this script has nothing to do with it.

WK audio element js ``` this.additionalContent.audio = e = function(t) { var n, i, r, a; if (r = $.jStorage.get("currentItem"), a = $.jStorage.get("questionType"), $("audio").remove(), r.aud && "reading" === a) return i = $("#option-audio"), n = i.find("button"), t = t, $("#answer-form fieldset").hasClass("correct") || (t = !1), n.removeAttr("disabled"), e = $("", { autoplay: t }).appendTo(i.removeClass("disabled").children("span")), $("", { src: "https://cdn.wanikani.com/audio/" + r.aud, type: "audio/mpeg" }).appendTo(e), $("", { src: "https://cdn.wanikani.com/audio/" + r.aud.replace(".mp3", ".ogg"), type: "audio/ogg" }).appendTo(e), //and so on...

/**
Also, seriously!? Javascript comma operators wtf!?
Why can’t we use semicolons to separate expressions???
Why do we need to evaluate multiple expressions in a return statement?
This seems totally unnecessary…
**/

</details>

As for the level up box, is this referring to the colored box that says apprentice, guru, ect. in red or green after finishing an item? If so I might look into it when I have reviews and free time. It looks like most of it (including the content o.O) is controlled with a set of .srs classes, so there might be a set of dirty workarounds here.

On a tangent here, this is definitely my favorite review script now. Super convenient and keeps me from double tapping enter on a wrong item. Kudos for making this and helping out so much with all of the scripts. After fiddling with this I've realized I don't want to write userscripts with a 10ft pole despite being a web developer. This is seriously frustrating stuff to deal with.
1 Like

#28

I made a workaround to get the level up box to show. When WK gets a correct answer it makes a div with .srs and a child div with the appropriate sub classes (.srs-up .srs-master, ect). As soon as it loads a new item it calls a remove on elements with the .srs class so… cue dirty hack I just copied the contents into a new div using a different class name so it won’t get deleted. I know, it’s cheap and ugly, but it works. There’s a timeout to delete the element after 1 second on line 134.

So edit here… Just noticed the unicode for the srs down arrow isn’t showing up on my end. Also, the very last review will hang when moving to the summary page so both the original .srs div and the new one will show up. The latter should be an easy fix, but I have no idea why the down arrow is on the fritz for me.

dirty hack ``` // ==UserScript== // @name Wanikani Lightning Mode // @namespace wklightning // @description Eliminates second Enter or Click for correct review answers. // @include https://www.wanikani.com/review/session* // @version 1.0.2 // @author Robin Findley // @copyright 2015+, Robin Findley // @license MIT; http://opensource.org/licenses/MIT // @run-at document-end // @grant none // ==/UserScript==

//==[ History ]======================================================
// 1.0.2 - Enable lightning mode by default for new installs.
// 1.0.1 - Added option to not auto-advance if answer is slightly off.
// Added option to not auto-advance if item has multiple answers.
// 1.0.0 - Initial release.
//===================================================================

//==[ Settings ]=====================================================
// The following script configuration variables are available. You
// can enable them by pasting the corresponding line in the javascript
// console (press F12 in most browsers to open the console), or by
// removing the “//” before the corresponding “localStorage” line
// below. The setting will be saved in storage.
// To remove a setting from storage, enter the following line in the
// javascript console, with corresponding setting name replaced:
// delete localStorage.wkdpp_setting_name;
//-------------------------------------------------------------------
//
// Halt if answer is slightly off.
// localStorage.wklightning_halt_slightly_off = 1;
//
// Halt if answer has multiple meanings.
// localStorage.wklightning_halt_multiple = 1;
//===================================================================

wklightning = {};

(function(gobj){

var lightning = false;
var observer;
var ignore;

function addStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (head) {
        style = document.createElement('style');
        style.setAttribute('type', 'text/css');
        style.textContent = css;
        head.appendChild(style);
        return style;
    }
    return null;
}

//-------------------------------------------------------------------
// Process stored configuration settings.
//-------------------------------------------------------------------
function process_settings() {
    function value_or_default(value, dflt) {return (value===undefined ? dflt : value);}

    // Halt if answer is slightly off.
    gobj.halt_slightly_off = value_or_default(localStorage.wklightning_halt_slightly_off, 0);

    // Halt if answer has multiple meanings.
    gobj.halt_multiple = value_or_default(localStorage.wklightning_halt_multiple, 0);
}

//-------------------------------------------------------------------
// main() - Runs after page is done loading.
//-------------------------------------------------------------------
function main() {
    process_settings();
    addStyle(
        '#lightning-mode.active {color:#ff0; opacity:1.0;}'+
        '#answer-form fieldset.WKLM_warn button, #answer-form fieldset.WKLM_warn input[type=text], #answer-form fieldset.WKLM_warn input[type=text]:disabled {background-color:#fa2 !important;}'+
        //A lot of styles for the srs box
        '.WKLM_SRS {position:absolute; top:-2.25em; left:0%; width:100%; font-size:1.5em; text-shadow:none; letter-spacing:-0.05em}'+
        '.WKLM_SRS .srs-up, .WKLM_SRS .srs-down {display:inline-block; padding-0.15em 0.3em; font-weight:bold; -webkit-border-radius:3px; -moz-border-radius:3px; border-radius:3px; -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing: border-box}'+
        '.WKLM_SRS .srs-up:before, .WKLM_SRS .srsdown:before {margin-right: 0.25em; font-family: FontAwesome}'+
        '.WKLM_SRS .srs-up.srs-burn:after, .WKLM_SRS .srs-down.srs-burn:after {content: \'Burn\'}'+
        '.WKLM_SRS .srs-up.srs-enlighten:after, .WKLM_SRS .srs-down.srs-enlighten:after {content: \'Enlighten\'}'+
        '.WKLM_SRS .srs-up.srs-master:after, .WKLM_SRS .srs-down.srs-master:after {content: \'Master\'}'+
        '.WKLM_SRS .srs-up.srs-guru:after, .WKLM_SRS .srs-down.srs-guru:after {content: \'Guru\'}'+
        '.WKLM_SRS .srs-up.srs-apprentice:after, .WKLM_SRS .srs-down.srs-apprentice:after {content: \'Apprentice\'}'+
        '.WKLM_SRS .srs-up {background-color:#af0; color: #7ab700}'+
        '.WKLM_SRS .srs-down {background-color:#f03; color: #99001f}'+
        '.WKLM_SRS .srs-up:before {content:\'\\f01b\'}'+
        '.WKLM_SRS .srs-down:before {content:\'\\f01a\'}'
    );

    lightning = localStorage.getItem('lightning');
    lightning = (lightning !== 'false');
    $('#summary-button').append('<a id="lightning-mode" href="#"'+(lightning?' class="active"':'')+'><i class="icon-bolt"></i></a>');
    $('#lightning-mode').click(function() {
        lightning = !lightning;
        console.log('Lightning mode '+(lightning?'en':'dis')+'abled!');
        localStorage.setItem('lightning', lightning);
        $(this).toggleClass('active', lightning);
        return false;
    });
    ignore = false;
    observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (!lightning || ignore) return;
            window.rjf = mutation;
            switch (mutation.target.className) {
                case 'correct':
                    var exception = $('#answer-exception');
                    var advance = true;
                    if (exception.length > 0) {
                        var msg = exception.text();
                        // Show the item info.
                        if (msg.match('multiple') !== null && gobj.halt_multiple) {
                            advance = false;
                        } else if (msg.match('answer was a bit off') !== null && gobj.halt_slightly_off) {
                            advance = false;
                        }
                    }
                    //Set the SRS level box
                    if ($("div.srs").length > 0) {
                        var srsBox = $("div.srs")[0];
                        var srsClasses = srsBox.children[0].className;
                        var srsTitle = srsBox.children[0].title;
                        $("#question-type").append('<div class="WKLM_SRS" id="WKLM_SRS"></div>');
                        var srsLevel = $("#WKLM_SRS").append("<div class='" + srsClasses +
                                             "' title='" + srsTitle +
                                             "'></div>");
                        //I have no idea why I'm not allowed to use the shortcut selectors, but they break this next line
                        setTimeout(function(){document.getElementById("question-type").removeChild(document.getElementById("WKLM_SRS"));},1000);
                    }
                    // Auto-advance.
                    if (advance) {
                        $('#answer-form button').click();
                    } else {
                        $("#answer-form fieldset").addClass("WKLM_warn");
                    }
                    break;
                case 'warning':
                case '':
                    break;
                default:
                    $('#additional-content #option-item-info').click();
                    break;
            }

            // Ignore additional changes for 100ms
            ignore = true;
            setTimeout(function(){ignore = false;}, 100);
        });
    });
    observer.observe(document.querySelector('#answer-form fieldset'), {attributes: true, subtree: true, attributeFilter: ['class']});
}

//-------------------------------------------------------------------
// Run main() upon load.
//-------------------------------------------------------------------
if (document.readyState === 'complete')
    main();
else
    window.addEventListener("load", main, false);

}(wklightning));

</summary>
1 Like

[Userscript] Show Review SRS Level
#29

Great work! I’ll try to merge it later tonight, with credit to you in the script comments and the version history in this thread.

0 Likes