Greasy Fork

WaniKani Settings

try to take over the world!

目前为 2016-08-30 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/22751/144753/WaniKani%20Settings.js

// ==UserScript==
// @name         WaniKani Settings
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @grant        none
// ==/UserScript==

function test(){
    alert('test');
}

function openSettingsDialog(data){
	if (typeof jQuery.ui == 'undefined') {
		jQuery.getScript("https://code.jquery.com/ui/1.12.0/jquery-ui.js", function(data, status, jqxhr) {
		openSettingsDialog2(data);
	});
	} else {
		openSettingsDialog2(data);
	}	
}

function openSettingsDialog2(data){
	var divSettings = "<div id='divSettings'><table>";
    $('#txtApiKey').val(apiKey);
    $('#ddlDisplayMode').val(srsGridDisplay);
	
	
	$.each(data,function(item,value){
		divSettings = divSettings + '<tr><td><span>value.Name:</span></td>';
		switch(value.Type) {
			case "textbox":
				divSettings = divSettings + '<td><input type="textbox" id="txt' + value.Name + '"></input></td></tr>';
				break;
			case "checkbox":
				divSettings = divSettings + '<td>coming soon</td>';
				break;
			case "select":
				divSettings = divSettings + '<td><select id="ddl' + value.Name + '">';
				$.each(value.Options,function(item2,value2){
					divSettings = divSettings + '<option value="' + value2.Value + '">' + value2.Text + '</option>';
				});
				divSettings = divSettings + '</td></tr>';
				break;
			default:
				default code block
		}
	}
    divSettings = divSettings + '</table>';
    $('section.progression').after(divSettings);
	$.each(data,function(item,value){
			switch(value.Type) {
			case "textbox":
				$('#txt' + value.Name).val(getSetting(value.Name));
				break;
			case "checkbox":
				break;
			case "select":
				$('#ddl' + value.Name).val(getSetting(value.Name));
				break;
			default:
				default code block
		}
	}
    $('#divSettings').dialog({
				autoOpen: false,
				height: 300,
				width: 400,
				modal: true,
				buttons: {
					"Save": function () {
                        //localStorage.setItem('apiKeyForSRS', $('#txtApiKey').val());
                        //localStorage.setItem('srsGridDisplay', $('#ddlDisplayMode option:selected').val());
						$(this).dialog("close");
					},
					Cancel: function () {
						$(this).dialog("close");
					}
				}
			}).dialog('open');
}

function getSetting(setting){
	return localStorage.getItem(setting);
}