// ==UserScript==
// @name Amazon Enable Non-US Purchase
// @namespace netherman.amazonpurchase
// @description Enables purchasing downloadables from Amazon.com that are for US only even if outside US and without US billing address.
// @include https://www.amazon.com/gp/swvgdtt/order/handle-order.html*
// ==/UserScript==
function FindTag(elementTag)
{
var tags = document.getElementsByTagName(elementTag);
return tags;
}
function GetAttributeMatch(list, attribute, attValue)
{
for (var i = 0; i= 0)
return list[i];
}
return null;
}
function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}
function createInput(elementValue, elementName)
{
var tempElement = document.createElement('input');
tempElement.setAttribute('type', 'hidden');
tempElement.setAttribute('value', elementValue);
tempElement.setAttribute('name', elementName);
return tempElement
}
var imgs = FindTag('img');
var img = GetAttributeMatch(imgs, 'src', 'button_no_order._V192261387_.gif');
//alert(img.getAttribute('src'));
var formCreated = document.createElement('form');
formCreated.setAttribute('method', 'post');
formCreated.setAttribute('action', '/gp/swvgdtt/order/handle-order.html');
formCreated.setAttribute('name', 'makePurchase');
formCreated.setAttribute('style', 'margin: 0px;');
formCreated.setAttribute('onsubmit', "document.getElementById('dsvOrderConfirmationLoadingImageDiv').style.display = 'block'; document.getElementById('dsvPurchaseConfirmationButton').style.display ='none'");
formCreated.setAttribute('id', 'dsv-order-confirmation-page-place-order-button');
//
var elementValue = getQuerystring('asin');
var elementName = "asin";
var tempElement = createInput(elementValue, elementName);
formCreated.appendChild(tempElement);
//
var elementValue = "dc";
var elementName = "v";
var tempElement = createInput(elementValue, elementName);
formCreated.appendChild(tempElement);
//
var elementValue = unsafeWindow.ue_sid;
var elementName = "sid";
var tempElement = createInput(elementValue, elementName);
formCreated.appendChild(tempElement);
//
var input = FindTag('input');
input = GetAttributeMatch(input, 'name', 'pid');
var elementValue = input.getAttribute('value');
var elementName = "pid";
var tempElement = createInput(elementValue, elementName);
formCreated.appendChild(tempElement);
//// [IMG]https://images-na.ssl-images-amazon.com/images/G/01/ui/loadIndicators/loading-small._V192238939_.gif[/IMG]
//
var tempDiv = document.createElement('div');
tempDiv.setAttribute('style', 'display: none;');
tempDiv.setAttribute('id', 'dsvOrderConfirmationLoadingImageDiv');
var tempElement = document.createElement('img');
tempDiv.appendChild(tempElement);
tempElement.setAttribute('border', '0');
tempElement.setAttribute('width', '14');
tempElement.setAttribute('height', '14');
tempElement.setAttribute('src', 'https://images-na.ssl-images-amazon.com/images/G/01/ui/loadIndicators/loading-small._V192238939_.gif');
formCreated.appendChild(tempDiv);
//
var tempElement = document.createElement('input');
tempElement.setAttribute('border', '0');
tempElement.setAttribute('width', '170');
tempElement.setAttribute('type', 'image');
tempElement.setAttribute('height', '27');
tempElement.setAttribute('id', 'dsvPurchaseConfirmationButton');
tempElement.setAttribute('name', 'BuyAndDownload');
tempElement.setAttribute('alt', 'Buy and Download');
tempElement.setAttribute('src', 'https://images-na.ssl-images-amazon.com/images/G/01/digital/downloads/buttons/button_proceed_purchase_md_pri._V169498703_.gif');
formCreated.appendChild(tempElement);
img.parentNode.insertBefore(formCreated, img);
//maybe remove this image
//[IMG]https://images-na.ssl-images-amazon.com/images/G/01/digital/bowser/buttons/button_no_order._V192261387_.gif[/IMG]
//img.parentNode.removeChild(img);