Walmart Persistent In-Store Filter

Automatically applies the in-store filter to all search results

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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 });
})();