My GreaseMonkey Scripts

Created: 2025-05-29 14:52:17 | Last updated: 2025-05-30 00:04:00 | Status: Public


// ==UserScript==
// @name         Webpage Fullscreen Toggle
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a button to toggle fullscreen mode for any webpage
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Create the fullscreen toggle button
    const fullscreenButton = document.createElement('button');
    fullscreenButton.textContent = '⛶';
    fullscreenButton.title = 'Toggle Fullscreen';
    fullscreenButton.style.position = 'fixed';
    fullscreenButton.style.bottom = '20px';
    fullscreenButton.style.right = '20px';
    fullscreenButton.style.zIndex = '9999';
    fullscreenButton.style.fontSize = '24px';
    fullscreenButton.style.background = 'none';
    fullscreenButton.style.border = 'none';
    fullscreenButton.style.cursor = 'pointer';
    fullscreenButton.style.color = '#666666';



    // Add hover effect
    fullscreenButton.addEventListener('mouseover', function() {
        this.style.opacity = '0.8';
    });

    fullscreenButton.addEventListener('mouseout', function() {
        this.style.opacity = '1';
    });

    // Function to toggle fullscreen
    function toggleFullScreen() {
        if (!document.fullscreenElement) {
            // If not in fullscreen mode, enter fullscreen
            if (document.documentElement.requestFullscreen) {
                document.documentElement.requestFullscreen();
                fullscreenButton.textContent = '⏹';
            } else if (document.documentElement.mozRequestFullScreen) { // Firefox
                document.documentElement.mozRequestFullScreen();
                fullscreenButton.textContent = '⏹';
            } else if (document.documentElement.webkitRequestFullscreen) { // Chrome, Safari
                document.documentElement.webkitRequestFullscreen();
                fullscreenButton.textContent = '⏹';
            } else if (document.documentElement.msRequestFullscreen) { // IE/Edge
                document.documentElement.msRequestFullscreen();
                fullscreenButton.textContent = '⏹';
            }
        } else {
            // If in fullscreen mode, exit fullscreen
            if (document.exitFullscreen) {
                document.exitFullscreen();
                fullscreenButton.textContent = '⛶';
            } else if (document.mozCancelFullScreen) { // Firefox
                document.mozCancelFullScreen();
                fullscreenButton.textContent = '⛶';
            } else if (document.webkitExitFullscreen) { // Chrome, Safari
                document.webkitExitFullscreen();
                fullscreenButton.textContent = '⛶';
            } else if (document.msExitFullscreen) { // IE/Edge
                document.msExitFullscreen();
                fullscreenButton.textContent = '⛶';
            }
        }
    }

    // Add click event to the button
    fullscreenButton.addEventListener('click', toggleFullScreen);

    // Listen for fullscreenchange event to update button appearance
    document.addEventListener('fullscreenchange', function() {
        if (document.fullscreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    // Also handle browser-specific events
    document.addEventListener('mozfullscreenchange', function() {
        if (document.mozFullScreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    document.addEventListener('webkitfullscreenchange', function() {
        if (document.webkitFullscreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    document.addEventListener('MSFullscreenChange', function() {
        if (document.msFullscreenElement) {
            fullscreenButton.textContent = '⏹';
        } else {
            fullscreenButton.textContent = '⛶';
        }
    });

    // Add the button to the page
    document.body.appendChild(fullscreenButton);

    // Key shortcut (Alt+F) to toggle fullscreen
    document.addEventListener('keydown', function(e) {
        if (e.altKey && e.key === 'f') {
            toggleFullScreen();
        }
    });
})();

// ==UserScript==
// @name         Walmart Price Per Pound Calculator
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Display price per pound/ounce conversions on Walmart.com
// @author       ill13
// @match        https://www.walmart.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function calculatePricePerPound(pricePerOunce) {
        // Convert price per ounce to price per pound (16 oz = 1 lb)
        return pricePerOunce * 16;
    }

    function calculatePricePerOunce(pricePerPound) {
        // Convert price per pound to price per ounce (1 lb = 16 oz)
        return pricePerPound / 16;
    }

    function formatPrice(price) {
        // Format price to 2 decimal places with $ symbol
        return '$' + price.toFixed(2);
    }

    function formatCents(price) {
        // Format price as cents with ¢ symbol
        return (price * 100).toFixed(1) + '¢';
    }

    function extractPriceFromText(text) {
        // Extract numeric price from text like "27.8 ¢/oz" or "$5.97/lb"
        const centMatch = text.match(/(\d+\.?\d*)\s*¢/);
        if (centMatch) {
            return parseFloat(centMatch[1]) / 100; // Convert cents to dollars
        }

        // Handle dollar format like "$2.50/oz" or "$5.97/lb"
        const dollarMatch = text.match(/\$(\d+\.?\d*)/);
        if (dollarMatch) {
            return parseFloat(dollarMatch[1]);
        }

        return null;
    }

    function addPriceConversions() {
        // Find all price per unit elements - broader selector to catch various formats
        const priceElements = document.querySelectorAll('div.gray[class*="f6"][class*="flex"]');

        priceElements.forEach(element => {
            // Skip if already processed
            if (element.dataset.processed) return;

            const text = element.textContent.trim();

            // Only process elements that contain unit pricing
            if (!text.includes('/oz') && !text.includes('/lb')) return;

            const priceValue = extractPriceFromText(text);

            if (priceValue !== null) {
                // Handle price per ounce -> price per pound
                if (text.includes('/oz')) {
                    const pricePerPound = calculatePricePerPound(priceValue);
                    const formattedPricePerPound = formatPrice(pricePerPound);
                    element.textContent = text + ' (' + formattedPricePerPound + ')';
                    element.dataset.processed = 'true';
                }
                // Handle price per pound -> price per ounce
                else if (text.includes('/lb')) {
                    const pricePerOunce = calculatePricePerOunce(priceValue);
                    const formattedPricePerOunce = formatCents(pricePerOunce);
                    element.textContent = text + ' (' + formattedPricePerOunce + ')';
                    element.dataset.processed = 'true';
                }
            }
        });
    }

    function observeChanges() {
        // Create a MutationObserver to handle dynamically loaded content
        const observer = new MutationObserver(function(mutations) {
            let shouldProcess = false;

            mutations.forEach(function(mutation) {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    shouldProcess = true;
                }
            });

            if (shouldProcess) {
                // Use setTimeout to allow DOM to settle
                setTimeout(addPriceConversions, 100);
            }
        });

        // Start observing
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    // Initial processing when page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(addPriceConversions, 500);
            observeChanges();
        });
    } else {
        setTimeout(addPriceConversions, 500);
        observeChanges();
    }

    // Also run when navigating (for SPAs)
    let currentUrl = location.href;
    new MutationObserver(() => {
        if (location.href !== currentUrl) {
            currentUrl = location.href;
            setTimeout(addPriceConversions, 1000);
        }
    }).observe(document, { subtree: true, childList: true });

})();
// ==UserScript==
// @name         Walmart Price Per Pound Calculator
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Display price per pound alongside price per ounce on Walmart.com
// @author       ill13
// @match        https://www.walmart.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function calculatePricePerPound(pricePerOunce) {
        // Convert price per ounce to price per pound (16 oz = 1 lb)
        return pricePerOunce * 16;
    }

    function formatPrice(price) {
        // Format price to 2 decimal places with $ symbol
        return '$' + price.toFixed(2);
    }

    function extractPriceFromText(text) {
        // Extract numeric price from text like "27.8 ¢/oz"
        const match = text.match(/(\d+\.?\d*)\s*¢/);
        if (match) {
            return parseFloat(match[1]) / 100; // Convert cents to dollars
        }

        // Handle dollar format like "$2.50/oz"
        const dollarMatch = text.match(/\$(\d+\.?\d*)/);
        if (dollarMatch) {
            return parseFloat(dollarMatch[1]);
        }

        return null;
    }

    function addPricePerPound() {
        // Find all price per ounce elements
        const priceElements = document.querySelectorAll('div.gray.mr1.f6.f5-l.flex.items-end.mt1');

        priceElements.forEach(element => {
            // Skip if already processed
            if (element.dataset.processed) return;

            const text = element.textContent.trim();

            // Check if this is a price per ounce element
            if (text.includes('/oz')) {
                const pricePerOunce = extractPriceFromText(text);

                if (pricePerOunce !== null) {
                    const pricePerPound = calculatePricePerPound(pricePerOunce);
                    const formattedPricePerPound = formatPrice(pricePerPound);

                    // Add the price per pound in parentheses
                    element.textContent = text + ' (' + formattedPricePerPound + ')';

                    // Mark as processed to avoid duplicate processing
                    element.dataset.processed = 'true';
                }
            }
        });
    }

    function observeChanges() {
        // Create a MutationObserver to handle dynamically loaded content
        const observer = new MutationObserver(function(mutations) {
            let shouldProcess = false;

            mutations.forEach(function(mutation) {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    shouldProcess = true;
                }
            });

            if (shouldProcess) {
                // Use setTimeout to allow DOM to settle
                setTimeout(addPricePerPound, 100);
            }
        });

        // Start observing
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    // Initial processing when page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(addPricePerPound, 500);
            observeChanges();
        });
    } else {
        setTimeout(addPricePerPound, 500);
        observeChanges();
    }

    // Also run when navigating (for SPAs)
    let currentUrl = location.href;
    new MutationObserver(() => {
        if (location.href !== currentUrl) {
            currentUrl = location.href;
            setTimeout(addPricePerPound, 1000);
        }
    }).observe(document, { subtree: true, childList: true });

})();