WaniKani Fast Abridged Wrong/Multiple Answer

try to take over the world!

当前为 2017-11-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         WaniKani Fast Abridged Wrong/Multiple Answer
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  try to take over the world!
// @author       You
// @match        https://www.wanikani.com/review/session
// @match        https://www.wanikani.com/
// @match        https://www.wanikani.com/dashboard
// @require      https://greasyfork.org/scripts/22751-wanikani-settings/code/WaniKani%20Settings.js?version=166555
// @grant        none
// ==/UserScript==

var onlyIfMultiples;
var wrongCountFAWA;
(function() {
    'use strict';
    wrongCountFAWA = $.jStorage.get("wrongCount");
    if(window.location.href == "https://www.wanikani.com" || window.location.href == "https://www.wanikani.com/dashboard"){
        makeSettings("Fast Wrong Answer",{1: {Name: "wkFastWrongAlwaysShow", Display: "Always Show Correct Answers", Type: "checkbox"},
                    2: {Name: "wkFastWrongAlwaysShowOnlyMultiple", Display: "   (Only if multiple answers)", Type: "checkbox"},
                    3: {Name: "wkFastWrongDontShowWrong", Display: "   (Don't show wrongs)", Type: "checkbox"}});
        $('#divFastWrongAnswerLink').click(function(){
            wkFastAbridgedWrongAnswerSettingTweak();
            $('#chkwkFastWrongAlwaysShow').click(function(){
                wkFastAbridgedWrongAnswerSettingTweak();
            });
        });
    }
    var alwaysShowCorrect = getSetting('wkFastWrongAlwaysShow');
    var dontShowWrong = getSetting('wkFastWrongDontShowWrong');
    onlyIfMultiples = getSetting('wkFastWrongAlwaysShowOnlyMultiple');
    $('#user-response').after("<label id='lblCorrect' style='background-color: orange; display: none; height: 50px; line-height: 2em; font-size: 1.5em; font-weight: bold; color: white; text-shadow: 2px 2px 0 rgba(0,0,0,0.2) !important;'></label>");
    $('#lblCorrect').css('width',$('#user-response').css('width'));
    $.jStorage.listenKeyChange('currentItem', function (key, action) {
        if (action === 'updated') {
            $('#lblCorrect').text('').css('display','none');
        }
    });
    //$.jStorage.listenKeyChange('wrongCount', function (key, action) {
    //    if (action === 'updated' && $.jStorage.get("wrongCount") > 0) {
    //        showCorrect(0);
    //    }
    //});
    $.jStorage.listenKeyChange('questionCount', function (key, action) {
        if(wrongCountFAWA != $.jStorage.get("wrongCount"))
        {
            wrongCountFAWA = $.jStorage.get("wrongCount");
            if(dontShowWrong == "0"){
                showCorrect(0);
            }
        }
        else {
            if (action === 'updated' && $.jStorage.get("questionCount") > 0 && alwaysShowCorrect == "1") {
                showCorrect(1);
            }
        }
    });
})();

function showBar(mode){
    $('#lblCorrect').text('').css('display','block');
    $('#lblCorrect').text('').css('background-color', mode === 0 ? 'orange' : 'blue');
}

function showCorrect(mode){
    switch($('#question-type h1').text().toLowerCase()){
        case "vocabulary reading":
            if(mode === 1 && onlyIfMultiples == "1" && $.jStorage.get("currentItem").kana.length === 1) return;
            showBar(mode);
            $('#lblCorrect').text($.jStorage.get("currentItem").kana.join(", "));
            break;
        case "vocabulary meaning":
        case "kanji meaning":
        case "radical name":
            if(mode === 1 && onlyIfMultiples == "1" && $.jStorage.get("currentItem").en.length === 1) return;
            showBar(mode);
            $('#lblCorrect').text($.jStorage.get("currentItem").en.join(", "));
            break;
        case "kanji reading":
            switch($.jStorage.get("currentItem").emph.toLowerCase()){
                case "onyomi":
                    if(mode === 1 && onlyIfMultiples == "1" && $.jStorage.get("currentItem").on.length === 1) return;
                    showBar(mode);
                    $('#lblCorrect').text($.jStorage.get("currentItem").on.join(", "));
                    break;
                case "kunyomi":
                    if(mode === 1 && onlyIfMultiples == "1" && $.jStorage.get("currentItem").kun.length === 1) return;
                    showBar(mode);
                    $('#lblCorrect').text($.jStorage.get("currentItem").kun.join(", "));
                    break;
            }
            break;
    }
}

function wkFastAbridgedWrongAnswerSettingTweak(){
    if($('#chkwkFastWrongAlwaysShow').prop('checked')){
        $('#chkwkFastWrongAlwaysShowOnlyMultiple').closest('tr').css('opacity','1.0').css('filter', 'alpha(opacity = 60)');
        $('#chkwkFastWrongAlwaysShowOnlyMultiple').prop('disabled','');
        $('#chkwkFastWrongDontShowWrong').closest('tr').css('opacity','1.0').css('filter', 'alpha(opacity = 60)');
        $('#chkwkFastWrongDontShowWrong').prop('disabled','');
    } else {
        $('#chkwkFastWrongAlwaysShowOnlyMultiple').closest('tr').css('opacity','0.6').css('filter', 'alpha(opacity = 100)');
        $('#chkwkFastWrongAlwaysShowOnlyMultiple').prop('disabled','disabled');
        $('#chkwkFastWrongAlwaysShowOnlyMultiple').prop('checked',false);
        $('#chkwkFastWrongDontShowWrong').closest('tr').css('opacity','0.6').css('filter', 'alpha(opacity = 100)');
        $('#chkwkFastWrongDontShowWrong').prop('disabled','disabled');
        $('#chkwkFastWrongDontShowWrong').prop('checked',false);
    }
}