Amazon Price Variation (Fork)

Embeds CamelCamelCamel price chart in Amazon product pages

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

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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        Amazon Price Variation (Fork)
// @namespace   dsr-price-variation-camel
// @description Embeds CamelCamelCamel price chart in Amazon product pages
// @include     https://amazon.*/*
// @include     https://www.amazon.*/*
// @include     https://smile.amazon.*/*
// @version     20250708
// @grant       none
// @run-at      document-idle
// ==/UserScript==

(() => {
  'use strict';
  const width = 500, height = 200, duration = '1y', chart = 'amazon-new';

  /**
   * Brief: Determine country code from hostname
   */
  const getCountry = () => {
    const parts = location.hostname.split('.');
    let tld = parts.pop();
    return tld === 'com' ? 'us' : tld;
  };

  /**
   * Brief: Create and insert chart element under availability
   */
  const insertChart = asin => {
    const country = getCountry();
    const imgUrl = `${location.protocol}//charts.camelcamelcamel.com/${country}/${asin}/${chart}.png?force=1&zero=0&w=${width}&h=${height}&desired=false&legend=1&ilt=1&tp=${duration}&fo=0`;
    const link = document.createElement('a');
    link.href = `${location.protocol}//${country}.camelcamelcamel.com/product/${asin}`;
    link.target = '_blank';

    const img = document.createElement('img');
    img.src = imgUrl;
    img.alt = 'Price history chart';
    img.width = width;
    img.height = height;
    link.appendChild(img);

    const container = document.querySelector('#titleSection');
    if (container) {
      const wrapper = document.createElement('div');
      wrapper.id = 'camelcamelcamel';
      wrapper.style.margin = '0';
      wrapper.appendChild(link);
      container.appendChild(wrapper);
    }
  };

  // get ASIN from hidden input or URL
  const asinInput = document.querySelector('input[name="ASIN"]');
  const asin = asinInput
    ? asinInput.value.trim()
    : location.pathname.match(/\/dp\/([A-Z0-9]{10})/)?.[1];

  if (asin) {
    console.info('[!] Amazon Price Variation: ASIN found', asin);
    insertChart(asin);
  }
})();