Youtube Player Simplifier

Remove buttons

  1. // ==UserScript==
  2. // @name Youtube Player Simplifier
  3. // @namespace LeKAKiD
  4. // @match https://*.youtube.com/*
  5. // @exclude https://*.youtube.com/live_chat
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @grant GM_addValueChangeListener
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_unregisterMenuCommand
  11. // @version 1.7
  12. // @author LeKAKiD
  13. // @description Remove buttons
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. const ytButtons = {
  18. progress: {
  19. label: '탐색 불가 진행바',
  20. style: `
  21. div.ytp-progress-bar-container[aria-disabled] {
  22. display: none !important;
  23. }
  24. `,
  25. },
  26. next: {
  27. label: '다음 재생 버튼',
  28. style: `
  29. a.ytp-next-button {
  30. display: none !important;
  31. }
  32. `,
  33. },
  34. autonav: {
  35. label: '자동 재생 버튼',
  36. style: `
  37. [data-tooltip-target-id="ytp-autonav-toggle-button"] {
  38. display: none !important;
  39. }
  40. `,
  41. },
  42. subtitle: {
  43. label: '사용 불가 자막 버튼',
  44. style: `
  45. .ytp-subtitles-button:not([title$="(c)"]):not(:hover) {
  46. display: none !important;
  47. }
  48. `,
  49. },
  50. youtube: {
  51. label: '유튜브에서 보기 버튼',
  52. style: `
  53. .ytp-youtube-button {
  54. display: none !important;
  55. }
  56. `,
  57. },
  58. miniplayer: {
  59. label: '미니 플레이어 버튼',
  60. style: `
  61. .ytp-miniplayer-button {
  62. display: none !important;
  63. }
  64. `,
  65. },
  66. theater: {
  67. label: '극장 모드 버튼',
  68. style: `
  69. .ytp-size-button {
  70. display: none !important;
  71. }
  72. `,
  73. },
  74. remote: {
  75. label: 'TV에서 보기 버튼',
  76. style: `
  77. .ytp-remote-button {
  78. display: none !important;
  79. }
  80. `,
  81. },
  82. fullscreen: {
  83. label: '전체화면 버튼',
  84. style: `
  85. .ytp-fullscreen-button {
  86. display: none !important;
  87. }
  88. `,
  89. },
  90. }
  91.  
  92. const defaultConfig = {
  93. progress: false,
  94. next: true,
  95. autonav: true,
  96. subtitle: false,
  97. youtube: false,
  98. miniplayer: true,
  99. theater: true,
  100. remote: true,
  101. fullscreen: true,
  102. }
  103.  
  104. const menuID = {
  105. progress: undefined,
  106. next: undefined,
  107. autonav: undefined,
  108. subtitle: undefined,
  109. youtube: undefined,
  110. miniplayer: undefined,
  111. theater: undefined,
  112. remote: undefined,
  113. fullscreen: undefined,
  114. }
  115.  
  116. let currentConfig = {
  117. ...defaultConfig,
  118. ...GM_getValue('config', undefined),
  119. }
  120.  
  121. const styleElement = document.createElement('style');
  122. document.head.append(styleElement);
  123.  
  124. function setStyle(config) {
  125. const configEntries = Object.entries(currentConfig);
  126. const styleList = configEntries
  127. .filter(([key, value]) => !value)
  128. .map(([key, value]) => ytButtons[key].style);
  129.  
  130. styleElement.textContent = styleList.join('\n');
  131. }
  132.  
  133. function commandGenerator(key) {
  134. return () => {
  135. currentConfig[key] = !currentConfig[key];
  136. GM_setValue('config', currentConfig);
  137. }
  138. }
  139.  
  140. function renderMenu() {
  141. Object.entries(currentConfig).forEach(([key, value]) => {
  142. const { label } = ytButtons[key];
  143.  
  144. menuID[key] = GM_registerMenuCommand(`${label}: ${value ? '표시됨': '숨겨짐'}`, commandGenerator(key));
  145. // console.log(`registered ${menuID[key]} (${key} - ${value})`);
  146. });
  147. }
  148.  
  149. function clearMenu() {
  150. Object.entries(menuID).forEach(([key, value]) => {
  151. // console.log(`unregistered ${value} (${key})`);
  152. GM_unregisterMenuCommand(value);
  153. });
  154. }
  155.  
  156. GM_addValueChangeListener('config', (_key, _prev, next) => {
  157. currentConfig = next;
  158. setStyle();
  159.  
  160. clearMenu();
  161. renderMenu();
  162. });
  163.  
  164. setStyle();
  165. renderMenu();