Greasy Fork is available in English.

WaniKani Settings

try to take over the world!

Dette script bør ikke installeres direkte. Det er et bibliotek, som andre scripts kan inkludere med metadirektivet // @require https://update.greatest.deepsurf.us/scripts/22751/230720/WaniKani%20Settings.js

  1. function noSpaces(value){
  2. return value.replace(/ /g,'');
  3. }
  4.  
  5. function makeSettings(Name, data){
  6. if($('.dropdown.account .dropdown-menu li.nav-header:contains("Scripts")').length === 0){
  7. $('.dropdown.account .dropdown-menu').append('<li id="scriptsMenu" class="nav-header">Scripts</li>');
  8. }
  9. $('#scriptsMenu').after("<li><a id='div" + noSpaces(Name) + "Link' href='#' onclick='$(\"#div" + noSpaces(Name) + "Settings\").dialog(\"open\");return false;'>" + Name + "</a></li>");
  10. $('head').append('<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css" type="text/css" />');
  11. if (typeof jQuery.ui == 'undefined') {
  12. jQuery.getScript("https://code.jquery.com/ui/1.12.0/jquery-ui.js", function(data2, status, jqxhr) {
  13. makeSettings2(Name, data);
  14. });
  15. } else {
  16. makeSettings2(Name, data);
  17. }
  18. }
  19.  
  20. function makeSettings2(Name, data){
  21. var divSettings = "<div id='div" + noSpaces(Name) + "Settings'><table>";
  22. $.each(data,function(item,value){
  23. divSettings = divSettings + '<tr><td><span>' + value.Display + '</span></td>';
  24. switch(value.Type) {
  25. case "textbox":
  26. divSettings = divSettings + '<td><input type="textbox" id="txt' + value.Name + '"></input></td></tr>';
  27. break;
  28. case "checkbox":
  29. divSettings = divSettings + '<td><input type="checkbox" id="chk' + value.Name + '"></input></td></tr>';
  30. break;
  31. case "select":
  32. divSettings = divSettings + '<td><select id="ddl' + value.Name + '">';
  33. $.each(value.Options,function(item2,value2){
  34. divSettings = divSettings + '<option value="' + value2.Value + '">' + value2.Text + '</option>';
  35. });
  36. divSettings = divSettings + '</td></tr>';
  37. break;
  38. default:
  39. break;
  40. }
  41. });
  42. divSettings = divSettings + '</table>';
  43. $('section.progression').after(divSettings);
  44. $.each(data,function(item,value){
  45. switch(value.Type) {
  46. case "textbox":
  47. $('#txt' + value.Name).val(getSetting(value.Name) === null ? value.Default === null ? "" : value.Default : getSetting(value.Name));
  48. break;
  49. case "checkbox":
  50. $('#chk' + value.Name).val();
  51. if((getSetting(value.Name) === null ? value.Default === null ? "" : value.Default : getSetting(value.Name)) === "1"){
  52. $('#chk' + value.Name).prop('checked','checked');
  53. }
  54. break;
  55. case "select":
  56. $('#ddl' + value.Name).val(getSetting(value.Name) === null ? value.Default === null ? "" : value.Default : getSetting(value.Name));
  57. break;
  58. default:
  59. return;
  60. }
  61. });
  62. $('#div' + noSpaces(Name) + "Settings").dialog({
  63. autoOpen: false,
  64. height: 350,
  65. width: 'auto',
  66. modal: true,
  67. buttons: {
  68. "Save": function () {
  69. $.each(data,function(item,value){
  70. switch(value.Type) {
  71. case "textbox":
  72. localStorage.setItem(value.Name,$('#txt' + value.Name).val());
  73. break;
  74. case "checkbox":
  75. if($('#chk' + value.Name).prop('checked') == true){
  76. localStorage.setItem(value.Name,"1");
  77. } else {
  78. localStorage.setItem(value.Name,"0");
  79. }
  80. break;
  81. case "select":
  82. localStorage.setItem(value.Name,$('#ddl' + value.Name).val());
  83. break;
  84. default:
  85. return;
  86. }
  87. });
  88. $(this).dialog("close");
  89. doReload();
  90. },
  91. Cancel: function () {
  92. $(this).dialog("close");
  93. }
  94. }
  95. });
  96. }
  97.  
  98. function getSetting(setting){
  99. return localStorage.getItem(setting);
  100. }
  101.  
  102. function doReload(){
  103. $('<div class="yesNoDialog"></div>').appendTo('body')
  104. .html('<div><h6>WaniKani needs to reload for changes to take effect.\nReload now?</h6></div>')
  105. .dialog({
  106. modal: true,
  107. title: "Refresh?",
  108. zIndex: 10000,
  109. autoOpen: true,
  110. width: 'auto',
  111. resizable: false,
  112. buttons: {
  113. Yes: function () {
  114. location.reload();
  115. },
  116. No: function () {
  117. $(this).remove();
  118. }
  119. },
  120. close: function (event, ui) {
  121. $(this).remove();
  122. }
  123. });
  124. }
  125.  
  126. //-------------------------------------------------------------------
  127. // Add a <style> section to the document.
  128. //-------------------------------------------------------------------
  129. function addStyle(aCss) {
  130. var head, style;
  131. head = document.getElementsByTagName('head')[0];
  132. if (head) {
  133. style = document.createElement('style');
  134. style.setAttribute('type', 'text/css');
  135. style.textContent = aCss;
  136. head.appendChild(style);
  137. return style;
  138. }
  139. return null;
  140. }