Walgreens to Walmart Search

Creates a button that opens a new tab on Walmart and searches for the product using the extracted title from Walgreens product page

目前为 2023-05-02 提交的版本。查看 最新版本

// ==UserScript==
// @name         Walgreens to Walmart Search
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Creates a button that opens a new tab on Walmart and searches for the product using the extracted title from Walgreens product page
// @author       Your Name
// @match        https://www.walgreens.com/store/c/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Get the product title from the page
    var productTitle = document.querySelector('title').innerText.replace(' | Walgreens', '');

    // Create the Walmart search URL with the product title
    var searchUrl = 'https://www.walmart.com/search?q=' + encodeURIComponent(productTitle) + '&facet=fulfillment_method_in_store%3AIn-store';

    // Create the button element
    var button = document.createElement('a');
    button.innerHTML = 'Walmart';
    button.href = searchUrl;
    button.target = '_blank';

    // Add the button after the product name
    var productName = document.querySelector('#productName');
    productName.parentNode.insertBefore(button, productName.nextSibling);

    // Style the button with CSS
    button.style.backgroundColor = '#0071DC';
    button.style.color = 'white';
    button.style.padding = '5px 20px';
    button.style.margin = '5px 10px 10px 0';
    button.style.borderRadius = '5px';
    button.style.border = 'none';
    button.style.cursor = 'pointer';
    button.style.transition = 'background-color 0.3s';

    button.addEventListener('mouseover', () => {
        button.style.backgroundColor = '#004F9A';
    });

    button.addEventListener('mouseout', () => {
        button.style.backgroundColor = '#0071DC';
    });

})();