Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Cleverflow (with audio)
- // @namespace http://waniiikaniii.com/
- // @include http://www.wanikani.com/review/session
- // @version 2.5
- // @grant GM_addStyle
- // @grant GM_getResourceText
- // @run-at document-end
- // @require http://code.jquery.com/jquery-1.9.1.min.js
- // ==/UserScript==
- //This is the timer that dictates how quickly to check for a new item to update the 'last item' button
- var timer_showNextItem = 350;
- //AUDIO SETTINGS
- //This toggles the audio on or off: ON = 1, OFF = 0
- var playAudioWhenAvailable = 1;
- //This is the timer that dictates how long it gives the audio to play before moving on to the next item
- var timer_audioPlayTime = 1500;
- var lastItem = "";
- var lastType = "";
- 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>').insertBefore('#option-last-items').addClass('disabled');
- $('#additional-content ul').css('text-align','center');
- $('#additional-content ul li').css('width','16%');
- 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');
- }
- if (playAudioWhenAvailable == 1)
- {
- playAudioThenMove();
- }
- else
- {
- moveToNextItem();
- }
- }
- function playAudioThenMove()
- {
- console.log('Attempting to play audio clip before advancing');
- if ($("#option-audio").attr('class') != "disabled")
- {
- $("#option-audio").click();
- setTimeout(moveToNextItem, timer_audioPlayTime);
- }
- else
- {
- moveToNextItem();
- }
- }
- function moveToNextItem()
- {
- $('#answer-form button').click();
- currentItem = $.trim($('#character span').html());
- currentType = $('#character').attr('class');
- console.log('currentItem: ' + currentItem);
- console.log('currentType: ' + currentType);
- if(previousItem != currentItem)
- {
- $('#option-show-previous').off("click");
- 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/';
- 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').on("click", function(event){ window.open(previousItemURL); });
- }
- }
- }
- $(document).keyup(function(e) {
- code = (e.keyCode ? e.keyCode : e.which);
- if(code == 13)
- {
- submittedAnswer = $('#user-response').val();
- console.log('submittedAnswer: ' + submittedAnswer);
- setTimeout(checkAnswer, timer_showNextItem);
- }
- });
- reviewLoaded();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement