Skip to content

Instantly share code, notes, and snippets.

@vsviridov
Created December 21, 2014 01:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsviridov/37eba161d64db662f793 to your computer and use it in GitHub Desktop.
Save vsviridov/37eba161d64db662f793 to your computer and use it in GitHub Desktop.
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