M-Team AV Cover Display

Extract AV codes on M-Team and display cover images

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         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);
})();