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.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като 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

})();