WaniKani Fast Abridged Wrong/Multiple Answer

try to take over the world!

Version au 06/04/2018. Voir la dernière version.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name         WaniKani Fast Abridged Wrong/Multiple Answer
// @namespace    http://tampermonkey.net/
// @version      2.5
// @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
// @grant        none
// ==/UserScript==

window.wk_fawa = {};

var wrongCountFAWA;
(function(global) {
    'use strict';
    // Hook into App Store
    try { $('.app-store-menu-item').remove(); $('<li class="app-store-menu-item"><a href="https://community.wanikani.com/t/there-are-so-many-user-scripts-now-that-discovering-them-is-hard/20709">App Store</a></li>').insertBefore($('.navbar .dropdown-menu .nav-header:contains("Account")')); window.appStoreRegistry = window.appStoreRegistry || {}; window.appStoreRegistry[GM_info.script.uuid] = GM_info; localStorage.appStoreRegistry = JSON.stringify(appStoreRegistry); } catch (e) {}

    if (!window.wkof) {
        alert('WaniKani Fast Abridged Wrong/Multiple Answer requires Wanikani Open Framework.\nYou will now be forwarded to installation instructions.');
        window.location.href = 'https://community.wanikani.com/t/instructions-installing-wanikani-open-framework/28549';
        return;
    }

    var settings_dialog;
    var defaults = {
        alwaysShow: false,
        alwaysShowOnlyMultiple: false,
        dontShowWrong: false,
        correctColor: "#88cc00",
        incorrectColor: "#ff0033"
    };

    if(localStorage.getItem("wkFastWrongAlwaysShow") != null){
        defaults.alwaysShow = localStorage.getItem("wkFastWrongAlwaysShow");
        defaults.alwaysShowOnlyMultiple = localStorage.getItem("wkFastWrongAlwaysShowOnlyMultiple");
        defaults.dontShowWrong = localStorage.getItem("wkFastWrongDontShowWrong");
        localStorage.removeItem("wkFastWrongAlwaysShow");
        localStorage.removeItem("wkFastWrongAlwaysShowOnlyMultiple");
        localStorage.removeItem("wkFastWrongDontShowWrong");
    }
    if(localStorage.getItem("wkFastWrongWrongColor") != null){
        defaults.correctColor = localStorage.getItem("wkFastWrongWrongColor");
        defaults.incorrectColor = localStorage.getItem("wkFastWrongMultipleColor");
        localStorage.removeItem("wkFastWrongWrongColor");
        localStorage.removeItem("wkFastWrongMultipleColor");
    }

    wrongCountFAWA = $.jStorage.get("wrongCount");
    if(window.location.pathname == "/" || window.location.pathname == "/dashboard"){
        wkof.include('Apiv2, Menu, Settings');
        wkof.ready('Menu').then(install_menu);
        wkof.ready('Settings').then(install_settings);
    } else {
        wkof.include('Apiv2, Settings');
        wkof.ready('Settings').then(install_settings).then(function(){
            $('#user-response').after("<input id='lblCorrect' type='text' style='display: none;' disabled/>");
            $.jStorage.listenKeyChange('currentItem', function (key, action) {
                if (action === 'updated') {
                    $('#lblCorrect').val('').css('display','none');
                }
            });
            $.jStorage.listenKeyChange('questionCount', function (key, action) {
                if(wrongCountFAWA != $.jStorage.get("wrongCount"))
                {
                    wrongCountFAWA = $.jStorage.get("wrongCount");
                    if(wkof.settings.fawa.dontShowWrong != "1"){
                        showCorrect(0);
                    }
                }
                else {
                    if (action === 'updated' && $.jStorage.get("questionCount") > 0 && wkof.settings.fawa.alwaysShow == "1") {
                        showCorrect(1);
                    }
                }
            });
        });
    }

    function install_menu() {
        wkof.Menu.insert_script_link({
            script_id: 'fawa',
            name: 'fawa',
            submenu:   'Settings',
            title:     'Fast Abridged Wrong/Multiple Answer',
            on_click:  open_settings
        });
    }
    function open_settings() {
        settings_dialog.open();
    }
    function install_settings() {
        settings_dialog = new wkof.Settings({
            script_id: 'fawa',
            name: 'fawa',
            title: 'Fast Abridged Wrong/Multiple Answer',
            on_save: process_settings,
            settings: {
				'grp_main': {
                    type:'group',
                    label:'Main',
                    content:{
                        'alwaysShow': {type:'checkbox',label:'Always Show Correct Answers',default:defaults.alwaysShow},
                        'alwaysShowOnlyMultiple': {type:'checkbox',label:'&nbsp;&nbsp;&nbsp;(Only if multiple answers)',default:defaults.alwaysShowOnlyMultiple},
                        'dontShowWrong': {type:'checkbox',label:'&nbsp;&nbsp;&nbsp;(Don\'t show wrongs)',default:defaults.dontShowWrong}
                    }
                },
                'grp_colors':{
                    type: 'group',
                    label: 'colors',
                    content: {
                        'correctColor': {type:'color',label:'Correct',default:defaults.correctColor},
                        'incorrectColor': {type:'color',label:'Incorrect',default:defaults.incorrectColor},
                    }
                }
            }
        });
        settings_dialog.load().then(function(){
            wkof.settings.fawa = $.extend(true, {}, defaults,wkof.settings.fawa);
        });
    }
    function process_settings(){
        settings_dialog.save();
        console.log('Settings saved!');
    }

    function showBar(mode){//0=wrong, 1=right
        $('#lblCorrect').css('display','block');
        $('#lblCorrect').attr('style','display: block; background-color: ' + ((mode == 0) ? wkof.settings.fawa.incorrectColor : wkof.settings.fawa.correctColor) + ' !important;');
    }

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

})(window.wk_fawa);