Youtube Player Simplifier

Remove buttons

目前為 2023-02-18 提交的版本,檢視 最新版本

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