WK Smaller Lessons And Reviews Buttons

try to take over the world!

当前为 2023-02-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WK Smaller Lessons And Reviews Buttons
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.12
  5. // @description try to take over the world!
  6. // @author You
  7. // @icon https://i.pinimg.com/236x/5f/68/68/5f6868d18acbc1221de49387a3c07833--batman-poster-batman-batman.jpg
  8. // @match https://www.wanikani.com/
  9. // @match https://www.wanikani.com/dashboard
  10. // @require https://greasyfork.org/scripts/369353-jigen-s-other-stuff/code/Jigen's%20other%20stuff.js?version=604095
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. window.wk_smaller_lessons_and_reviews_buttons = {};
  16. (function() {
  17. 'use strict';
  18.  
  19. if (!window.wkof) {
  20. if (confirm('WaniKani Smaller Lessons And Reviews Buttons requires Wanikani Open Framework.\nDo you want to be forwarded to the installation instructions?'))
  21. window.location.href = 'https://community.wanikani.com/t/instructions-installing-wanikani-open-framework/28549';
  22. return;
  23. }
  24.  
  25. var settings_dialog;
  26. var defaults = {
  27. showRecentLessons: true,
  28. showRecentMistakes: true,
  29. showLevel: true
  30. };
  31.  
  32. wkof.include('Apiv2, Menu, Settings');
  33. wkof.ready('Menu').then(install_menu);
  34. wkof.ready('Settings').then(install_settings);
  35.  
  36.  
  37. function install_menu() {
  38. wkof.Menu.insert_script_link({
  39. script_id: 'smaller_lessons_and_reviews_buttons',
  40. name: 'smaller_lessons_and_reviews_buttons',
  41. submenu: 'Settings',
  42. title: 'Smaller Lessons And Reviews Buttons',
  43. on_click: open_settings
  44. });
  45. }
  46.  
  47. function open_settings() {
  48. settings_dialog.open();
  49. }
  50. function process_settings(){
  51. settings_dialog.save();
  52. console.log('Settings saved!');
  53. }
  54.  
  55. function install_settings() {
  56. console.log("dfsafasfas");
  57. settings_dialog = new wkof.Settings({
  58. script_id: 'smaller_lessons_and_reviews_buttons',
  59. name: 'smaller_lessons_and_reviews_buttons',
  60. title: 'Smaller Lessons And Reviews Buttons',
  61. on_save: process_settings,
  62. settings: {
  63. 'grp_main': {
  64. type:'group',
  65. label:'Main',
  66. content:{
  67. 'showRecentLessons': {type:'checkbox',label:'Show Recent Lessons',default:defaults.alwaysShow,on_change:defaults.showRecentLessons},
  68. 'showRecentMistakes': {type:'checkbox',label:'Show Recent Mistakes',default:defaults.showRecentMistakes},
  69. 'showLevel': {type:'checkbox',label:'Show Level',default:defaults.showLevel},
  70. }
  71. },
  72. }
  73. });
  74. settings_dialog.load().then(function(){
  75. wkof.settings.smaller_lessons_and_reviews_buttons = $.extend(true, {}, defaults, wkof.settings.smaller_lessons_and_reviews_buttons);
  76. //console.log(wkof.settings.smaller_lessons_and_reviews_buttons);
  77. adjust_buttons();
  78. });
  79. }
  80.  
  81. function adjust_buttons() {
  82.  
  83. if($('.lessonAndReviewButtons').length == 0){
  84. $('.lessons-and-reviews').remove();
  85. $('.dashboard-progress').css('grid-row','1 / 3');
  86. //make lesson hover work with it
  87. $('.lessonAndReviewButtons .lessons').mouseover(function(){
  88. $('.lessonAndReviewButtons .lessons').attr('data-content',$('.navigation .navigation-shortcut--lessons a').attr('data-content')).popover({
  89. html: true,
  90. animation: false,
  91. placement: 'bottom',
  92. trigger: 'hover',
  93. template: '<div class="popover review-time"><div class="arrow"></div><div class="popover-inner"><div class="popover-content"><p></p></div></div></div>'
  94. });
  95. });
  96. if(wkof.settings.smaller_lessons_and_reviews_buttons.showLevel == true){
  97. $($('.sitemap__section-header')[0]).before('<button class="dashboard-level">'+$('li.user-summary__attribute a')[0].href.split('/level/')[1]+'</button>');
  98. }
  99. //var extraStudy = $('[data-test="extra-study-button"]');
  100. //if(wkof.settings.smaller_lessons_and_reviews_buttons.showRecentLessons == true){
  101. // var newRecentLessons = `<li class="navigation-shortcut navigation-shortcut--recentLessons" data-count="${extraStudy[0].text.replace(' Recent Lessons','')}">\n <a href="https://www.wanikani.com/extra_study/session?title=Recent+Lessons">\n <span>${extraStudy[0].text.replace(' Recent Lessons','')}</span> Recent Lessons\n</a> </li>`;
  102. // $('.navigation-shortcut--reviews').after(newRecentLessons);
  103. //}
  104. //if(wkof.settings.smaller_lessons_and_reviews_buttons.showRecentMistakes == true){
  105. // var newRecentMistakes = `<li class="navigation-shortcut navigation-shortcut--recentMistakes" data-count="${extraStudy[1].text.replace(' Recent Mistakes','')}">\n <a href="https://www.wanikani.com/extra_study/session?title=Recent+Mistakes">\n <span>${extraStudy[1].text.replace(' Recent Mistakes','')}</span> Recent Mistakes\n</a> </li>`;
  106. // $('.navigation-shortcut--reviews').after(newRecentMistakes);
  107. //}
  108.  
  109. $('[data-react-class="ExtraStudyDashboard/ExtraStudyDashboard"]').remove();
  110. $('.sitemap__section-header--help').parent().remove();
  111.  
  112. jigen.addStyle(`
  113. .navigation-shortcuts, .navigation-shortcuts.hidden{
  114. display: flex !important;
  115. visibility: visible;
  116. }
  117. @media (min-width: 768px){
  118. .dashboard .progress-and-forecast .forecast {
  119. grid-row: 1 / 3;
  120. }
  121. }
  122. .dashboard-level {
  123. min-width: 16px;
  124. padding: 0 8px;
  125. font-size: 0.75rem;
  126. display: inline-block;
  127. border-radius: 4px 0 0 4px;
  128. vertical-align: top;
  129. line-height: 32px;
  130. color: #fff;
  131. text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
  132. font-weight: bold !important;
  133. text-align: center;
  134. background: transparent;
  135. color: black;
  136. line-height: 28px;
  137. color: rgb(51, 51, 51);
  138. border: 2px solid rgba(0, 0, 0, 0.1);
  139. }
  140. [aria-controls=sitemap__levels],[aria-controls=sitemap__vocabulary],[aria-controls=sitemap__kanji],[aria-controls=sitemap__radicals]{
  141. border-radius: 0 4px 4px 0;
  142. border: 2px solid rgba(0, 0, 0, 0.1);
  143. border-left: 0
  144. width:auto;
  145. display: inline;
  146. border-radius: 4px;
  147. }
  148. [aria-controls=sitemap__vocabulary],[aria-controls=sitemap__kanji],[aria-controls=sitemap__radicals]{
  149. margin-right: 0;
  150. margin-left: 0;
  151. }
  152. .navigation-shortcut--recentMistakes, .navigation-shortcut--recentLessons, .sitemap {
  153. white-space: nowrap;
  154. }
  155. [aria-controls=sitemap__levels] {
  156. padding: 0;
  157. border-radius: 0 4px 4px 0;
  158. width: 80px;
  159. }
  160. .dashboard-level {
  161. border-right: none;
  162. }
  163. [data-react-class="ExtraStudyDashboardLegacy/ExtraStudyDashboard"] {
  164. display: none;
  165. }
  166. `);
  167. }
  168. }
  169. })(wk_smaller_lessons_and_reviews_buttons);