Walmart Business Name Extractor

Extracts business name from Walmart.com seller page and appends it after the "Sold by" div

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

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

1// ==UserScript==
// @name         Walmart Business Name Extractor
// @namespace    talus.dev
// @version      1.2
// @description  Extracts business name from Walmart.com seller page and appends it after the "Sold by" div
// @match        https://www.walmart.com/ip/*
// @grant        none
// @license      GPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';
  function decode(str) {
    let txt = document.createElement("textarea");
    txt.innerHTML = str;
    return txt.value;
  }

    // Function to extract the business name from the seller page
    function extractBusinessName() {
        const linkElement = document.querySelector('a[data-testid="view-seller-info-link"]');
        if (linkElement) {
            const sellerUrl = linkElement.href;
            fetch(sellerUrl)
                .then(response => response.text())
                .then(html => {
                    const businessNameRegex = /Business Name: <!-- -->\s*(.*?)<\/div>/;
                    const match = html.match(businessNameRegex);
                    if (match && match.length > 1) {
                        const businessName = match[1].trim();
                        console.log('Business Name:', businessName);

                        // Find the "Sold by" div on the original page
                        const soldByDivs = document.getElementsByClassName('lh-copy');
                        for (let i = 0; i < soldByDivs.length; i++) {
                            const soldByDiv = soldByDivs[i];
                            if (soldByDiv.textContent.match(/Sold.+by/)) {
                                // Create a new span element for the business name
                                const businessNameDiv = document.createElement('div');
                                businessNameDiv.className = 'mr0 black-90 b';
                                businessNameDiv.textContent = 'Business Name: ' + decode(businessName);

                                // Append the business name after the "Sold by" div
                                soldByDiv.appendChild(document.createTextNode(' '));
                                soldByDiv.appendChild(businessNameDiv);
                                break;
                            }
                        }
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                });
        }
    }

    // Call the extractBusinessName function when the page finishes loading
    window.addEventListener('load', extractBusinessName);
})();