M-Team AV Cover Display

Extract AV codes on M-Team and display cover images

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 or Violentmonkey 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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         M-Team AV Cover Display
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Extract AV codes on M-Team and display cover images
// @author       winnie
// @match        https://*.m-team.cc/browse/adult*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    /**
     * Extracts the first AV code from a string.
     * Matches formats like ABC-123, ABCD-123, etc.
     * @param {string} text
     * @returns {string|null}
     */
    function extractFirstAvCode(text) {
        const avRegex = /([A-Z]{2,5})-(\d{2,5})/;
        const match = text.match(avRegex);
        return match ? match[0] : null;
    }

    /**
     * Processes a <span> element to check and insert AV cover image.
     * @param {HTMLElement} span
     */
    function processSpan(span) {
        const avCode = extractFirstAvCode(span.textContent);
        if (!avCode) return;

        const lowerCode = avCode.toLowerCase();
        const img = document.createElement('img');
        img.src = `http://fourhoi.com/${lowerCode}/cover-n.jpg`;
        img.style.maxWidth = '280px';
        img.style.marginRight = '5px';
        img.style.verticalAlign = 'middle';
        img.style.transition = 'transform 0.3s ease';

        img.onerror = () => img.remove();

        span.parentNode.insertBefore(img, span);
    }

    /**
     * Initializes the script by processing current spans
     * and observing dynamic DOM changes.
     */
    function initAvCoverDisplay() {
        const spans = document.querySelectorAll('span[aria-describedby]');
        spans.forEach(processSpan);

        const observer = new MutationObserver(mutations => {
            for (const mutation of mutations) {
                for (const node of mutation.addedNodes) {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        const newSpans = node.querySelectorAll('span[aria-describedby]');
                        newSpans.forEach(processSpan);
                    }
                }
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    window.addEventListener('load', initAvCoverDisplay);
})();