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

})();