GEVI - Enhancer

Automatically selects entries in dropdowns and buttons on /movies* and /performer* pages, also adds search link to pbc.xxx/*. Some other tweaks too.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GEVI - Enhancer
// @namespace    https://github.com/BD9Max/userscripts
// @version      1.3
// @description  Automatically selects entries in dropdowns and buttons on /movies* and /performer* pages, also adds search link to pbc.xxx/*. Some other tweaks too.
// @author       krbd9max
// @license      MIT
// @match        https://gayeroticvideoindex.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  // Auto-select 100 entries
  function setLengthTo100() {
    const selects = document.querySelectorAll(
      'select[name$="_length"], .dataTables_length select, select'
    );

    selects.forEach(sel => {
      const opt100 = Array.from(sel.options).find(
        o => o.value === '100' || o.textContent.trim() === '100'
      );
      if (opt100 && sel.value !== '100') {
        sel.value = '100';
        sel.dispatchEvent(new Event('change', { bubbles: true }));
      }
    });
  }

  // 2. Auto-select "Hide Compilations"
  function selectHideCompilations() {
    const candidates = [
      ...document.querySelectorAll('input[type="radio"], input[type="checkbox"]')
    ];

    for (const input of candidates) {
      const value = (input.value || '').toLowerCase();
      const id = (input.id || '').toLowerCase();
      const name = (input.name || '').toLowerCase();
      const label = input.labels?.[0]?.textContent?.toLowerCase() || '';
      const parentText = input.parentElement?.textContent?.toLowerCase() || '';

      if (
        value.includes('hide') ||
        id.includes('hide') ||
        name.includes('hide') ||
        label.includes('hide compilations') ||
        parentText.includes('hide compilations')
      ) {
        if (!input.checked) {
          input.checked = true;
          input.dispatchEvent(new Event('change', { bubbles: true }));
          input.dispatchEvent(new Event('click', { bubbles: true }));
        }
        return;
      }
    }

    // Fallback: click element containing the text
    const textNodes = document.evaluate(
      "//*[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'hide compilations')]",
      document,
      null,
      XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
      null
    );

    for (let i = 0; i < textNodes.snapshotLength; i++) {
      const el = textNodes.snapshotItem(i);
      const clickable = el.closest('label, button, a, span, div') || el;
      clickable.click();
      break;
    }
  }

  // Add pbc.xxx search link next to performer name
  function addPerformerSearchLink() {
    if (!location.pathname.startsWith('/performer/')) return;

    // Target the h1 that contains the performer name
    const h1 = document.querySelector('h1.text-3xl.text-yellow-200, h1.text-yellow-200, .pt-2 > h1');
    if (!h1 || h1.dataset.pbcLinkAdded) return;

    const name = h1.textContent.trim();
    if (!name) return;

    const searchUrl = 'https://pbc.xxx/w/index.php?search=' + encodeURIComponent(name).replace(/%20/g, '+');

    const link = document.createElement('a');
    link.href = searchUrl;
    link.target = '_self';
    link.rel = 'noopener noreferrer';
    link.textContent = ' [PBC]';
    link.title = 'Search on pbc.xxx';
    link.style.cssText = 'margin-left: 0.5rem; font-size: 0.7em; color: #60a5fa; text-decoration: none; vertical-align: middle;';
    link.onmouseover = () => link.style.textDecoration = 'underline';
    link.onmouseout  = () => link.style.textDecoration = 'none';

    // Insert right after the name (same row)
    h1.appendChild(link);
    h1.dataset.pbcLinkAdded = '1';
  }

  // Add pbc.xxx search link next to video title
  function addVideoSearchLink() {
    if (!location.pathname.startsWith('/video/')) return;

    // Target the video title h1
    const h1 = document.querySelector(
      'h1.text-yellow-300, h1.text-center.text-2xl, h1.md\\:text-3xl'
    );
    if (!h1 || h1.dataset.pbcLinkAdded) return;

    const title = h1.textContent.trim();
    if (!title) return;

    const searchUrl = 'https://pbc.xxx/w/index.php?search=' + encodeURIComponent(title).replace(/%20/g, '+');

    const link = document.createElement('a');
    link.href = searchUrl;
    link.target = '_self';
    link.rel = 'noopener noreferrer';
    link.textContent = ' [PBC]';
    link.title = 'Search on pbc.xxx';
    link.style.cssText = 'margin-left: 0.5rem; font-size: 0.7em; color: #60a5fa; text-decoration: none; vertical-align: middle;';
    link.onmouseover = () => link.style.textDecoration = 'underline';
    link.onmouseout  = () => link.style.textDecoration = 'none';

    h1.appendChild(link);
    h1.dataset.pbcLinkAdded = '1';
  }

  // Runner
  function run() {
    setLengthTo100();
    selectHideCompilations();
    addPerformerSearchLink();
    addVideoSearchLink();
  }

  // Initial runs
  run();
  setTimeout(run, 400);
  setTimeout(run, 1200);
  setTimeout(run, 2500);

  // Watch for dynamic changes
  const observer = new MutationObserver(() => run());
  observer.observe(document.body, { childList: true, subtree: true });

  // DataTables redraw support
  if (window.jQuery) {
    jQuery(document).on('draw.dt', run);
  }
})();