Replace "Available" with non-clickable Attack-Links

Replaces "available" with non-clickable attack links in the Item Market.

Εγκατάσταση αυτού του κώδικαΒοήθεια
Κώδικας προτεινόμενος από τον δημιιουργό

Μπορεί, επίσης, να σας αρέσει ο κώδικας Makes the Attack-Links clickable..

Εγκατάσταση αυτού του κώδικα

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Replace "Available" with non-clickable Attack-Links
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Replaces "available" with non-clickable attack links in the Item Market.
// @author       Grance [3487987]
// @match        *://www.torn.com/page.php?sid=ItemMarket*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // Function to replace "available" with attack links based on extracted IDs
    function replaceAvailableWithAttackLinks() {
       // Select only profile links inside the seller list
        const sellerList = document.querySelector('ul.sellerList___kgAh_'); // Get the <ul> with class 'sellerList___kgAh_'

        if (sellerList){
            const profileLinks = sellerList.querySelectorAll('a[href^="/profiles.php?XID="]'); // Only anchor tags with href starting with '/profiles.php?XID='

        // Iterate through the links and extract their IDs
        const profileIDs = Array.from(profileLinks).map(link => {
            const url = new URL(link.href, 'https://www.torn.com'); // Handle relative URLs
            return url.searchParams.get('XID'); // Extract the XID parameter from the href
        });


        // Counter to track replacements
        let replacementIndex = 0;

        // Use TreeWalker to find text nodes with "available"
        const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, {
            acceptNode: function (node) {
                if (node.nodeValue.includes('available') && replacementIndex < profileIDs.length) {
                    return NodeFilter.FILTER_ACCEPT;
                }
                return NodeFilter.FILTER_REJECT;
            }
        });

        let node;
        while ((node = walker.nextNode())) {
            node.nodeValue = node.nodeValue.replace(/available/, () => {
                // Get the ID at the current replacement index
                const id = profileIDs[replacementIndex];
                replacementIndex++;
                return `https://www.torn.com/loader.php?sid=attack&user2ID=${id}`;
            });
        }}
    }

    // Run the replacement function after the page has fully loaded
    window.addEventListener('load', () => {
        replaceAvailableWithAttackLinks();
    });

    // Observe for dynamic updates and replace again
    const observer = new MutationObserver(() => {
        replaceAvailableWithAttackLinks();
    });

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