WaniKani Settings

try to take over the world!

当前为 2016-08-30 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/22751/144752/WaniKani%20Settings.js

  1. // ==UserScript==
  2. // @name WaniKani Settings
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. function test(){
  11. alert('test');
  12. }
  13.  
  14. function openSettingsDialog(data){
  15. if (typeof jQuery.ui == 'undefined') {
  16. jQuery.getScript("https://code.jquery.com/ui/1.12.0/jquery-ui.js", function(data, status, jqxhr) {
  17. openSettingsDialog2(data);
  18. });
  19. } else {
  20. openSettingsDialog2(data);
  21. }
  22. }
  23.  
  24. function openSettingsDialog2(data){
  25. var divSettings = "<div id='divSettings'><table>";
  26. $('#txtApiKey').val(apiKey);
  27. $('#ddlDisplayMode').val(srsGridDisplay);
  28. $.each(data,function(item,value){
  29. divSettings = divSettings + '<tr><td><span>value.Name:</span></td>';
  30. switch(value.Type) {
  31. case "textbox":
  32. divSettings = divSettings + '<td><input type="textbox" id="txt' + value.Name + '"></input></td></tr>';
  33. break;
  34. case "checkbox":
  35. divSettings = divSettings + '<td>coming soon</td>';
  36. break;
  37. case "select":
  38. divSettings = divSettings + '<td><select id="ddl' + value.Name + '">';
  39. $.each(value.Options,function(item2,value2){
  40. divSettings = divSettings + '<option value="' + value2.Value + '">' + value2.Text + '</option>';
  41. }
  42. divSettings = divSettings + '</td></tr>';
  43. break;
  44. default:
  45. default code block
  46. }
  47. }
  48. divSettings = divSettings + '</table>';
  49. $('section.progression').after(divSettings);
  50. $.each(data,function(item,value){
  51. switch(value.Type) {
  52. case "textbox":
  53. $('#txt' + value.Name).val(getSetting(value.Name));
  54. break;
  55. case "checkbox":
  56. break;
  57. case "select":
  58. $('#ddl' + value.Name).val(getSetting(value.Name));
  59. break;
  60. default:
  61. default code block
  62. }
  63. }
  64. $('#divSettings').dialog({
  65. autoOpen: false,
  66. height: 300,
  67. width: 400,
  68. modal: true,
  69. buttons: {
  70. "Save": function () {
  71. //localStorage.setItem('apiKeyForSRS', $('#txtApiKey').val());
  72. //localStorage.setItem('srsGridDisplay', $('#ddlDisplayMode option:selected').val());
  73. $(this).dialog("close");
  74. },
  75. Cancel: function () {
  76. $(this).dialog("close");
  77. }
  78. }
  79. }).dialog('open');
  80. }
  81.  
  82. function getSetting(setting){
  83. return localStorage.getItem(setting);
  84. }