Wanikani Review Count Analysis

Reports review counts.

当前为 2015-08-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Wanikani Review Count Analysis
// @namespace   HoovardWKRCA
// @description Reports review counts.
// @include     https://www.wanikani.com/dashboard
// @include     https://www.wanikani.com/
// @version     0.0.2
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

$(document).ready(initReviewCount);

var strAPIKey = "";

var strUserLevelURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/level-progression";

var strRadURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/radicals";
var strKanURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/kanji/";
var strVocURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/vocabulary/";

const TYPE_RAD = 0;
const TYPE_KAN = 1;
const TYPE_VOC = 2;

// Display helper list
var a_strDataTypeNames = ["Rad", "Kan", "Voc"];


var a_iLevelTotals = []; // Array to hold level subtotals

var iUserLevel = 0;

var iCorrectTotal = 0;
var iIncorrectTotal = 0;

function initReviewCount()
{
	// Insert the div and table elements
	var ReviewAnalysisStyles = "";
	var strInitialDiv = "";
	
	

	
	
	if (strAPIKey != "") {
        	strInitialDiv += "<div style='padding-top: 10px; padding-bottom:10px; margin-bottom: 10px;'>"
    +"<div id='buttonRegion' style='width: 100%; text-align: center;'>"
        +"<button id='startAnalysis'>Review Count Analysis</button>"
        +"<button id='clearResults'>Clear Results</button>"
       
    +"</div>"
    +"<div id='ReviewAnalysisSection' style='width: 100%; text-align: center;'></div></div>";
		$("#APIkey").val(strAPIKey)
    }else{
        	strInitialDiv += "<div style='padding-top: 10px; padding-bottom:10px; margin-bottom: 10px;'>"
    +"<div id='buttonRegion' style='width: 100%; text-align: center;'>"
        +"<button id='startAnalysis'>Review Count Analysis</button>"
        +"<button id='clearResults'>Clear Results</button>"
        +"<br>API Key: <input id='APIkey' style='font-size: 10pt; width: 400px; border: 1px solid #999999; background-color: #ffffff;' type='text' name='APIkey' size='20' maxlength='256' value='' />"
    +"</div>"
    +"<div id='ReviewAnalysisSection' style='width: 100%; text-align: center;'></div></div>";
        GM_setValue("holdKey",strAPIKey);
    }
		$( "head" ).append( ReviewAnalysisStyles );
	$('section.progression').after(strInitialDiv);
	$( "button#startAnalysis" ).click(function() {
	  startReviewAnalysis();
	});
	
	$( "button#clearResults" ).click(function() {
	  clearTable();});
	
}



