Skip to content

Instantly share code, notes, and snippets.

@andrewiankidd
Created June 22, 2018 20:15
Show Gist options
  • Save andrewiankidd/c6dededf8c8856314555adbb1635bed3 to your computer and use it in GitHub Desktop.
Save andrewiankidd/c6dededf8c8856314555adbb1635bed3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TaoBao Currency Converter (GBP)
// @namespace http://andrewiankidd.co.uk/
// @version 0.1
// @description taobao inline currency converter
// @author You
// @match *item.taobao.com/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
$(document).ready(function(){
let curCont = $('#J_PromoPrice .tb-rmb');
let priceCont = $('#J_PromoPrice .tb-rmb-num');
console.clear();
logger("getting price");
let price = priceCont.text().match(/\d+/);
logger("getting exchange rate");
$.ajax({
url: 'https://free.currencyconverterapi.com/api/v5/convert?q=CNY_GBP&compact=ultra',
type: 'GET',
async: false,
success: function(result) {
let exchangeRate = result;
console.log(exchangeRate);
logger("getting newprice");
let newPrice = (exchangeRate.CNY_GBP * price).toFixed(2);
logger("price: " + price + ", exchangeRate: " + exchangeRate.CNY_GBP + ", newPrice: " + newPrice);
curCont.text('£');
priceCont.text(newPrice);
}
});
});
function logger(text){
console.log('[TaoBao Currency Converter] ' + text);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment