jav.guru: Add MissAV link next to Code

Find "Code:" in <li> elements and add a MissAV search link next to the code

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         jav.guru: Add MissAV link next to Code
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Find "Code:" in <li> elements and add a MissAV search link next to the code
// @match        https://jav.guru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=jav.guru
// @grant        none
// @run-at       document-end
// @license      Public Domain
// ==/UserScript==

(function () {
    'use strict';

    // Extract the code from text like "Code: ***-***"
    function extractCode(text) {
        const m = text.match(/Code:\s*([A-Za-z0-9-]+)/);
        return m ? m[1] : null;
    }

    // Add the MissAV link if not already added
    function addLink(li) {
        const text = li.textContent || '';
        const code = extractCode(text);
        if (!code) return false;

        // Avoid duplicates
        if (li.querySelector('.missav-link')) return true;

        const link = document.createElement('a');
        link.href = `https://missav.ws/en/search/${encodeURIComponent(code)}`;
        link.textContent = 'MissAV';
        link.target = '_blank';
        link.rel = 'nofollow noopener';
        link.className = 'missav-link';
        link.style.marginLeft = '8px';
        link.style.color = '#1e90ff';
        link.style.textDecoration = 'none';

        // Insert link after the code text
        li.appendChild(link);
        console.log(`[MissAV Link] Added for code: ${code}`);
        return true;
    }

    // Try to find and add links to any matching elements
    function processAll() {
        let added = false;
        document.querySelectorAll('li').forEach(li => {
            if (addLink(li)) added = true;
        });
        return added;
    }

    // Observe for dynamically added content
    function initObserver() {
        if (processAll()) return; // maybe already added

        const observer = new MutationObserver((mutations, obs) => {
            if (processAll()) {
                // stop if you only want to add once
                // obs.disconnect();
            }
        });

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

    // Run
    initObserver();
})();