function getLevelInformation(iLev)
{
	iUserLevel = iLev;
	console.log("Level: " + iUserLevel);
	
	// get r/k/v info
	
	for (i = 1; i <= iUserLevel; ++i) {
		var iLevelRadSubTotal = 0;
		var iLevelKanSubTotal = 0;
		var iLevelVocSubTotal = 0;		
		
		// Radicals
		$.get( strRadURL + "/" + i, function( data ) {
			var iDataLevel = data['requested_information'][0]['level'];
			var iRadCount = Object.keys(data['requested_information']).length
			
			var iRadCorrectAnswers = 0;
			var iRadIncorrectAnswers = 0;
			
			for (n = 0; n < iRadCount; ++n) {
				
				if (data['requested_information'][n]['user_specific'] != null) {
					var irCorrect = parseInt(data['requested_information'][n]['user_specific']['meaning_correct']);
					var irIncorrect = parseInt(data['requested_information'][n]['user_specific']['meaning_incorrect']);
					
					iRadCorrectAnswers += irCorrect;
					iRadIncorrectAnswers += irIncorrect;
					
					iCorrectTotal += irCorrect;
					iIncorrectTotal += irIncorrect;
				}
			}
			a_iLevelTotals[iDataLevel-1] += (iRadCorrectAnswers + iRadIncorrectAnswers);
			$( "td#Levtot" + iDataLevel ).html(a_iLevelTotals[iDataLevel-1]);
			$( "td#Rad" + iDataLevel ).html( (iRadCorrectAnswers + iRadIncorrectAnswers) + " [+"+iRadCorrectAnswers+" -"+iRadIncorrectAnswers+"]");
$( "td#mainTotal" ).html( "TOTAL REVIEWS: "+ (iCorrectTotal+iIncorrectTotal) +", TOTAL PERCENTAGE: "+Math.round(iCorrectTotal/(iCorrectTotal+iIncorrectTotal)*10000)/100 + "%");		});
		
		// Kanji
		$.get( strKanURL + "/" + i, function( data ) {
			var iDataLevel = data['requested_information'][0]['level'];
			var iKanCount = Object.keys(data['requested_information']).length;			
			var iKanCorrectAnswers = 0;
			var iKanIncorrectAnswers = 0;
			for (n = 0; n < iKanCount; ++n) {
				if (data['requested_information'][n]['user_specific'] != null) {
					var ikCorrectM = parseInt(data['requested_information'][n]['user_specific']['meaning_correct']);
					var ikIncorrectM = parseInt(data['requested_information'][n]['user_specific']['meaning_incorrect']);
					var ikCorrectR = parseInt(data['requested_information'][n]['user_specific']['reading_correct']);
					var ikIncorrectR = parseInt(data['requested_information'][n]['user_specific']['reading_incorrect']);
					
					iKanCorrectAnswers += ikCorrectM + ikCorrectR;
					iKanIncorrectAnswers += ikIncorrectM + ikIncorrectR;
					
					iCorrectTotal += ikCorrectM + ikCorrectR;
					iIncorrectTotal += ikIncorrectM + ikIncorrectR;
				}
			}					
			a_iLevelTotals[iDataLevel-1] += (iKanCorrectAnswers + iKanIncorrectAnswers);
			$( "td#Levtot" + iDataLevel ).html( a_iLevelTotals[iDataLevel-1] );
			$( "td#Kan" + iDataLevel ).html( (iKanCorrectAnswers + iKanIncorrectAnswers) + " [+"+iKanCorrectAnswers+" -"+iKanIncorrectAnswers+"]");
$( "td#mainTotal" ).html( "TOTAL REVIEWS: "+ (iCorrectTotal+iIncorrectTotal) +", TOTAL PERCENTAGE: "+Math.round(iCorrectTotal/(iCorrectTotal+iIncorrectTotal)*10000)/100 + "%");		});
		
		// Vocab
		$.get( strVocURL + "/" + i, function( data ) {
			var iDataLevel = data['requested_information'][0]['level'];
			var iVocCount = Object.keys(data['requested_information']).length;
			var iVocCorrectAnswers = 0;
			var iVocIncorrectAnswers = 0;
			
			for (n = 0; n < iVocCount; ++n) {
				if (data['requested_information'][n]['user_specific'] != null) {
					var ivCorrectM = parseInt(data['requested_information'][n]['user_specific']['meaning_correct']);
					var ivIncorrectM = parseInt(data['requested_information'][n]['user_specific']['meaning_incorrect']);
					var ivCorrectR = parseInt(data['requested_information'][n]['user_specific']['reading_correct']);
					var ivIncorrectR = parseInt(data['requested_information'][n]['user_specific']['reading_incorrect']);
					
					iVocCorrectAnswers += ivCorrectM + ivCorrectR;
					iVocIncorrectAnswers += ivIncorrectM + ivIncorrectR;
					
					iCorrectTotal += ivCorrectM + ivCorrectR;
					iIncorrectTotal += ivIncorrectM + ivIncorrectR;
				}
			}
			a_iLevelTotals[iDataLevel-1] += (iVocCorrectAnswers + iVocIncorrectAnswers);
			$( "td#Levtot" + iDataLevel ).html( a_iLevelTotals[iDataLevel-1] );	
			$( "td#Voc" + iDataLevel ).html( (iVocCorrectAnswers + iVocIncorrectAnswers) + " [+"+iVocCorrectAnswers+" -"+iVocIncorrectAnswers+"]");
$( "td#mainTotal" ).html( "TOTAL REVIEWS: "+ (iCorrectTotal+iIncorrectTotal) +", TOTAL PERCENTAGE: "+Math.round(iCorrectTotal/(iCorrectTotal+iIncorrectTotal)*10000)/100 + "%");	});
	}
}

function clearTable()
{
	$( "div#ReviewAnalysisSection" ).html( "" );
}

function startReviewAnalysis()
{ 
    if (!document.getElementById('MyElementId')){
        strAPIKey = "";
    }else {
        strAPIKey = $("#APIkey").val();
    }
    if (strAPIKey != "") {
        GM_setValue("holdKey",strAPIKey);
    }else{
        strAPIKey = GM_getValue("holdKey")
        if (!strAPIKey) {
           $("#APIkey").val(strAPIKey);
        }
    }
		strUserLevelURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/level-progression";
		strRadURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/radicals";
		strKanURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/kanji/";
		strVocURL = "https://www.wanikani.com/api/user/"+ strAPIKey +"/vocabulary/";
	//}
	
	clearTable();
	
	var strBaseTable = "";
	
	strBaseTable = "<table border='1' style='margin-left: auto; margin-right: auto; width: 80%; border 1px solid #000000;' id='ReviewAnalysisTable'><tr><td>Level</td><td>Rad</td><td>Kan</td><td>Voc</td><td>Level Tot.</td></tr></table>";
	
	$( "div#ReviewAnalysisSection" ).append( strBaseTable );	
	
	$.get( strUserLevelURL, function( data ) {
		if (data['user_information'] == null) {
			clearTable();
			alert("No data returned. Something wrong with API key or network.");
			return 0;
		}
		var iCurrentUserLevel = parseInt(data['user_information']['level']);
		a_iLevelTotals = initialiseLevelTotalsArray(iCurrentUserLevel);
		for (n = 0; n < iCurrentUserLevel; ++n) {
			$( "table#ReviewAnalysisTable" ).append( "<tr><td>"+ (n+1) +"</td><td id='Rad"+ (n+1) +"'>0</td><td id='Kan"+ (n+1) +"'>0</td><td id='Voc"+ (n+1) +"'>0</td><td id='Levtot"+ (n+1) +"'>0</td></tr>" );
		}
		$( "table#ReviewAnalysisTable" ).append( "<tr><td style='background-color: #660000; color: #ffffff; font-weight: bold;' id='mainTotal' colspan='5'>0</td></tr>" );
		getLevelInformation(iCurrentUserLevel);
	});	
}

function initialiseLevelTotalsArray(iCt)
{
	var a_iReturn = new Array(iCt);
	for (x = 0; x < iCt; ++x) {
		a_iReturn[x] = 0;
	}
	return a_iReturn;
}