Nuuvem Enhancer

Currency converter to USD and some translations

目前為 2015-07-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
// ==/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 = /<meta itemprop="price"[\s]+content="([\d.]+)" \/>/;
            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 = $('<div>'+e.info+'</div>');
                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();
    
});