Customize the number of wrap-up items
当前为
- // ==UserScript==
- // @name WaniKani Customize Wrap Up
- // @namespace http://alsanchez.es/
- // @description Customize the number of wrap-up items
- // @include /^https?://(www\.)?wanikani\.com/review/session/?$/
- // @version 1
- // @grant none
- // ==/UserScript==
- (function()
- {
- var numberOfItems = localStorage.getItem("wanikani-addon-number-of-wrap-up-items") || 10;
- var fn = loadingScreen.remove;
- var wrapUpActive = false;
- loadingScreen.remove = function()
- {
- loadingScreen.remove = fn;
- fn();
- var wrapUp = $("#option-wrap-up");
- wrapUp.bindFirst("click", function()
- {
- wrapUpActive = !wrapUpActive;
- if(wrapUpActive)
- {
- updateQueues(numberOfItems);
- }
- });
- wrapUp.click(function()
- {
- // Force available-count update
- $.jStorage.set("activeQueue", $.jStorage.get("activeQueue"));
- });
- var control = $('<span style="cursor: pointer;"><i class="icon-time"></i><span id="number-of-wrap-up-items">' + numberOfItems +'<span></span>');
- $("#stats").prepend(control);
- control.click(function()
- {
- var answer = prompt("Number of items");
- if(answer !== null)
- {
- numberOfItems = answer;
- $("#number-of-wrap-up-items").html(numberOfItems);
- localStorage.setItem("wanikani-addon-number-of-wrap-up-items", numberOfItems);
- }
- });
- }
- function updateQueues(numberOfItems)
- {
- var activeQueue = getSortedActiveQueue();
- var reviewQueue = $.jStorage.get("reviewQueue");
- var newQueue = getSortedActiveQueue().concat(reviewQueue);
- numberOfItems = Math.min(numberOfItems, newQueue.length);
- $.jStorage.set("activeQueue", newQueue.slice(0, numberOfItems));
- $.jStorage.set("reviewQueue", newQueue.slice(numberOfItems));
- $.jStorage.set("questionCount", 6);
- }
- function getSortedActiveQueue()
- {
- var currentItem = $.jStorage.get("currentItem");
- var otherItems = $.jStorage.get("activeQueue").filter(function(item)
- {
- return item.id !== currentItem.id;
- });
- return [ currentItem ].concat(otherItems);
- }
- })();
- /*
- * jQuery.bind-first library v0.2.3
- * Copyright (c) 2013 Vladimir Zhuravlev
- *
- * Released under MIT License
- * @license
- *
- * Date: Thu Feb 6 10:13:59 ICT 2014
- **/
- (function(t){function e(e){return u?e.data("events"):t._data(e[0]).events}function n(t,n,r){var i=e(t),a=i[n];if(!u){var s=r?a.splice(a.delegateCount-1,1)[0]:a.pop();return a.splice(r?0:a.delegateCount||0,0,s),void 0}r?i.live.unshift(i.live.pop()):a.unshift(a.pop())}function r(e,r,i){var a=r.split(/\s+/);e.each(function(){for(var e=0;a.length>e;++e){var r=t.trim(a[e]).match(/[^\.]+/i)[0];n(t(this),r,i)}})}function i(e){t.fn[e+"First"]=function(){var n=t.makeArray(arguments),i=n.shift();return i&&(t.fn[e].apply(this,arguments),r(this,i)),this}}var a=t.fn.jquery.split("."),s=parseInt(a[0]),f=parseInt(a[1]),u=1>s||1==s&&7>f;i("bind"),i("one"),t.fn.delegateFirst=function(){var e=t.makeArray(arguments),n=e[1];return n&&(e.splice(0,2),t.fn.delegate.apply(this,arguments),r(this,n,!0)),this},t.fn.liveFirst=function(){var e=t.makeArray(arguments);return e.unshift(this.selector),t.fn.delegateFirst.apply(t(document),e),this},u||(t.fn.onFirst=function(e,n){var i=t(this),a="string"==typeof n;if(t.fn.on.apply(i,arguments),"object"==typeof e)for(type in e)e.hasOwnProperty(type)&&r(i,type,a);else"string"==typeof e&&r(i,e,a);return i})})(jQuery);