Advertisement
Guest User

wanikani improve 1.3

a guest
Jul 25th, 2013
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name WaniKani Improve
  3. // @namespace http://www.michaelfrank.com.br/wanikani_improve/
  4. // @include http://www.wanikani.com/review
  5. // @version 1.3
  6. // @grant GM_addStyle
  7. // @grant GM_getResourceText
  8. // @run-at document-end
  9. // @require http://code.jquery.com/jquery-1.9.1.min.js
  10. // @require http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.1.1/jquery.qtip.min.js
  11. // @resource qtipCSS http://qtip2.com/v/stable/jquery.qtip.min.css
  12. // ==/UserScript==
  13.  
  14. // time in miliseconds to move to the next item in the review session
  15. // if set too low, the script will not be able to check if the answer was correct
  16. var timer_showNextItem = 50;
  17.  
  18.  
  19. var qtipCSS = GM_getResourceText("qtipCSS");
  20. GM_addStyle(qtipCSS);
  21.  
  22. var currentItem = "";
  23. var currentType = "";
  24. var previousItem = "";
  25. var previousType = "";
  26. var previousItemURL = "";
  27.  
  28. function reviewLoaded()
  29. {
  30. if ($('#loading').is(':visible'))
  31. {
  32. console.log('Initial load in progress...');
  33. setTimeout(reviewLoaded, 150);
  34. }
  35. else
  36. {
  37. $('<li id="option-show-previous"><span title="Check previous item"><i class="icon-question-sign"></i></span></li>').insertAfter('#option-home').addClass('disabled');
  38. $('<style type="text/css"> .qtip{ max-width: 380px !important; } #additional-content ul li { width: 16% !important; } #additional-content {text-align: center;}</style>').appendTo('head');
  39.  
  40. // we check if the key pressed is the ENTER key
  41. $('#user-response').keydown(function (e){
  42. if(e.keyCode == 13)
  43. {
  44. setTimeout(checkAnswer, timer_showNextItem);
  45. }
  46. });
  47.  
  48. console.log('Initial load finished');
  49. }
  50. }
  51.  
  52. function checkAnswer()
  53. {
  54. previousItem = $.trim($('#character').text());
  55. previousType = $('#character').attr('class');
  56.  
  57. console.log('previousItem: ' + previousItem);
  58. console.log('previousType: ' + previousType);
  59.  
  60. if($('#answer-form form fieldset').hasClass('correct'))
  61. {
  62. $('#answer-form button').click();
  63. console.log('Correct answer. Moving to the next item.');
  64. }
  65. else
  66. {
  67. console.log('Wrong answer. We will not move to the next item.');
  68. }
  69.  
  70.  
  71. if (currentItem != previousItem)
  72. {
  73. currentItem = $.trim($('#character').text());
  74. currentType = $('#character').attr('class');
  75.  
  76. console.log('currentItem: ' + currentItem);
  77. console.log('currentType: ' + currentType);
  78.  
  79. if(previousItem == '')
  80. {
  81. console.log('lastItem: Previous item unavailable');
  82. }
  83. else
  84. {
  85. $('#option-show-previous').removeClass('disabled');
  86. $('#option-show-previous span').attr('title', 'Check the ' + previousType + ' ' + previousItem).html('<i class="icon-question-sign"></i> ' + previousItem);
  87.  
  88. previousItemURL = 'http://www.wanikani.com/quickview/';
  89.  
  90. if (previousType == 'kanji')
  91. {
  92. previousItemURL += 'kanji/' + previousItem + '/';
  93. }
  94. else if (previousType == 'vocabulary')
  95. {
  96. previousItemURL += 'vocabulary/' + previousItem + '/';
  97. }
  98. else
  99. {
  100. previousItemURL += 'radicals/' + previousItem + '/';
  101. }
  102. }
  103.  
  104. console.log('previousItemURL: ' + previousItemURL);
  105. }
  106.  
  107. $('#option-show-previous').not('.disabled').on('click', function(event) {
  108. $(this).qtip({
  109. show: 'click',
  110. hide: 'unfocus',
  111. overwrite: true, // Don't overwrite tooltips already bound
  112. content: {
  113. title: 'Previous ' + previousType,
  114. text: '<iframe src="' + previousItemURL + '" frameborder="0" marginheight="0" style="width:350px; height: 250px; overflow-x: hidden; overflow-y: scroll"></iframe>'
  115. },
  116. position: {
  117. my: 'Top Center',
  118. at: 'Bottom Center',
  119. viewport: $(window)
  120. },
  121. show: {
  122. event: event.type, // Use the same event type as above
  123. ready: true // Show immediately - important!
  124. },
  125. style: 'qtip-bootstrap'
  126. });
  127. });
  128. }
  129.  
  130. // initial load
  131. reviewLoaded();
Advertisement
RAW Paste Data Copied
Advertisement