// ==UserScript== // @name Nuuvem Enhancer // @namespace sharkiller_nuuvem_enhancer // @author sharkiller // @version 1.1 // @description Currency converter to USD and some translations // @homepage https://greasyfork.org/scripts/8939-nuuvem-enhancer // @match http://www.nuuvem.com/* // @match https://secure.nuuvem.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant GM_addStyle // @copyright 2015 // @downloadURL none // ==/UserScript== var BRL2USD = GM_getValue('BRL2USD', false); // Currency conversion last update var BRL2USD_LU = GM_getValue('BRL2USD_LU', false); // Older than 1 day var older = new Date().getTime() - (1 * 24 * 60 * 60 * 1000); if(!BRL2USD || !BRL2USD_LU || older > BRL2USD_LU){ console.log('%c[Nuuvem Enhancer] Updating currency converter ', 'background: #222; color: #ffffff;'); BRL2USD = 3.1266; GM_xmlhttpRequest({ method: "GET", url: "https://www.google.com/finance?q=USDBRL", synchronous: true, onload: function(response) { var re = //; var m = re.exec(response.response) if(!isNaN(m[1])){ console.log('%c[Nuuvem Enhancer] Currency converter updated to: '+m[1], 'background: #222; color: #ffffff;'); GM_setValue('BRL2USD', m[1]); GM_setValue('BRL2USD_LU', new Date().getTime()); } } }); } console.log('%c[Nuuvem Enhancer] Using currency converter: '+BRL2USD, 'background: #222; color: #ffffff;'); function updatePrices(){ $('.price.price-conversion').each(function() { if($( this ).find('.currency-symbol').text() != 'U$D'){ var price = $( this ).find('.integer').text()+$( this ).find('.decimal').text().replace(',','.'); price = (parseFloat(price / BRL2USD).toFixed(2)+"").split('.'); $( this ).find('.integer').text(price[0]); $( this ).find('.decimal').text(','+price[1]); $( this ).find('.currency-symbol').text('U$D'); } }); $("#product [data-load-url]").each(function() { var t = $(this), e = t.data("load-url"); e && (t.addClass("loading"), $.ajax({ url: e, dataType: "jsonp json", success: function(e) { var dataprice = $(e.info).data('price'); var price = dataprice.iv+'.'+dataprice.c; price = (parseFloat(price / BRL2USD).toFixed(2)+"").split('.'); var html = $('
'+e.info+'
'); html.find('.integer').text(price[0]); html.find('.decimal').text(','+price[1]); html.find('.currency-symbol').text('U$D'); t.html(html.html()).removeClass("loading"), appNuuvem.com.countdown.init() } })); }); }; var update = false; $( 'html' ).bind('DOMNodeInserted', function() { if($(this).hasClass('nprogress-busy')){ if(!update){ update = true; console.log('Busy and update changed to true'); } }else{ if(update){ update = false; updatePrices(); console.log('Not busy and update changed to false'); } } }); $( document ).ready(function() { updatePrices(); });