WaniKani Mini Item Marker

Another Item Marker for WaniKani

目前为 2017-12-19 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name WaniKani Mini Item Marker
  3. // @namespace wk_mtm
  4. // @version 0.1.2
  5. // @description Another Item Marker for WaniKani
  6. // @author polv
  7. // @match https://www.wanikani.com/review/session
  8. // @match https://www.wanikani.com/dashboard
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var word = {id: ''};
  13. var marker_array = $.jStorage.get('wk_marker_array', []);
  14. var marked_text = ['Usage', 'Reading'];
  15. var marked_color = ['#CCCCCC', 'green'];
  16. var num_click = 0;
  17. var url = document.URL;
  18.  
  19. (function() {
  20. 'use strict';
  21. $('head').append(`<style>
  22. .marked {
  23. border: solid 5px;
  24. padding: 4px;
  25. margin: 4px 4px 0px 4px;
  26. }
  27. .marked-text {
  28. position : absolute;
  29. top : -1em;
  30. right : 0em;
  31. font-size : 0.2em;
  32. }
  33. .marked-parent {
  34. position: relative;
  35. width: 0;
  36. height: 0;
  37. }
  38. pre{
  39. -moz-tab-size: 15;
  40. -o-tab-size: 15;
  41. tab-size: 15;
  42. }
  43. </style>`);
  44.  
  45. if(url.indexOf('review') != -1){
  46. $('#character span').click(function(){
  47. word = $.jStorage.get("currentItem");
  48.  
  49. if(num_click >= marked_text.length){
  50. num_click = -1;
  51. $(this).removeClass('marked');
  52. $('.marked-parent').remove();
  53. for(var i=0; i<marked_text.length; i++) {
  54. var index_splice = getMarkerIndex(marked_text[i], word);
  55. if(index_splice !== -1)
  56. marker_array.splice(index_splice,1);
  57. }
  58. $.jStorage.set('wk_marker_array', marker_array);
  59. } else {
  60. $(this).addClass('marked');
  61. $(this).css('border-color', marked_color[num_click]);
  62. }
  63.  
  64. if($(this).hasClass('marked')) {
  65. $('.marked-parent').remove();
  66. $('.marked').after('<span class="marked-parent"><span class="marked-text">' + marked_text[num_click] + '</span></span>');
  67. for(var i=0; i<marked_text.length; i++) {
  68. var index_splice = getMarkerIndex(marked_text[i], word);
  69. if(index_splice !== -1)
  70. marker_array.splice(index_splice,1);
  71. }
  72. marker_array.push([marked_text[num_click], word]);
  73. $.jStorage.set('wk_marker_array', marker_array);
  74. }
  75. num_click++;
  76. });
  77.  
  78. $.jStorage.listenKeyChange('currentItem', function(key) {
  79. if(markedWord($('#character span:first').text())){
  80. $('.marked-parent').remove();
  81. num_click = marked_text.indexOf(markedWord($('#character span:first').text()));
  82. $('#character span').css('border-color', marked_color[num_click]);
  83. $('#character span').addClass('marked');
  84. $('.marked').after('<span class="marked-parent"><span class="marked-text">' + marked_text[num_click] + '</span></span>');
  85. }
  86. else {
  87. num_click = 0;
  88. $('.marked-parent').remove();
  89. $('#character span').removeClass('marked');
  90. }
  91. });
  92. } else {
  93. $('.progression').after('<section class="item-marker"/>');
  94. for(var i=0; i<marked_text.length; i++){
  95. $('.item-marker').append('<h2 class="' + marked_text[i] + '"></h2><pre class="' + marked_text[i] + '"></pre>');
  96. $('.item-marker h2.' + marked_text[i]).append(marked_text[i]);
  97. }
  98. for(i=0; i<marker_array.length; i++){
  99. $('.item-marker pre.' + marker_array[i][0]).append(formatCurrentItem(marker_array[i][1]));
  100. }
  101.  
  102. $('.item-marker-remove').click(function(){
  103. word.id = $(this).parent('div').attr('class');
  104. for(var i=0; i<marked_text.length; i++) {
  105. var index_splice = getMarkerIndex(marked_text[i], word);
  106. if(index_splice !== -1)
  107. marker_array.splice(index_splice,1);
  108. }
  109. $.jStorage.set('wk_marker_array', marker_array);
  110. $(this).parent('div').remove();
  111. debugger;
  112. });
  113. }
  114. })();
  115.  
  116. function markedWord(word){
  117. for(var i=0; i<marker_array.length; i++){
  118. var check;
  119. if(marker_array[i][1].voc)
  120. check = marker_array[i][1].voc;
  121. else if(marker_array[i][1].kan)
  122. check = marker_array[i][1].kan;
  123. else
  124. check = marker_array[i][1].rad;
  125.  
  126. if(check === word)
  127. return marker_array[i][0];
  128. }
  129. return false;
  130. }
  131.  
  132. function getMarkerIndex(text, word){
  133. for(var i=0; i<marker_array.length; i++){
  134. if(marker_array[i][0]===text && marker_array[i][1].id==word.id)
  135. return i;
  136. }
  137. return -1;
  138. }
  139.  
  140. function formatCurrentItem(currentItem){
  141. var output = '<div class="'+currentItem.id+'">';
  142.  
  143. if(currentItem.voc)
  144. output += 'Vocabulary\t' + currentItem.voc;
  145. else if(currentItem.kan)
  146. output += 'Kanji\t' + currentItem.kan;
  147. else if(currentItem.rad)
  148. output += 'Radical\t' + currentItem.rad;
  149.  
  150. if(currentItem.voc)
  151. output += '\t' + currentItem.kana.join(',');
  152. else if(currentItem.kan)
  153. output += '\t[On]' + currentItem.on.join(',') + '[Kun]' + currentItem.kun.join(',');
  154. else if(currentItem.rad)
  155. output += '\t';
  156.  
  157. output += '\t' + currentItem.en.join(',');
  158.  
  159. output += '\t<a class="item-marker-remove">Remove</a>';
  160.  
  161. output += '\n</div>';
  162.  
  163. return output;
  164. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址