WaniKani Review Item Delay

skip the current item and move it to the end of the queue

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          WaniKani Review Item Delay
// @namespace     https://www.wanikani.com
// @description   skip the current item and move it to the end of the queue
// @version       0.1.0
// @include       https://www.wanikani.com/review/session
// @run-at        document-end
// @grant         none
// ==/UserScript==

/*jslint browser: true*/
/*global $, console */

(function () {
    'use strict';

    function askNewQuestion() {
        $('#user-response').prop('disabled', true);
        $('#answer-form button').click();
    }
    function skipPushEnd() {
        var currentItem = $.jStorage.get('currentItem'),
            activeQueue = $.jStorage.get('activeQueue'),
            reviewQueue = $.jStorage.get('reviewQueue'),
            originalLength = activeQueue.length;
        activeQueue = $.grep(activeQueue, function (item) {
            return !(currentItem.id === item.id && (
                (currentItem.rad && item.rad) || (currentItem.kan && item.kan) || (currentItem.voc && item.voc)
            ));
        });
        if (0 < activeQueue.length && activeQueue.length < originalLength) {
            reviewQueue.unshift(currentItem); // add to beginning (last to be removed)
            activeQueue.push(reviewQueue.pop()); // add next item to replace removed
            $.jStorage.set('reviewQueue', reviewQueue);
            $.jStorage.set('activeQueue', activeQueue); // triggers callback (counters)
        }
        askNewQuestion();
    }
    function init() {
        $('footer').prepend('<button id="wkrid_DelayButton" title="skip current item, move to end">Delay</button>');
        $('footer').prepend('<button id="wkrid_SkipButton" title="ask new random question">Skip</button>');
        $('#wkrid_DelayButton').click(skipPushEnd);
        $('#wkrid_SkipButton').click(askNewQuestion);
    }
    // from: https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js
    function addStyle(aCss) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (head) {
            style = document.createElement('style');
            style.setAttribute('type', 'text/css');
            style.textContent = aCss;
            head.appendChild(style);
            return style;
        }
        return null;
    }
    addStyle('\n' +
        '#wkrid_DelayButton, #wkrid_SkipButton {\n' +
        '    background-color: #0000CC;\n' +
        '    color: #FFFFFF;\n' +
        '    border: medium none;\n' +
        '    border-radius: 3px 3px 0 0;\n' +
        '    display: inline-block;\n' +
        '    font-size: 0.8125em;\n' +
        '    padding: 10px;\n' +
        '    margin-right: 2px;\n' +
        '    font-weight: bold;\n' +
        '}\n');
    setTimeout(init, 100); // init after other scripts like WKO
    console.log('WaniKani Review Item Delay: script load end');
}());