Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Woolworths Filter Script
- // @namespace http://tampermonkey.net/
- // @version 1.1
- // @description Automatically add &filter=SoldBy(Woolworths) to URLs on Woolworths' website
- // @author Kriptanik
- // @match https://www.woolworths.com.au/*
- // @icon https://www.woolworths.com.au/favicon.ico
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Check if the current page is a catalogue page
- if (window.location.href.startsWith("https://www.woolworths.com.au/shop/catalogue")) {
- return; // Exit the script if on a catalogue page
- }
- const addFilterToURL = () => {
- let url = new URL(window.location.href);
- // Check if we're in the /shop/ section and if the filter is missing
- if (url.pathname.startsWith('/shop/') && !url.searchParams.has('filter')) {
- // Manually construct the desired URL with the correct parameter format
- let query = url.searchParams.toString();
- query += (query ? '&' : '') + 'filter=SoldBy(Woolworths)';
- let newUrl = `${url.origin}${url.pathname}?${query}${url.hash}`;
- // Redirect to the correctly formatted URL
- window.location.replace(newUrl);
- }
- };
- // Run the function initially
- addFilterToURL();
- // Use a MutationObserver to detect changes in the <body> tag (common in SPAs)
- const observer = new MutationObserver(() => {
- addFilterToURL();
- });
- // Observe the entire document for changes
- observer.observe(document.body, { childList: true, subtree: true });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement