M-Team AV Cover Display

Extract AV codes on M-Team and display cover images

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला 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);
})();