Toggle Youtube Styles

Adds toggles to enable/disable some styles that change Youtube

Από την 21/05/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Toggle Youtube Styles
// @license     MIT
// @namespace   rtonne
// @match       https://www.youtube.com/*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @version     1.4
// @author      Rtonne
// @description Adds toggles to enable/disable some styles that change Youtube
// @grant       GM.addStyle
// @grant       GM.registerMenuCommand
// @grant       GM.unregisterMenuCommand
// @grant       GM.getValue
// @grant       GM.setValue
// ==/UserScript==

// To check if inplace command replacement is supported
// https://violentmonkey.github.io/api/gm/#gm_registermenucommand
const inplace =
  "test" === GM.registerMenuCommand("test", () => {}, { id: "test" });
GM.unregisterMenuCommand("test");

const commands = [
  {
    id: "guide_sections",
    disabled_caption: "☑ Guide Sections",
    enabled_caption: "☐ Guide Sections",
    disableStyle: () =>
      GM.addStyle(`
      #sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(n+3) {
        display: unset;
      }
    `),
    enableStyle: () =>
      GM.addStyle(`
      #sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(n+3) {
        display: none;
      }
    `),
  },
  {
    id: "comments",
    disabled_caption: "☑ Comments",
    enabled_caption: "☐ Comments",
    disableStyle: () =>
      GM.addStyle(`
      ytd-comments#comments {
        display: unset;
      }
    `),
    enableStyle: () =>
      GM.addStyle(`
      ytd-comments#comments {
        display: none;
      }
    `),
  },
  {
    id: "related_videos",
    disabled_caption: "☑ Related Videos",
    enabled_caption: "☐ Related Videos",
    disableStyle: () =>
      GM.addStyle(`
      #secondary.ytd-watch-flexy > #secondary-inner > #related {
        display: unset;
      }
    `),
    enableStyle: () =>
      GM.addStyle(`
      #secondary.ytd-watch-flexy > #secondary-inner > #related {
        display: none;
      }
    `),
  },
  {
    id: "shorts",
    disabled_caption: "☑ Shorts",
    enabled_caption: "☐ Shorts",
    disableStyle: () =>
      GM.addStyle(`
      ytd-rich-section-renderer:has(> div > [is-shorts]) {
        display: unset;
      }
    `),
    enableStyle: () =>
      GM.addStyle(`
      ytd-rich-section-renderer:has(> div > [is-shorts]) {
        display: none;
      }
    `),
  },
  {
    id: "community",
    disabled_caption: "☑ Community Posts",
    enabled_caption: "☐ Community Posts",
    disableStyle: () =>
      GM.addStyle(`
      ytd-rich-section-renderer:has(> div > :not([is-shorts]):not([thumbnail-style])) {
        display: unset;
      }
    `),
    enableStyle: () =>
      GM.addStyle(`
      ytd-rich-section-renderer:has(> div > :not([is-shorts]):not([thumbnail-style])) {
        display: none;
      }
    `),
  },
];

for (const command of commands) {
  setCommand(command);
}
registerAllCommands();

async function registerAllCommands() {
  for (const command of commands) {
    GM.registerMenuCommand(
      await getCaption(command),
      () => toggleCommand(command),
      { id: command.id, autoClose: false }
    );
  }
}
async function unregisterAllCommands() {
  for (const command of commands) {
    GM.unregisterMenuCommand(command.id);
  }
}
async function toggleCommand(command) {
  await GM.setValue(command.id, !(await GM.getValue(command.id, false)));
  setCommand(command);
  if (inplace) {
    GM.registerMenuCommand(
      await getCaption(command),
      () => toggleCommand(command),
      { id: command.id, autoClose: false }
    );
  } else {
    unregisterAllCommands();
    registerAllCommands();
  }
}
async function setCommand(command) {
  if (await GM.getValue(command.id, false)) {
    command.enableStyle();
  } else {
    command.disableStyle();
  }
}
async function getCaption(command) {
  let caption = command.enabled_caption;
  if (!(await GM.getValue(command.id, false))) {
    caption = command.disabled_caption;
  }
  return caption;
}