Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Cleverflow
- // @namespace http://waniiikaniii.com/
- // @include http://www.wanikani.com/review
- // @version 2.0
- // @grant GM_addStyle
- // @grant GM_getResourceText
- // @run-at document-end
- // @require http://code.jquery.com/jquery-1.9.1.min.js
- // @require http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.1.1/jquery.qtip.min.js
- // @resource qtipCSS http://www.michaelfrank.com.br/wanikani_improve/jquery.qtip.min.css
- // ==/UserScript==
- //This is the timer that dictates how long before it switches to next item
- var timer = 200;
- //This is the timer that dictates how quickly to check for a new item to update the 'last item' button
- var timer_showNextItem = 350;
- var qtipCSS = GM_getResourceText("qtipCSS");
- GM_addStyle(qtipCSS);
- var playAudio = 0;
- var lastItem = "";
- var lastType = "";
- var isAudioPlaying = 0;
- var saved_lastType = "";
- var saved_lastItem = "";
- var saved_currentItem="";
- var currentItem = "";
- var currentType = "";
- var previousItem = "";
- var previousType = "";
- var previousItemURL = "";
- var submittedAnswer = "";
- var previousCorrect = false;
- function reviewLoaded()
- {
- if ($('#loading').is(':visible'))
- {
- console.log('Initial load in progress...');
- setTimeout(reviewLoaded, 250);
- }
- else
- {
- $('<li id="option-show-previous"><span title="Check previous item"><i class="icon-question-sign"></i></span></li>').insertAfter('#option-home').addClass('disabled');
- $('<style type="text/css"> .qtip{ max-width: 380px !important; } #additional-content ul li { width: 16% !important; } #additional-content {text-align: center;} #option-show-previous img { max-width: 12px; background-color: #00A2F3; padding: 2px 3px; }</style>').appendTo('head');
- console.log('Initial load finished');
- }
- }
- function checkAnswer()
- {
- previousItem = $.trim($('#character span').html());
- previousType = $('#character').attr('class');
- console.log('previousItem: ' + previousItem);
- console.log('previousType: ' + previousType);
- if($('#answer-form form fieldset').hasClass('correct'))
- {
- previousCorrect = true;
- console.log('Correct answer. Moving to the next item.');
- $('#option-show-previous span').css('background-color', '#FBFBFB');
- }
- else if($('#answer-form form fieldset').hasClass('incorrect'))
- {
- previousCorrect = false;
- console.log('Wrong answer. We will move to the next item and change the button color to red');
- $('#option-show-previous span').css('background-color', '#FF8E8E');
- }
- $('#answer-form button').click();
- currentItem = $.trim($('#character span').html());
- currentType = $('#character').attr('class');
- console.log('currentItem: ' + currentItem);
- console.log('currentType: ' + currentType);
- if(previousItem != currentItem)
- {
- if(previousItem == '')
- {
- $('#option-show-previous').addClass('disabled');
- $('#option-show-previous span').attr('title', 'Previous item unavailable').html('<i class="icon-question-sign"></i> ' + previousItem);
- console.log('lastItem: Previous item unavailable');
- }
- else
- {
- $('#option-show-previous').removeClass('disabled');
- if(previousCorrect === true)
- $('#option-show-previous span').attr('title', 'Check the previous ' + previousType).html('<i class="icon-question-sign"></i> ' + previousItem);
- else
- $('#option-show-previous span').attr('title', 'You answered ' + submittedAnswer).html('<i class="icon-question-sign"></i> ' + previousItem);
- previousItemURL = 'http://www.wanikani.com/quickview/';
- if (previousType == 'kanji')
- {
- previousItemURL += 'kanji/' + previousItem + '/';
- }
- else if (previousType == 'vocabulary')
- {
- previousItemURL += 'vocabulary/' + previousItem + '/';
- }
- else
- {
- previousItemURL += 'radicals/' + submittedAnswer.toLowerCase().replace(' ', '-') + '/';
- }
- console.log('previousItemURL: ' + previousItemURL);
- }
- }
- $('#option-show-previous').not('.disabled').on('click', function(event) {
- $(this).qtip({
- show: 'click',
- hide: 'unfocus',
- overwrite: true,
- content: {
- title: 'Previous ' + previousType,
- text: '<iframe src="' + previousItemURL + '" frameborder="0" marginheight="0" style="width:350px; height: 250px; overflow-x: hidden; overflow-y: scroll"></iframe>'
- },
- position: {
- my: 'Top Center',
- at: 'Bottom Center',
- viewport: $(window)
- },
- show: {
- event: event.type, // Use the same event type as above
- ready: true // Show immediately - important!
- },
- events: {
- hide: function(event, api) {
- $(this).qtip('destroy');
- }
- },
- style: 'qtip-bootstrap'
- });
- });
- }
- $(document).keypress(function(e) {
- if(e.which == 13)
- {
- submittedAnswer = $('#user-response').val();
- console.log('submittedAnswer: ' + submittedAnswer);
- setTimeout(checkAnswer, timer_showNextItem);
- }
- });
- reviewLoaded();
- setTimeout(WaitForCorrectAnswer, timer);
- function MoveToNextQuestion()
- {
- checkAnswer();
- isAudioPlaying = 0;
- setTimeout(WaitForCorrectAnswer, timer);
- }
- function PlayAudioClipThenMove()
- {
- if ($(".play")[0] != undefined)
- {
- $(".play")[0].click();
- setTimeout(MoveToNextQuestion, 2000);
- }
- else
- {
- setTimeout(MoveToNextQuestion,timer);
- }
- }
- function WaitForCorrectAnswer()
- {
- if (($('fieldset').attr("class") == "correct") && (isAudioPlaying == 0))
- {
- if ((playAudio == 1) && ($("#option-audio").attr("class") != "disabled"))
- {
- isAudioPlaying = 1;
- setTimeout(PlayAudioClipThenMove, timer);
- }
- else {
- setTimeout(MoveToNextQuestion,timer);
- }
- }
- else
- {
- setTimeout(WaitForCorrectAnswer, timer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement