Walmart Persistent In-Store Filter

Automatically applies the in-store filter to all search results

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Walmart Persistent In-Store Filter
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically applies the in-store filter to all search results
// @author       Rim
// @tag          shopping
// @license      GNU GPLv3
// @match        https://*.walmart.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function applyFilter() {
        const url = new URL(window.location.href);

        // Check if we're on a search page and don't already have the facet
        if (url.pathname === '/search' && url.searchParams.has('q')) {
            const currentFacet = url.searchParams.get('facet');
            const targetFacet = 'fulfillment_method_in_store:In-store';

            // Only add if the facet isn't already present
            if (currentFacet !== targetFacet) {
                url.searchParams.set('facet', targetFacet);
                window.location.replace(url.href);
            }
        }
    }

    // Run on initial load
    applyFilter();

    // Watch for URL changes (for single-page app navigation)
    let lastUrl = location.href;
    new MutationObserver(() => {
        const currentUrl = location.href;
        if (currentUrl !== lastUrl) {
            lastUrl = currentUrl;
            applyFilter();
        }
    }).observe(document, { subtree: true, childList: true });
})();