WaniKani Review Item Delay

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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');
}());