Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name WaniKani Improve
- // @namespace http://www.michaelfrank.com.br/wanikani_improve/
- // @include http://www.wanikani.com/review
- // @version 1.3
- // @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://qtip2.com/v/stable/jquery.qtip.min.css
- // ==/UserScript==
- // time in miliseconds to move to the next item in the review session
- // if set too low, the script will not be able to check if the answer was correct
- var timer_showNextItem = 50;
- var qtipCSS = GM_getResourceText("qtipCSS");
- GM_addStyle(qtipCSS);
- var currentItem = "";
- var currentType = "";
- var previousItem = "";
- var previousType = "";
- var previousItemURL = "";
- function reviewLoaded()
- {
- if ($('#loading').is(':visible'))
- {
- console.log('Initial load in progress...');
- setTimeout(reviewLoaded, 150);
- }
- 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;}</style>').appendTo('head');
- // we check if the key pressed is the ENTER key
- $('#user-response').keydown(function (e){
- if(e.keyCode == 13)
- {
- setTimeout(checkAnswer, timer_showNextItem);
- }
- });
- console.log('Initial load finished');
- }
- }
- function checkAnswer()
- {
- previousItem = $.trim($('#character').text());
- previousType = $('#character').attr('class');
- console.log('previousItem: ' + previousItem);
- console.log('previousType: ' + previousType);
- if($('#answer-form form fieldset').hasClass('correct'))
- {
- $('#answer-form button').click();
- console.log('Correct answer. Moving to the next item.');
- }
- else
- {
- console.log('Wrong answer. We will not move to the next item.');
- }
- if (currentItem != previousItem)
- {
- currentItem = $.trim($('#character').text());
- currentType = $('#character').attr('class');
- console.log('currentItem: ' + currentItem);
- console.log('currentType: ' + currentType);
- if(previousItem == '')
- {
- console.log('lastItem: Previous item unavailable');
- }
- else
- {
- $('#option-show-previous').removeClass('disabled');
- $('#option-show-previous span').attr('title', 'Check the ' + previousType + ' ' + previousItem).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/' + previousItem + '/';
- }
- }
- console.log('previousItemURL: ' + previousItemURL);
- }
- $('#option-show-previous').not('.disabled').on('click', function(event) {
- $(this).qtip({
- show: 'click',
- hide: 'unfocus',
- overwrite: true, // Don't overwrite tooltips already bound
- 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!
- },
- style: 'qtip-bootstrap'
- });
- });
- }
- // initial load
- reviewLoaded();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement