Youtube Button Remover

Remove buttons

2022-04-24 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Youtube Button Remover
// @namespace   LeKAKiD
// @match       https://*/*
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_registerMenuCommand
// @version     1.4
// @author      LeKAKiD
// @description Remove buttons
// @license     MIT
// ==/UserScript==

const ytButtons = {
  next: {
    label: '1 다음 재생 버튼',
    style: `
      a.ytp-next-button {
        display: none !important;
      }
    `,
  },
  autonav: {
    label: '2 자동 재생 버튼',
    style: `
      [data-tooltip-target-id="ytp-autonav-toggle-button"] {
        display: none !important;
      }
    `,
  },
  subtitle: {
    label: '3 사용 불가 자막 버튼',
    style: `
      .ytp-subtitles-button:not([title$="(c)"]):not(:hover) {
        display: none !important;
      }
    `,
  },
  youtube: {
    label: '4 유튜브에서 보기 버튼',
    style: `
      .ytp-youtube-button {
        display: none !important;
      }
    `,
  },
  miniplayer: {
    label: '5 미니 플레이어 버튼',
    style: `
      .ytp-miniplayer-button {
        display: none !important;
      }
    `,
  },
  theater: {
    label: '6 극장 모드 버튼',
    style: `
      .ytp-size-button {
        display: none !important;
      }
    `,
  },
}

const defaultConfig = {
  next: true,
  autonav: true,
  subtitle: false,
  youtube: false,
  miniplayer: true,
  theater: true,
}

const currentConfig = {
  ...defaultConfig,
  ...GM_getValue('config', undefined),
}

const styleElement = document.createElement('style');
document.head.append(styleElement);

function setStyle() {
  const configEntries = Object.entries(currentConfig);
  const style = configEntries.reduce((prev, [key, value]) => prev + (!value ? ytButtons[key].style : ''), '');
  styleElement.textContent = style;
}

const urlRegex = /https:\/\/(www\.){0,1}youtube\.com\/($|(|watch|embed).*)/;
if(urlRegex.test(location.href)) setStyle();

const frames = [...document.querySelectorAll('iframe')];

if(frames.some(e => urlRegex.test(e.src))) {
  Object.keys(defaultConfig).forEach(key => {
    GM_registerMenuCommand(ytButtons[key].label, () => {
      currentConfig[key] = !currentConfig[key];
      GM_setValue('config', currentConfig);
      if(urlRegex.test(location.href)) setStyle();
    });
  });
}
else {
  GM_registerMenuCommand('확인된 유튜브 영상 없음');
}