Advertisement
Guest User

Cleverflow by Thenn42 (Tweaked by Psycoder)

a guest
Jul 4th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       WaniKani Flash Forward
  3. // @namespace thenn42.eu/userscripts
  4. // @description Automatically moves to the next item, and replaces the kana chart button with previous item's info page link.  Optionally will play audio (when available) before advancing.
  5. // @include    http://www.wanikani.com/review/*
  6. // @version    0.3
  7. // @run-at document-end
  8. // @require http://code.jquery.com/jquery-1.9.1.min.js
  9. // @grant GM_log
  10. // ==/UserScript==
  11. var playAudio = 0;
  12. var timer = 500;
  13. var lastItem = "";
  14. var currentItem = "";
  15. var lastType = "";
  16. var currentType = "";
  17. var url = "";
  18. var isAudioPlaying = 0;
  19. WhenNewQuestion();
  20. setTimeout(WaitForCorrectAnswer, timer);
  21.  
  22. function MoveToNextQuestion() {
  23.     $('#option-submit').click();
  24.     isAudioPlaying = 0;
  25.     setTimeout(WaitForCorrectAnswer, timer);
  26. }
  27.  
  28. function PlayAudioClipThenMove() {
  29.     if ($(".play")[0] != undefined) {
  30.         $(".play")[0].click();
  31.         setTimeout(MoveToNextQuestion, 2000);
  32.     } else {
  33.         MoveToNextQuestion();
  34.     }
  35. }
  36.  
  37. function WaitForCorrectAnswer() {
  38.     if (($('fieldset').attr("class") == "correct") && (isAudioPlaying == 0)) {
  39.         if ((playAudio == 1) && ($("#option-audio").attr("class") != "inactive")) {
  40.             isAudioPlaying = 1;
  41.             setTimeout(PlayAudioClipThenMove, timer);
  42.         } else {
  43.             MoveToNextQuestion();
  44.         }
  45.     } else {
  46.         setTimeout(WaitForCorrectAnswer, timer);
  47.     }
  48. }
  49.  
  50. function WhenNewQuestion() {
  51.     currentType = $("#item-box").find("h1").attr("class");
  52.     if (currentType == "vocabulary") {
  53.         currentItem = $("#item-box").find("h1 small").text();
  54.     } else if (currentType == "kanji") {
  55.         currentItem = $("#item-box").find("h1").text();
  56.     } else {
  57.         currentItem = $("#meanings p").text().toLowerCase();
  58.         currentItem = currentItem.replace(" ","-");
  59.     }
  60.     if (currentItem != lastItem) {
  61.         url = "http://www.wanikani.com/quickview/";
  62.         if (lastType == "kanji") {
  63.             url += "kanji\/"+lastItem;
  64.         } else if (lastType=="vocabulary") {
  65.             url += "vocabulary\/" + lastItem;
  66.         } else {
  67.             url += "radicals\/" + lastItem;
  68.         }
  69.         $("#option-kana-chart").replaceWith("<li id=\"option-kana-chart\"><a target=\"_blank\" href=\""+url+"\"><i class=\"icon-question-sign\"></i></a></li>");
  70.     }
  71.     lastType = currentType;
  72.     lastItem = currentItem;
  73. }
  74.  
  75. $('#item-info-sub').bind('DOMNodeInserted', WhenNewQuestion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement