// ==UserScript== // @name WaniKani Nippongrammar Extension // @namespace WK-nippongrammar // @version 0.2 // @website http://nippongrammar.appspot.com/ // @description Svg Canvas used to draw Kanji on reviews and lessons, using website code. // @author Code by Aaron Drew, Wanikani adaption by Ethan McCoy // @include *.wanikani.com/review/session* // @include *.wanikani.com/lesson/session* // @grant none // run-at document-end // @license MIT // @downloadURL none // ==/UserScript== $("head").prepend(''); $("head").prepend(''); function handleKeyChange(key, action){ console.group("animate strokes userscript"), console.log("key", key), cur = $.jStorage.get(key), text = cur.voc || cur.kan || cur.rad || "", console.log("text", text); strokeDiv = document.getElementById('strokeChar') || document.createElement('div'), strokeDiv.style.padding = "20px 20px 0", strokeDiv.id = "strokeChar"; if (key === "l/currentLesson" || key === "l/currentQuizItem"){ //console.log(charDiv.childNodes[0].nodeType === 3), charDiv = document.getElementById("character"); console.log("parent", charDiv.parentNode); }else{ //Reviews 'charDiv' is actually a span charDiv = document.getElementById("character").getElementsByTagName("span")[0]; } charDiv.parentNode.insertBefore(strokeDiv, charDiv); // console.log("text for "+key+"?",[charDiv.childNodes[0].nodeType]), // itemSpan = charDiv.getElementsByTagName("span")[0]; if(text.indexOf(".png") === -1){ //weed out picture radicals for now, extend svg library later strokeDiv && (strokeDiv.style.display = "block"); animateWriting(text,'strokeChar',30), charDiv && (charDiv.style.display = "none"); }else{ strokeDiv && (strokeDiv.style.display = "none"); charDiv && (charDiv.style.display = "block"); } console.groupEnd(); }; $.jStorage.listenKeyChange("currentItem", handleKeyChange); $.jStorage.listenKeyChange("l/currentQuizItem", handleKeyChange); $.jStorage.listenKeyChange("l/currentLesson", handleKeyChange);