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
// @downloadURL https://openuserjs.org/install/RamiEjailat/CamelCamelCamel_Price_History_and_Sales_Rank.user.js
// @version     20230319
// @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 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";
  }

  if (undefined == document.getElementsByName("ASIN")[0]) return;
  var asin = document.getElementsByName("ASIN")[0].value.trim();

  var duration = "3m"; //"all", "1y", "6m", "1m"

  var width = document.body.clientWidth;
  var height = 400;

  var price = '<a target="blank" href="https://' + country + '.camelcamelcamel.com/product/' + asin + '"><img src="https://charts.camelcamelcamel.com/' + country + '/' + asin + '/amazon-new-used.png?force=1&zero=0&w=' + width + '&h=' + height + '&desired=false&legend=1&ilt=1&tp=' + duration + '&fo=0&lang=en" /></a>';
  var newDiv = '<div id="camelcamelcamel" style="margin: 10px; clear: both;">' + price + '</div>';

  var newEl = document.createElement("div");
  newEl.innerHTML = newDiv;
  document.getElementById("ppd").after(newEl);

  // document.getElementById("ppd").style.display = "block";
  // document.getElementById("ppd").innerHTML += newDiv;
})();