Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name WaniKani Flash Forward
- // @namespace thenn42.eu/userscripts
- // @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.
- // @include http://www.wanikani.com/review/*
- // @version 0.3
- // @run-at document-end
- // @require http://code.jquery.com/jquery-1.9.1.min.js
- // @grant GM_log
- // ==/UserScript==
- var playAudio = 0;
- var timer = 500;
- var lastItem = "";
- var currentItem = "";
- var lastType = "";
- var currentType = "";
- var url = "";
- var isAudioPlaying = 0;
- WhenNewQuestion();
- setTimeout(WaitForCorrectAnswer, timer);
- function MoveToNextQuestion() {
- $('#option-submit').click();
- 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) {
- url = "http://www.wanikani.com/quickview/";
- if (lastType == "kanji") {
- url += "kanji\/"+lastItem;
- } else if (lastType=="vocabulary") {
- url += "vocabulary\/" + lastItem;
- } else {
- url += "radicals\/" + lastItem;
- }
- $("#option-kana-chart").replaceWith("<li id=\"option-kana-chart\"><a target=\"_blank\" href=\""+url+"\"><i class=\"icon-question-sign\"></i></a></li>");
- }
- lastType = currentType;
- lastItem = currentItem;
- }
- $('#item-info-sub').bind('DOMNodeInserted', WhenNewQuestion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement