Walmart Mobile Share Button

Brings back the native share button on Walmart product pages!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Walmart Mobile Share Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Brings back the native share button on Walmart product pages!
// @match        *://*.walmart.com/*
// @grant        none
// @license      MIT
// @esversion    8
// ==/UserScript==

(function() {
    'use strict';

    // This function builds our shiny new button
    function injectShareButton() {
        // If our button is already hanging out on the page, don't make a clone!
        if (document.getElementById('rogue-share-btn')) return;

        // Create the button element
        const shareBtn = document.createElement('button');
        shareBtn.id = 'rogue-share-btn';
        shareBtn.innerHTML = '🔗 Share'; 
        
        // Let's make it look like a native app button (High contrast, easy to tap!)
        Object.assign(shareBtn.style, {
            position: 'fixed',
            bottom: '90px', // Sits perfectly above the bottom navigation bar
            right: '20px',
            zIndex: '99999',
            backgroundColor: '#0071dc', // Official Walmart Blue
            color: '#ffffff', // Crisp white text for readability
            border: '2px solid #004c91', // Darker border for contrast
            borderRadius: '50px',
            padding: '14px 24px',
            fontSize: '18px',
            fontWeight: 'bold',
            boxShadow: '0 6px 12px rgba(0,0,0,0.4)', // Nice drop shadow so it floats
            cursor: 'pointer'
        });

        // The magic that happens when you tap it
        shareBtn.addEventListener('click', async () => {
            // Grab the product title (Walmart usually puts this in an <h1> tag)
            const titleElement = document.querySelector('h1');
            const productTitle = titleElement ? titleElement.innerText : 'Check out this item at Walmart';
            
            // Grab the URL, but strip out all the messy tracking garbage at the end
            const cleanUrl = window.location.origin + window.location.pathname;

            try {
                // Call the phone's native Share menu (The cool part!)
                if (navigator.share) {
                    await navigator.share({
                        title: productTitle,
                        text: `Hey! Check this out on Walmart: ${productTitle}`,
                        url: cleanUrl
                    });
                } else {
                    // Plan B: Just in case the browser gets grumpy
                    navigator.clipboard.writeText(cleanUrl);
                    alert('Link copied to clipboard! Ready to paste.');
                }
            } catch (err) {
                // If they close the share menu without sending, just silently ignore it
                console.log('Share cancelled by user.');
            }
        });

        // Slap the button onto the webpage
        document.body.appendChild(shareBtn);
    }

    // Because Walmart's site loads pages dynamically without refreshing, 
    // we need a little night-watchman to check if we are on a product page.
    setInterval(() => {
        // If the URL has "/ip/" in it, we are looking at an item!
        if (window.location.href.includes('/ip/')) {
            injectShareButton();
        } else {
            // If we went back to the home page, hide the evidence
            const existingBtn = document.getElementById('rogue-share-btn');
            if (existingBtn) existingBtn.remove();
        }
    }, 1000); // The watchman checks the aisle every 1 second

})();