☰

R34 Thumb LMB Control + Remove Tooltip

LMB opens video in bg tab + Remove Tooltip

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         R34 Thumb LMB Control + Remove Tooltip
// @namespace    http://tampermonkey.net/
// @version      3.3
// @match        https://rule34video.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=rule34video.com
// @grant        GM_openInTab
// @run-at       document-start
// @description LMB opens video in bg tab + Remove Tooltip
// ==/UserScript==

(function () {
  'use strict';

  // 1 = обычное поведение, 2 = отключить ЛКМ, 3 = открыть в фоновой вкладке
  const THUMB_LMB_MODE = 3;

  // Очистка нативных подсказок
  document.addEventListener('mouseover', function (e) {
    const el = e.target?.closest?.('[title]');
    if (el?.closest?.('.thumb, .th, .video-card-meta, .ma-thumb, .ma-v, .ma-v__t') && !el.closest('.vv-cardchip, [data-vv-chip]')) {
      el.removeAttribute('title');
    }
  }, true);

  // Поиск окна версий
  function getVersionsDialog(target) {
    if (target.closest('.vv-cardchip, [data-vv-chip]')) return null;
    if (target.closest('a[href*="/logout/"]')) return null;
    if (target.closest('#rd-hd-login, #rd-hd-sugg, .fancybox-wrap, .fancybox-overlay, .rda, [data-rd-account], [aria-controls="rd-hd-login"]')) return null;
    return target.closest(
      '#rd-hd-acct, ' +
      '[role="dialog"], [data-vv-dialog], [data-vv-pop], .fs-pop, .fs-sheet, ' +
      '.vv-popover, .vv-dialog, .vv-modal, .vv-cardpop, .vv-pop, .vv-menu, .vv-versions, ' +
      '[class*="vv-"][class*="pop"], [class*="vv-"][class*="dialog"], [class*="vv-"][class*="modal"], [class*="vv-"][class*="menu"], ' +
      '[class*="vv-"][class*="window"], [class*="vv-"][class*="sheet"]'
    );
  }

  // Поиск ссылки версии
  function getVersionLink(target, dialog) {
    if (target.closest('[data-rd-close], .close, [class*="close"], [aria-label*="close" i], [title*="close" i]')) {
      return null;
    }

    const directLink = target.closest('a[href]');
    if (directLink && dialog.contains(directLink)) {
      const href = directLink.getAttribute('href');
      if (href && !href.startsWith('#') && !href.startsWith('javascript:')) {
        return directLink.href;
      }
    }

    const row = target.closest(
      '[data-vv-id], [data-video-id], [data-href], ' +
      '.vv-item, .vv-row, [class*="vv-"][class*="item"], [class*="version"], [role="listitem"]'
    );
    if (row && dialog.contains(row)) {
      const innerLink = row.querySelector('a[href]');
      if (innerLink) {
        const href = innerLink.getAttribute('href');
        if (href && !href.startsWith('#') && !href.startsWith('javascript:')) {
          return innerLink.href;
        }
      }

      const dataHref = row.getAttribute('data-href');
      if (dataHref) {
        return new URL(dataHref, location.origin).href;
      }

      const videoId = row.getAttribute('data-vv-id') || row.getAttribute('data-video-id');
      if (videoId) {
        return `${location.origin}/video/${videoId}/`;
      }

      const card = row.closest('.item, [data-video-card-id]') || dialog.closest('.item, [data-video-card-id]');
      const cardLink = card?.querySelector('a.th, a[href*="/video/"]');
      if (cardLink && cardLink.href) {
        return cardLink.href;
      }
    }

    return null;
  }

  // Открытие ссылки
  function openLink(e, href) {
    e.preventDefault();
    e.stopImmediatePropagation();

    if (THUMB_LMB_MODE === 3) {
      GM_openInTab(href, {
        active: false,
        insert: true,
        setParent: true
      });
    }
  }

  // Обработка клика ЛКМ
  if (THUMB_LMB_MODE !== 1) {
    document.addEventListener('click', function (e) {
      if (e.button !== 0) return;

      // Игнорирование кнопки выбора версий
      if (e.target.closest('.vv-cardchip, [data-vv-chip]')) {
        return;
      }

      // Обработка клика в окне версий
      const dialog = getVersionsDialog(e.target);
      if (dialog) {
        const versionHref = getVersionLink(e.target, dialog);
        if (versionHref) {
          openLink(e, versionHref);
        }
        return;
      }

      // Обработка клика по миниатюре
      const thumb = e.target.closest('.thumb, .th, .ma-thumb');
      if (!thumb) return;

      const link = thumb.tagName.toLowerCase() === 'a' ? thumb : (thumb.closest('a') || thumb.querySelector('a'));
      if (!link || !link.href) {
        const card = thumb.closest('.item, .ma-v');
        const fallbackLink = card?.querySelector('a.th, a.ma-thumb, a.ma-v__t, a[href*="/video/"]');
        if (fallbackLink && fallbackLink.href) {
          openLink(e, fallbackLink.href);
        }
        return;
      }

      openLink(e, link.href);
    }, true);
  }
})();