Amazon Product Price Loader (Optimized)

Load Amazon product pages and display price in a tooltip

Auteur
Hikary
Nombre d'installations quotidiennes
0
Nombre d'installations
11
Évaluations
0 0 0
Version
1.0
Créer
2024-09-08
Mis à jour
2024-09-08
Licence
MIT https://opensource.org/licenses/MIT
S'applique à

### Additional Info: Detailed Description & Instructions for the Script

#### Overview:
This Tampermonkey userscript, **Amazon Product Price Loader (Optimized)**, enhances the Amazon Seller Central experience by displaying product prices in a tooltip when users hover over product links. The script optimizes page loading and price fetching, providing faster performance and improved user interaction.

#### Key Features:
1. **Tooltip Creation**: A floating tooltip is created and styled using the `GM_addStyle` function. The tooltip remains hidden until triggered by a hover event.

2. **Price Extraction**: The script uses DOM parsing to extract product prices from the HTML of the Amazon product page. It uses a set of common CSS selectors for price elements, making it flexible across different Amazon regions and product types.

3. **Caching Mechanism**:
- Prices are cached after being fetched from the page. This avoids redundant network requests for the same product, making subsequent interactions faster.
- The `priceCache` object stores prices and checks whether a product's price has already been cached before initiating a new request.

4. **Debounced Mouseover**:
- The script adds a debounce function for mouseover events, limiting the frequency of price-fetching requests and improving performance when users hover over multiple products rapidly.
- The tooltip is shown after a brief delay (300ms) to avoid unnecessary requests for quick, transient mouse movements.

5. **Efficient Price Loading**: The `GM_xmlhttpRequest` function is used to asynchronously fetch the HTML of the product page, extract the price, and display it in the tooltip. The request is non-blocking, so the page remains responsive.

#### Instructions:
1. **Install Tampermonkey**:
- This script is designed to run using the [Tampermonkey](https://www.tampermonkey.net/) browser extension. Make sure to install it in your preferred browser (e.g., Chrome, Firefox).

2. **Script Installation**:
- Copy the entire userscript into a new Tampermonkey script. To do this, open Tampermonkey and create a new script. Replace the default template with this script.

3. **Supported Pages**:
- This script works on the following Amazon Seller Central domains: `.com`, `.co.uk`, `.de`, `.fr`, `.it`, `.es`, `.ca`, `.mx`, `.br`, `.co.jp`, `.in`, and `.com.au`.

4. **Using the Script**:
- After installation, when you visit any of the supported Amazon Seller Central product pages, the script will be active.
- Hover over any product link (with `/dp/` or `/product/` in the URL) to see the price. The tooltip will appear near the cursor with the price information.
- The script pre-fetches prices and caches them, so repeated hovering over the same product will display the price instantly.

#### Customization:
- **Adjust Debounce Time**: The delay for showing the tooltip can be modified in the `debounce` function. Increase or decrease the `200ms` debounce time based on the desired responsiveness.

- **Adjust Tooltip Style**: The tooltip's appearance (e.g., background color, font size, padding) can be customized by modifying the `GM_addStyle` block.

- **Error Handling**: If the price cannot be found or the page fails to load, the tooltip displays appropriate messages (`Price not found` or `Error loading price`).

#### Limitations:
- **Amazon UI Changes**: The price extraction relies on specific CSS selectors. If Amazon updates its page structure, the selectors may need to be updated for the script to continue working effectively.

- **Network Latency**: The speed of price loading depends on network conditions and Amazon's server response time.

This optimized script should now fetch and display product prices significantly faster, with improved handling of multiple product links.