Walgreens to Walmart/Amazon Search

Creates buttons that open new tabs on Walmart and Amazon, and searches for the product using the extracted title from Walgreens product page

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Walgreens to Walmart/Amazon Search
// @namespace    http://tampermonkey.net/
// @version      3
// @description  Creates buttons that open new tabs on Walmart and Amazon, and searches for the product using the extracted title from Walgreens product page
// @author       Your Name
// @match        https://www.walgreens.com/store/*
// @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 walmartSearchUrl = 'https://www.walmart.com/search?q=' + encodeURIComponent(productTitle) + '&facet=fulfillment_method_in_store%3AIn-store';

    // Create the Amazon search URL with the product title
    var amazonSearchUrl = 'https://www.amazon.com/s?k=' + encodeURIComponent(productTitle);

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

    // Create the Amazon button element
    var amazonButton = document.createElement('a');
    amazonButton.innerHTML = 'Amazon';
    amazonButton.href = amazonSearchUrl;
    amazonButton.target = '_blank';

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

    // Style the Walmart button with CSS
    var styleWalmartButton = function(button) {
        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';
        });
    };

    // Style the Amazon button with CSS
    var styleAmazonButton = function(button) {
        button.style.backgroundColor = '#C45500';
        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 = '#F3A847';
        });

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

    styleWalmartButton(walmartButton);
    styleAmazonButton(amazonButton);

})();