Self Q.O.L

Alters WK Lessons for a self-review focused experience

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Self Q.O.L
// @namespace    wk_selfQOL
// @version      1.0.2
// @description  Alters WK Lessons for a self-review focused experience
// @author       ccookf
// @match        https://www.wanikani.com/lesson/session
// @license      MIT; http://opensource.org/licenses/MIT
// ==/UserScript==

(function() {
    'use strict';
    var header = $('#main-info');
    var headerText = header.children('#meaning').first();
    var MAX_CHARS = 20;

    //Remove the prompt for starting the quiz after "finishing" lessons
    $('#screen-quiz-ready').remove();

    //Set up event listeners to update the headers
    $('#prev-btn').click(updateHeader);
    $('#next-btn').click(updateHeader);
    $('#supplement-nav').click(updateHeader);
    $.jStorage.listenKeyChange('l/currentLesson', updateHeader);
    $('body').keyup(function(event) {
        //I don't know where the original handler is working, so this prevents order issues
        //Should only be a single frame delay on most devices
        if (event.key == 'Enter') setTimeout(updateHeader, 10);
    });

    function updateHeader() {
        if ($('#lesson').css("display") === "none") return;
        var currentItem = $.jStorage.get('l/currentLesson');
        var active = $('#supplement-nav').find('.active').attr('data-index');
        var type = $('#main-info').attr('class');
        var out = '';
        switch (active) {
            case '0':
                headerText.text('。。。');
                break;
            case '1':
                currentItem.en.forEach(function(item) {
                    if (out.length + item.length + 2 <= MAX_CHARS) out += (out.length === 0 ? '': ', ') + item;
                });
                headerText.text(out);
                break;
            case '2':
                var data;
                if (type == "kanji") {
                    if (currentItem.emph == "onyomi") data = currentItem.on;
                    else data = currentItem.kun;
                } else data = currentItem.kana;
                data.forEach(function(item) {
                    if (out.length + item.length + 2 <= MAX_CHARS) out += (out.length === 0 ? '': ', ') + item;
                });
                headerText.text(out);
                break;
            default:
                console.warn('Unexpected case in Self Q.O.L script: active item = ' + active);
        }
    }
})();