Advertisement
Guest User

Untitled

a guest
Jul 24th, 2013
219
0
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/
  4. // @include http://www.wanikani.com/review
  5. // @version 2.1
  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. var qtipCSS = GM_getResourceText("qtipCSS");
  15. GM_addStyle(qtipCSS);
  16.  
  17. var playAudio = 0;
  18. var timer = 200;
  19. var lastItem = "";
  20. var currentItem = "";
  21. var lastType = "";
  22. var currentType = "";
  23. var url = "";
  24. var isAudioPlaying = 0;
  25. var saved_lastType = "";
  26. var saved_lastItem = "";
  27. var saved_currentItem="";
  28.  
  29. WhenNewQuestion();
  30. setTimeout(WaitForCorrectAnswer, timer);
  31.  
  32. $('<li id="option-show-previous"><span><i class="icon-question-sign"></i></span></li>').insertAfter('#option-home').addClass('disabled').attr('title','Previous item unavailable');
  33. $('#hotkeys').text('');
  34. $('<style type="text/css"> .qtip{ max-width: 380px !important; } #reviews nav li { width: 16% !important; }</style>').appendTo('head');
  35.  
  36. $("ul li").attr("style","width: 16.6%");
  37.  
  38. function MoveToNextQuestion()
  39. {
  40.     $('button').click();
  41.     isAudioPlaying = 0;
  42.     setTimeout(WaitForCorrectAnswer, timer);
  43. }
  44.  
  45. function PlayAudioClipThenMove()
  46. {
  47.     if ($(".play")[0] != undefined)
  48.     {
  49.         $(".play")[0].click();
  50.         setTimeout(MoveToNextQuestion, 2000);
  51.     }
  52.     else
  53.     {
  54.         MoveToNextQuestion();
  55.     }
  56. }
  57.  
  58. function WaitForCorrectAnswer()
  59. {
  60.         if (($('fieldset').attr("class") == "correct") && (isAudioPlaying == 0))
  61.         {
  62.             if ((playAudio == 1) && ($("#option-audio").attr("class") != "disabled"))
  63.             {
  64.                 isAudioPlaying = 1;
  65.                 setTimeout(PlayAudioClipThenMove, timer);
  66.             }
  67.             else {
  68.                 MoveToNextQuestion();
  69.             }
  70.         }
  71.         else
  72.         {
  73.             setTimeout(WaitForCorrectAnswer, timer);
  74.         }
  75. }
  76.  
  77. function WhenNewQuestion()
  78. {
  79.         currentType = $("#character").attr("class");
  80.  
  81.         if (currentType == "vocabulary")
  82.         {
  83.                 currentItem = $("#character").find("span").text();
  84.         }
  85.         else if (currentType == "kanji")
  86.         {
  87.                 currentItem = $("#character").find("span").text();
  88.         }
  89.         else
  90.         {
  91.                 /*currentItem = $("#meanings p").text().toLowerCase();
  92.                 currentItem = currentItem.replace(" ","-");*/
  93.                 currentItem ='';
  94.         }
  95.         if (currentItem != lastItem)
  96.         {
  97.                 saved_currentItem = $('#character').children("span").text();
  98.                 if(lastItem == '')
  99.                 {
  100.                     $('#option-show-previous').addClass('disabled').attr('title', 'Previous item unavailable');
  101.                 }
  102.                 else
  103.                 {
  104.                     saved_lastType = lastType;
  105.  
  106.                     $('#option-show-previous').removeClass('disabled').attr('title', 'Check more information about the ' + saved_lastType + ' ' + saved_lastItem).html('<span><i class="icon-question-sign"></i> ' + saved_lastItem+'</span>');
  107.  
  108.                     url = "http://www.wanikani.com/quickview/";
  109.                     if (lastType == "kanji")
  110.                     {
  111.                             url += "kanji\/"+lastItem;
  112.                     }
  113.                     else if (lastType=="vocabulary")
  114.                     {
  115.                             url += "vocabulary\/" + lastItem;
  116.                     }
  117.                     else
  118.                     {
  119.                             url += "radicals\/" + lastItem;
  120.                     }
  121.                 }
  122.         }
  123.  
  124.         $('#hotkeys').text('');
  125.  
  126.         saved_lastItem = saved_currentItem;
  127.  
  128.         lastType = currentType;
  129.         lastItem = currentItem;
  130.  
  131.  
  132.         $('#option-show-previous').not('.inactive').on('click', function(event) {
  133.              $(this).qtip({
  134.                 show: 'click',
  135.                 hide: 'unfocus',
  136.                 overwrite: true, // Don't overwrite tooltips already bound
  137.                 content: {
  138.                     title: 'Previous ' + saved_lastType,
  139.                     text: '<iframe src="' + url + '" frameborder="0" marginheight="0" style="width:350px; height: 250px; overflow-x: hidden; overflow-y: scroll"></iframe>'
  140.                 },
  141.                 position: {
  142.                     my: 'Top Center',
  143.                     at: 'Bottom Center',
  144.                     viewport: $(window)
  145.                 },
  146.                 show: {
  147.                     event: event.type, // Use the same event type as above
  148.                     ready: true // Show immediately - important!
  149.                 },
  150.                 style: 'qtip-bootstrap'
  151.             });
  152.         });
  153.  
  154. }
  155.  
  156. $("#question-type").on("DOMNodeInserted", WhenNewQuestion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement