Amazon Prime Now Checker

Adds a button to open Amazon items in Amazon Prime Now, when available.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Amazon Prime Now Checker
// @description  Adds a button to open Amazon items in Amazon Prime Now, when available.
// @namespace    Arithmomaniac_Tampermonkey
// @version      0.1
// @author       Arithmomaniac
// @include      /^https?://(www|smile)\.amazon\.com/.*/[A-Z\d]{10}//
// @run-at       document-ready
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    var primeIcon = document.querySelector("#priceBadging_feature_div .a-icon-prime");
    if (primeIcon) //available on prime
    {
        var span = document.createElement("span");
        span.className = "prime-now-link";
        span.innerHtml = "<i>Checking Prime Now...</i>";
        primeIcon.parentElement.appendChild(span);

        var primeUrl = "https://primenow.amazon.com" + window.location.pathname;
        GM_xmlhttpRequest({
            url: primeUrl,
            method: "GET",
            onload: function(response) {
                //if item exists and is available in PrimeNow
                if (response.status === 200 && response.responseText.indexOf('<span class="a-color-price a-text-bold">Currently Unavailable.</span>') === -1)
                {
                    
                    span.innerHTML = `<a target="_blank" href="${primeUrl}">` +
                        `<img height="16" src="https://images-na.ssl-images-amazon.com/images/I/31uhU1SAhgL.png"></img>` +
                        `</a>`;
                }
                else
                {
                    span.remove();
                }
            }
    })
    }
})();