Advertisement
Seiji

WK CleverflowMOD v1

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