YT: not interested in one click

Hover a thumbnail on youtube.com and click an icon at the right: "Not interested" and "Don't recommend channel"

La data de 03-02-2023. Vezi ultima versiune.

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           YT: not interested in one click
// @description    Hover a thumbnail on youtube.com and click an icon at the right: "Not interested" and "Don't recommend channel"
// @version        1.1.6
//
// @match          https://www.youtube.com/*
//
// @noframes
// @grant          none
//
// @author         wOxxOm
// @namespace      wOxxOm.scripts
// @license        MIT License
// ==/UserScript==

const ME = 'yt-one-click-dismiss';
const THUMB_TAG = 'ytd-thumbnail';
const PREVIEW = '#buttons';
const COMMANDS = {
  NOT_INTERESTED: {block: 'video', text: 'Not interested'},
  REMOVE: {block: 'channel', text: "Don't recommend channel"},
  DELETE: {block: 'unwatch', text: "Remove from 'Watch later'"},
};
let STYLE;

addEventListener('mouseover', onHover);
addEventListener('click', onClick, true);

function onHover(e) {
  for (const el of e.composedPath()) {
    const thumb = el.localName === THUMB_TAG && el ||
      el.id === 'media-container-link' && el.querySelector(THUMB_TAG);
    if (!thumb) continue;
    const elPreview = thumb.closest('ytd-video-preview');
    const elems = [...getMenuItems(elPreview || thumb)].map(cmd => cmd.element);
    const parent = elPreview ? elPreview.querySelector(PREVIEW) : thumb;
    if (elems.some(el => el.parentNode !== parent)) {
      parent.append(...elems);
    }
    break;
  }
}

async function onClick(e) {
  const {target} = e;
  const {block} = target.classList.contains(ME) && target.dataset;
  if (!block)
    return;
  e.stopPropagation();
  e.preventDefault();
  let index;
  try {
    index = STYLE.sheet.insertRule('ytd-menu-popup-renderer { display: none !important }');
    for (let more, el = target; el; el = el.parentElement) {
      if ((more = el.querySelector('.dropdown-trigger'))) {
        await 0;
        more.dispatchEvent(new Event('click'));
        await new Promise(setTimeout);
        break;
      }
    }
    for (const el of document.querySelector('ytd-menu-popup-renderer [role="listbox"]').children) {
      if (block === (COMMANDS[getProp(el, 'data.icon.iconType')] || {}).block) {
        el.click();
        break;
      }
    }
  } catch (e) {}
  await new Promise(setTimeout);
  document.body.click();
  await new Promise(setTimeout);
  STYLE.sheet.deleteRule(index);
}

function *getMenuItems(thumb) {
  for (const item of getProp(thumb, '__data.data.menu.menuRenderer.items') || []) {
    const type = getProp(item, 'menuServiceItemRenderer.icon.iconType');
    const data = COMMANDS[type];
    if (data) {
      if (!data.element) {
        const el = data.element = document.createElement('div');
        const text = getProp(item, 'menuServiceItemRenderer.text');
        el.className = ME;
        el.dataset.block = data.block;
        el.title = text.runs.map(r => r.text).join('') || data.text;
      }
      yield data;
    }
  }
  if (!STYLE) initStyle();
}

function getProp(obj, path) {
  return path.split('.').reduce((res, name) => res && res[name],
    (obj.wrappedJSObject || {}).__data || obj);
}

function initStyle() {
  STYLE = document.createElement('style');
  STYLE.textContent = /*CSS*/ `
ytd-video-preview[mini-mode] #buttons.ytd-video-preview {
  padding-right: 30px;
  position: relative;
}
${PREVIEW} .${ME} {
  opacity: .5;
}
${PREVIEW} .${ME},
${THUMB_TAG}:hover .${ME} {
  display: block;
}
.${ME} {
  display: none;
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 100%;
  border: 2px solid #fff;
  right: 8px;
  background: #0006;
  box-shadow: .5px .5px 7px #000;
  cursor: pointer;
  opacity: .75;
  z-index: 11000;
}
${PREVIEW} .${ME}:hover,
.${ME}:hover {
  opacity: 1;
}
.${ME}:active {
  color: yellow;
}
.${ME}[data-block] { top: 70px; }
.${ME}[data-block="channel"] { top: 100px; }
${PREVIEW} .${ME}[data-block] { top: 9px; right: 0; }
${PREVIEW} .${ME}[data-block="channel"] { top: 50px; right: 0; }
.ytd-playlist-video-renderer .${ME}[data-block="unwatch"] {
  top: 15px;
}
ytd-compact-video-renderer .${ME}[data-block] {
  top: 70px;
  right: 7px;
  box-shadow: .5px .5px 4px 6px #000;
  background: #000;
}
ytd-compact-video-renderer .${ME}[data-block="channel"] {
  right: 37px;
}
.${ME}::before {
  position: absolute;
  content: '';
  top: -8px;
  left: -6px;
  width: 32px;
  height: 30px;
}
.${ME}::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  margin: auto;
  border: none;
  border-bottom: 2px solid #fff;
}
.${ME}[data-block="video"]::after {
  transform: rotate(45deg);
}
.${ME}[data-block="channel"]::after {
  margin: auto 3px;
}
`.replace(/;/g, '!important;');
  document.head.appendChild(STYLE);
}