Walmart Business Name Extractor

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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);
})();