// ==UserScript== // @name Nuuvem Enhancer // @namespace sharkiller_nuuvem_enhancer // @author sharkiller // @version 0.3 // @description Currency converter to USD and some translations // @homepage https://greasyfork.org/scripts/8939-nuuvem-enhancer // @match http://www.nuuvem.com.br/* // @match https://secure.nuuvem.com.br/* // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant GM_log // @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){ GM_log('Updating currency converter'); 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])){ GM_log('Currency converter updated to '+m[1]); GM_setValue('BRL2USD', m[1]); GM_setValue('BRL2USD_LU', new Date().getTime()); } } }); } GM_log('Using currency converter '+BRL2USD); GM_addStyle(` .content1 .blockcontent #info div.addcartinfo a, .content1 .blockcontent #info div.ownedinfo a, .content1 .blockcontent #info div.freeinfo a, .content1 .blockcontent #info div.addcartinfo div.priceline div.price, .content1 .blockcontent #info div.addcartinfo div.priceline div.percent, .content1 .blockcontent #info div.addcartinfo div.priceline div.timer { background-image: url(http://i.imgur.com/KwYNL4m.png); } #promo .item .left strong, #promo .item .left b, #promo .item .left a { background-image: url(http://i.imgur.com/jEiwppt.png); } #destaques div.display div.item div.info div.right strong, #destaques div.display div.item div.info div.right b, #destaques div.display div.item div.info div.right a { background-image: url(http://i.imgur.com/SC9hrEh.png); } table tfoot tr td.odd.right{ line-height: 20px; } `); function addScript(fnc) { var script = document.createElement("script"); script.textContent = fnc.toString().replace(/_BRL2USD_/g, BRL2USD); document.head.appendChild(script); } function loadAddCartInfo(id) { if (NUUVEM_APP_DATA.loaded != true) { setTimeout(function () { loadAddCartInfo(id); }, 500); return; } $.ajax({ url: NUUVEM_APP_DATA.cocoon + "/product/addcartinfo/" + id, dataType: "jsonp", type: "GET", cache: true, jsonpCallback: "callbackCocoonProductAddCartInfo", data: { ajax: true, }, success: function(data) { $("#addcartloading").hide(); if (data.success) { var re = /(timerValorProduto\("[\d-T:]+"\);)/; var m; var str = ''; // offer time left if ((m = re.exec(data.product.html)) !== null) { if (m.index === re.lastIndex) { re.lastIndex++; } str = ''; } var productinfo = $('
'+data.product.html+'
'); price = productinfo.find(".price:first").text().replace(',','.'); productinfo.find(".price:first").text(parseFloat(price / _BRL2USD_).toFixed(2)); oldprice = productinfo.find(".oldprice:first").text().replace('de R$ ','').replace(',','.'); productinfo.find(".oldprice:first").text('before $'+parseFloat(oldprice / _BRL2USD_).toFixed(2)+ " U$D"); $(".blockcontent #info").append(productinfo.html()+str); } else { alert(data.message); } } }); } function loadCartContents() { if (NUUVEM_APP_DATA.loaded != true) { setTimeout(function () { loadCartContents(); }, 500); return; } $.ajax({ url: NUUVEM_APP_DATA.cocoon + "/cart/contents/", dataType: "jsonp", type: "GET", data: { ajax: true }, success: function(data) { if (data.success) { var carthtml = $('
'+data.html+'
'); console.log(carthtml.html()); carthtml.find('tfoot tr:contains(TOTAL) td.odd.right').each(function(){ var price = $( this ).find('b:first').text().replace(',','.'); price = parseFloat(price / _BRL2USD_).toFixed(2); $( this ).append('
U$D '+price+''); console.log('holaaa'); }); carthtml.find('tbody td.odd.right:has(b)').each(function(){ var price = $( this ).find('b:first').text().replace(',','.'); price = parseFloat(price / _BRL2USD_).toFixed(2); $( this ).html($( this ).html().trim()+'
U$D '+price+''); }); $("#cartcontents").html(carthtml.html()); exclusivePromoGateway = data.exclusivePromoGateway; afterLoadCartContents(); if (data.cupomInvalido) { showMessage("O cupom informado não existe ou não está mais disponível."); } if (data.fullDiscount) { $(".fulldiscount").removeClass("hidden"); $(".paymentchoser").addClass("hidden"); } else { $(".fulldiscount").addClass("hidden"); $(".paymentchoser").removeClass("hidden"); } adjustFooterTop(); var right = $('#cartpage div.blockholder.right'); right.scrollToFixed({ marginTop: 15, limit: $('#footer').offset().top - right.outerHeight() - 25 }); } else { showMessage(data.message, false); } } }); } // Override async html functions addScript(loadAddCartInfo); addScript(loadCartContents); $( document ).ready(function() { // new price / current price / old price $('div.content3 div.left div.container div ul li strong, '+ 'div.content3 div.left div.container div ul li b, '+ '.pageholder .games .list ul li .purchase.normal strong').each(function() { var price = $( this ).text().replace('R$','').replace(',','.'); price = (parseFloat(price / BRL2USD).toFixed(2)+"").split('.'); var pricestr = 'U$D '+price[0]+'.'+price[1]+''; $( this ).html(pricestr); }); // important $('#destaques div.display div.item div.info div.right strong:not(:has(span.original))').each(function() { var price = $( this ).text().replace('R$','').replace(',','.'); price = (parseFloat(price / BRL2USD).toFixed(2)+"").split('.'); var pricestr = price[0]+'.'+price[1]+''; $( this ).html(pricestr); }); // promo / important with discount $('#promo .item .left strong,'+ '#destaques div.display div.item div.info div.right strong:has(span.original)').each(function() { var priceOrig = $( this ).find('.original').text(); var price = $( this ).text().replace(priceOrig,'').replace(',','.'); priceOrig = parseFloat(priceOrig.replace(',','.') / BRL2USD).toFixed(2); price = (parseFloat(price / BRL2USD).toFixed(2)+"").split('.'); var pricestr = ''+priceOrig+''+price[0]+'.'+price[1]+''; $( this ).html(pricestr); }); // Simple translations $('.textbutton.purchase:not(:has(>span)),.textbutton.purchase span').text('Buy'); $('.textbutton.prevenda:not(:has(>span)),.textbutton.prevenda span').text('Pre-order'); $('.textbutton.info').text('See information'); $('.textbutton.empty span').text('Empty'); $('.textbutton.shop span').text('Continue shopping'); $('.pay.paymentchoser .textbutton').text('Checkout order'); $('#infonota .infocontent li').each(function(){ var text = $(this).text(); switch(text){ case 'Este conteúdo utiliza Steamworks e requer o aplicativo STEAM para ativação, download e instalação.': $(this).html('This game uses Steamworks and requires a STEAM account for activation, download and installation.'); break; case 'STEAMPLAY: Este conteúdo oferece suporte ao Steamplay': $(this).html('STEAMPLAY: This game supports Steamplay'); break; } }); });