Amazon CamelCamelCamel + Keepa Price Charts

Add a CamelCamelCamel and Keepa price charts to Amazon product pages.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name            Amazon CamelCamelCamel + Keepa Price Charts
// @version         1.0.8
// @description     Add a CamelCamelCamel and Keepa price charts to Amazon product pages.
// @author          miki.it
// @namespace       null
// @homepage        https://github.com/mikispag/userscripts/
// @include         https://www.amazon.*/*
// @include         https://smile.amazon.*/*
// @run-at          document-end
// ==/UserScript==

function getASIN() {
    var asinElement = document.getElementById("ASIN") || document.evaluate("//@data-asin", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    if (!asinElement) {
        throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to find ASIN!");
    }
    return asinElement.value;
}

window.addEventListener("load", function() {
    var tld = document.domain.split(".").pop();
    var country = tld;
    if (tld == "com") {
        country = "us";
    }

    var asin = getASIN();
    if (!asin) {
        throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to get ASIN!");
    }

    var parentElement = document.getElementById("unifiedPrice_feature_div") || document.getElementById("MediaMatrix");
    if (!parentElement) {
        throw new Error("Amazon CamelCamelCamel + Keepa Price Charts: unable to get parent element!");
    }

    var camelChartContainer = document.createElement("div");
    var camelLink = document.createElement("a");
    camelLink.target = "_blank";
    camelLink.href = "https://" + country + ".camelcamelcamel.com/product/" + asin;
    var camelChart = new Image(500, 400);
    camelChart.src = "https://charts.camelcamelcamel.com/" + country + "/" + asin + "/amazon-new-used.png?force=1&zero=0&w=500&h=400&desired=false&legend=1&ilt=1&tp=all&fo=0";
    camelLink.appendChild(camelChart);
    camelChartContainer.appendChild(camelLink);

    var keepaChartContainer = document.createElement("div");
    var keepaLink = document.createElement("a");
    keepaLink.target = "_blank";
    keepaLink.href = "https://keepa.com/#!product/8-" + asin;
    var keepaChart = new Image(500, 200);
    keepaChart.src = "https://graph.keepa.com/pricehistory.png?used=1&asin=" + asin + "&domain=" + tld;
    keepaLink.appendChild(keepaChart);
    keepaChartContainer.appendChild(keepaLink);

    var chartsContainer = document.createElement("div");
    chartsContainer.appendChild(camelChartContainer);
    chartsContainer.appendChild(keepaChartContainer);
    parentElement.appendChild(chartsContainer);
}, false);