Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name WaniKani Improve
- // @namespace http://www.michaelfrank.com.br/
- // @include http://www.wanikani.com/review/*
- // @version 2
- // @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==
- var qtipCSS = GM_getResourceText("qtipCSS");
- GM_addStyle(qtipCSS);
- var playAudio = 0;
- var timer = 200;
- var lastItem = "";
- var currentItem = "";
- var lastType = "";
- var currentType = "";
- var url = "";
- var isAudioPlaying = 0;
- var saved_lastType = "";
- var saved_lastItem = "";
- WhenNewQuestion();
- setTimeout(WaitForCorrectAnswer, timer);
- $('<li id="option-show-previous"><i class="icon-question-sign"></i></li>').insertAfter('#option-end-session').addClass('inactive').attr('title','Previous item unavailable');
- $('#hotkeys').text('');
- $('<style type="text/css"> .qtip{ max-width: 380px !important; } #reviews nav li { width: 16% !important; }</style>').appendTo('head');
- function MoveToNextQuestion()
- {
- $('#option-submit').click();
- $('#hotkeys').html('<strong>Loading next item...</strong>');
- isAudioPlaying = 0;
- setTimeout(WaitForCorrectAnswer, timer);
- }
- function PlayAudioClipThenMove()
- {
- if ($(".play")[0] != undefined)
- {
- $(".play")[0].click();
- setTimeout(MoveToNextQuestion, 2000);
- }
- else
- {
- MoveToNextQuestion();
- }
- }
- function WaitForCorrectAnswer()
- {
- if (($('fieldset').attr("class") == "correct") && (isAudioPlaying == 0))
- {
- if ((playAudio == 1) && ($("#option-audio").attr("class") != "inactive"))
- {
- isAudioPlaying = 1;
- setTimeout(PlayAudioClipThenMove, timer);
- }
- else {
- MoveToNextQuestion();
- }
- }
- else
- {
- setTimeout(WaitForCorrectAnswer, timer);
- }
- }
- function WhenNewQuestion()
- {
- currentType = $("#item-box").find("h1").attr("class");
- if (currentType == "vocabulary")
- {
- currentItem = $("#item-box").find("h1 small").text();
- }
- else if (currentType == "kanji")
- {
- currentItem = $("#item-box").find("h1").text();
- }
- else
- {
- currentItem = $("#meanings p").text().toLowerCase();
- currentItem = currentItem.replace(" ","-");
- }
- if (currentItem != lastItem)
- {
- saved_currentItem = $('#character').text();
- if(lastItem == '')
- {
- $('#option-show-previous').addClass('inactive').attr('title', 'Previous item unavailable');
- }
- else
- {
- saved_lastType = lastType;
- $('#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);
- url = "http://www.wanikani.com/quickview/";
- if (lastType == "kanji")
- {
- url += "kanji\/"+lastItem;
- }
- else if (lastType=="vocabulary")
- {
- url += "vocabulary\/" + lastItem;
- }
- else
- {
- url += "radicals\/" + lastItem;
- }
- }
- }
- $('#hotkeys').text('');
- saved_lastItem = saved_currentItem;
- lastType = currentType;
- lastItem = currentItem;
- $('#option-show-previous').not('.inactive').on('click', function(event) {
- $(this).qtip({
- show: 'click',
- hide: 'unfocus',
- overwrite: true, // Don't overwrite tooltips already bound
- content: {
- title: 'Previous ' + saved_lastType,
- text: '<iframe src="' + url + '" 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'
- });
- });
- }
- $("#item-info-sub").on("DOMNodeInserted", WhenNewQuestion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement