WaniKani Customize Wrap Up

Customize the number of wrap-up items

当前为 2016-11-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WaniKani Customize Wrap Up
  3. // @namespace http://alsanchez.es/
  4. // @description Customize the number of wrap-up items
  5. // @include /^https?://(www\.)?wanikani\.com/review/session/?$/
  6. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10.  
  11. (function()
  12. {
  13. var numberOfItems = localStorage.getItem("wanikani-addon-number-of-wrap-up-items") || 10;
  14. var fn = loadingScreen.remove;
  15. var wrapUpActive = false;
  16. loadingScreen.remove = function()
  17. {
  18. loadingScreen.remove = fn;
  19. fn();
  20. var wrapUp = $("#option-wrap-up");
  21. wrapUp.bindFirst("click", function()
  22. {
  23. wrapUpActive = !wrapUpActive;
  24. if(wrapUpActive)
  25. {
  26. updateQueues(numberOfItems);
  27. }
  28. });
  29. wrapUp.click(function()
  30. {
  31. // Force available-count update
  32. $.jStorage.set("activeQueue", $.jStorage.get("activeQueue"));
  33. });
  34. var control = $('<span style="cursor: pointer;"><i class="icon-time"></i><span id="number-of-wrap-up-items">' + numberOfItems +'<span></span>');
  35. $("#stats").prepend(control);
  36. control.click(function()
  37. {
  38. var answer = prompt("Number of items");
  39. if(answer !== null)
  40. {
  41. numberOfItems = answer;
  42. $("#number-of-wrap-up-items").html(numberOfItems);
  43. localStorage.setItem("wanikani-addon-number-of-wrap-up-items", numberOfItems);
  44. }
  45. });
  46. }
  47. function updateQueues(numberOfItems)
  48. {
  49. var activeQueue = getSortedActiveQueue();
  50. var reviewQueue = $.jStorage.get("reviewQueue");
  51. var newQueue = getSortedActiveQueue().concat(reviewQueue);
  52. numberOfItems = Math.min(numberOfItems, newQueue.length);
  53. $.jStorage.set("activeQueue", newQueue.slice(0, numberOfItems));
  54. $.jStorage.set("reviewQueue", newQueue.slice(numberOfItems));
  55. $.jStorage.set("questionCount", 6);
  56. }
  57. function getSortedActiveQueue()
  58. {
  59. var currentItem = $.jStorage.get("currentItem");
  60. var otherItems = $.jStorage.get("activeQueue").filter(function(item)
  61. {
  62. return item.id !== currentItem.id;
  63. });
  64. return [ currentItem ].concat(otherItems);
  65. }
  66. })();
  67.  
  68. /*
  69. * jQuery.bind-first library v0.2.3
  70. * Copyright (c) 2013 Vladimir Zhuravlev
  71. *
  72. * Released under MIT License
  73. * @license
  74. *
  75. * Date: Thu Feb 6 10:13:59 ICT 2014
  76. **/
  77. (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);