Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GreaseMonkey script to see the BTC price before checkout.
// ==UserScript==
// @name NewEgg Price in Bitcoin
// @namespace gist.github.com/vsviridov/
// @description Display the grand total of your shopping cart in BTC
// @include *//secure.newegg.ca/Shopping/ShoppingCart.aspx*
// @include *//secure.newegg.com/Shopping/ShoppingCart.aspx*
// @version 1
// @grant none
// ==/UserScript==
var targetCurrency = "USD";
switch(location.host.split('.').pop())
{
case "com":
break;
case "ca":
targetCurrency = "CAD";
break;
default:
console.error("Cannot determine currency from the domain");
return;
}
var widget = jQuery('.gm-btc-price-widget .btc-price');
if(widget.length === 0)
{
widget = jQuery('<tr class=".gm-btc-price-widget"><td class="discount-code"><h3>BTC Widget</h3>Price in BTC: <span class="btc-price"></span></td></tr>')
.insertAfter('.foot tbody tr:nth-child(3)')
.find('.btc-price');
}
var total = parseFloat(utag_data.cart_grand_total);
function updateRate()
{
jQuery.get("https://bitpay.com/api/rates", { json: true })
.then(function(rates)
{
var rate = rates.filter(function(rate) { return rate.code === targetCurrency; }).pop().rate;
var price = (total / rate).toFixed(8);
widget.text(price);
});
}
updateRate();
setInterval(updateRate, 65 * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment