Readouble Laravel Document Menu

ReadDoubleのLaravel日本語ドキュメントにサイドメニューを表示する

  1. // ==UserScript==
  2. // @name Readouble Laravel Document Menu
  3. // @namespace https://greatest.deepsurf.us/ja/scripts/374656-readouble-laravel-document-menu
  4. // @version 0.1
  5. // @description ReadDoubleのLaravel日本語ドキュメントにサイドメニューを表示する
  6. // @author tobigumo
  7. // @match https://readouble.com/laravel/*.*/*/*.html
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10.  
  11. GM_addStyle(`
  12. .menu-button{
  13. width: 30px;
  14. height: 30px;
  15. display: block;
  16. position: fixed;
  17. right: 10px;
  18. top: 30px;
  19. background-color:#ffffffcc;
  20. display:none;
  21. }
  22. .menu-button i{
  23. display: block;
  24. width: 20px;
  25. height: 2px;
  26. border-radius: 3px;
  27. background: #000;
  28. transition: background 0.5s;
  29. position: relative;
  30. left: 5px;
  31. top: 14px;
  32. }
  33. .menu-button i::before,
  34. .menu-button i::after{
  35. content: "";
  36. display: block;
  37. width: 20px;
  38. height: 2px;
  39. border-radius: 3px;
  40. background: #000;
  41. position: fixed;
  42. transform: rotate(0deg);
  43. transition: all 0.3s !important;
  44. }
  45. .menu-button i::before{
  46. transform:translateY(8px);
  47. }
  48. .menu-button i::after{
  49. transform:translateY(-8px);
  50. }
  51. .menu_container{
  52. float:right;
  53. }
  54. .menu_accordion_ul{
  55. height: 0;
  56. overflow: hidden;
  57. }
  58. .menu_accordion{
  59. display:none;
  60. }
  61. .current-page {
  62. font-weight:bold;
  63. }
  64. .menu_accordion:checked + .menu_accordion_ul{
  65. height: auto;
  66. }
  67. .full_screen_label{
  68. display:none !important;
  69. position:fixed;
  70. top:0;
  71. bottom:0;
  72. left:0;
  73. right:0;
  74. z-index:99;
  75. }
  76. @media screen and (max-width:1200px) {
  77. .menu_container {
  78. display: none;
  79. }
  80. .menu_switch:checked ~ .menu_container{
  81. display: block;
  82. }
  83. .menu_container{
  84. position:fixed;
  85. top: 0;
  86. right: 0;
  87. bottom: 0;
  88. overflow-y: auto;
  89.  
  90. z-index:100;
  91. background-color:#000000cc;
  92. }
  93. .menu_container::-webkit-scrollbar{
  94. display:none;
  95. }
  96. .menu_container label{
  97. color:#fff;
  98. }
  99. .menu_container a{
  100. color:#f6c2ac;
  101. }
  102. .menu-button {
  103. display:block;
  104. }
  105. .menu_switch:checked ~ .full_screen_label{
  106. display: block !important;
  107. }
  108.  
  109. }
  110. .menu_switch{
  111. display:none;
  112. }
  113. `);
  114.  
  115. (function() {
  116. 'use strict';
  117.  
  118. const menu_container = document.createElement('div');
  119. menu_container.className = 'menu_container';
  120. const content_container = document.getElementById('content');
  121. const category_blocks = document.getElementById('moveToPage').getElementsByClassName('categoryBlock');
  122. const ul = document.createElement('ul');
  123.  
  124. const menu_button = document.createElement('label');
  125. const full_screen_label = document.createElement('label');
  126. full_screen_label.className = 'full_screen_label';
  127. full_screen_label.setAttribute('for', 'menu_switch');
  128. menu_button.className = 'menu-button';
  129. menu_button.setAttribute('for', 'menu_switch');
  130. const menu_button_i = document.createElement('i');
  131. menu_button.appendChild(menu_button_i);
  132. const menu_switch = document.createElement('input');
  133. menu_switch.type = 'checkbox';
  134. menu_switch.id = 'menu_switch';
  135. menu_switch.className = 'menu_switch';
  136.  
  137. const url = location.origin + location.pathname;
  138.  
  139. for(let category_block of category_blocks) {
  140. const li = document.createElement('li');
  141. const input = document.createElement('input');
  142. const label = document.createElement('label');
  143. const category_name = category_block.getElementsByClassName('categoryName')[0].textContent;
  144. input.type = 'checkbox';
  145. input.id = category_name;
  146. input.name = 'menu_accordion';
  147. input.className = 'menu_accordion';
  148. label.textContent = category_name;
  149. label.setAttribute('for', category_name);
  150. li.appendChild(label);
  151. li.appendChild(input);
  152.  
  153. const sub_ul = document.createElement('ul');
  154. sub_ul.className = 'menu_accordion_ul';
  155. const document_pages = category_block.getElementsByClassName('chapters')[0].getElementsByTagName('a');
  156. for(let document_page of document_pages) {
  157. const sub_li = document.createElement('li');
  158. const a = document.createElement('a');
  159.  
  160. a.textContent = document_page.textContent;
  161. a.href = document_page.href;
  162.  
  163. if(url === a.href) {
  164. a.className = 'current-page';
  165. input.checked = true;
  166. }
  167.  
  168. sub_li.appendChild(a);
  169. sub_ul.appendChild(sub_li);
  170. }
  171. li.appendChild(sub_ul);
  172. ul.appendChild(li);
  173. }
  174.  
  175. menu_container.appendChild(ul);
  176.  
  177. content_container.insertBefore(menu_container, content_container.firstChild);
  178. content_container.insertBefore(full_screen_label, content_container.firstChild);
  179. content_container.insertBefore(menu_switch, content_container.firstChild);
  180. content_container.insertBefore(menu_button, content_container.firstChild);
  181. })();