RamiEjailat / CamelCamelCamel Price History and Sales Rank

// ==UserScript==
// @name        CamelCamelCamel Price History and Sales Rank
// @author      Rami S Ejailat
// @description Embeds CamelCamelCamel charts in Amazon product pages
// @copyright   RamiEjailat (https://openuserjs.org/users/RamiEjailat)
// @license     MIT
// @updateURL   https://openuserjs.org/meta/RamiEjailat/CamelCamelCamel_Price_History_and_Sales_Rank.meta.js
// @version     20211126
// @match       *://*.amazon.com/dp/*
// @match       *://*.amazon.com/*/dp/*
// @match       *://*.amazon.com/gp/product/*
// @match       *://*.amazon.com/*/ASIN/*
// @exclude     *://aws.amazon.*/*
// @icon        https://www.amazon.com/favicon.ico
// @run-at      document-end
// ==/UserScript==

(function () {
  var width = document.body.clientWidth / 2 - 50;
  var height = 275;
  var chart = "amazon-new"; //"amazon", "new", "used", "new-used", "amazon-new-used"
  var duration = "3m"; //"all", "1y", "6m", "1m"

  var arr = document.domain.split(".");
  var dom = document.domain.toLowerCase();
  var country = dom.substring(dom.search("amazon") + 7, dom.length);
  switch (country) {
    case "com":
      country = "us";
      break;
    case "ca":
      country = "ca";
      break;
    case "cn":
      country = "cn";
      break;
    case "de":
      country = "de";
      break;
    case "es":
      country = "es";
      break;
    case "fr":
      country = "fr";
      break;
    case "it":
      country = "it";
      break;
    case "co.jp":
      country = "jp";
      break;
    case "co.uk":
      country = "uk";
      break;
    default:
      country = "us";
      break;
  }

  if (country == "com") {
    country = "us";
  }

  var asin = document.getElementsByName("ASIN")[0].value.trim();
  var price = '<a target="blank" href="https://' + country + '.camelcamelcamel.com/product/' + asin + '"><img src="https://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&lang=en" /></a>';
  var rank = '<a target="blank" href="https://' + country + '.camelcamelcamel.com/product/' + asin + '?active=sales_rank"><img src="https://charts.camelcamelcamel.com/' + country + '/' + asin + '/sales-rank.png?force=1&zero=0&w=' + width + '&h=' + height + '&legend=1&ilt=1&tp=' + duration + '&fo=0&lang=en" /></a>';
  var div = '<div id="camelcamelcamel" style="margin: 10px; clear: both;">' + price + rank + '</div>';
  console.log("■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ " + div);
  document.getElementById("hover-zoom-end").style.display = "block";
  document.getElementById("hover-zoom-end").innerHTML += div;
})();