Wanikani Lightning Mode

Eliminates second Enter or Click for correct review answers.

当前为 2015-10-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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.0
// @author      Robin Findley
// @copyright   2015+, Robin Findley
// @license     MIT; http://opensource.org/licenses/MIT
// @run-at      document-end
// @grant       none
// ==/UserScript==

// This script was adapted from Kyle Coburn's original "WaniKani Customizer" plugin for Chrome.

(function(){

    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;
    }

    function main() {
        addStyle('#lightning-mode.active {color:#ff0; opacity:1.0;}');

        lightning = localStorage.getItem('lightning');
        if (lightning === 'false') 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':
                        $('#answer-form button').click();
                        break;
                    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);

}).call({});