lazada-MR2RS

Malaysian Lazada price in NPR

Устаревшая версия за 21.07.2017. Перейдите к последней версии.

// ==UserScript==
// @name         lazada-MR2RS
// @namespace    http://www.lazada.com.my/
// @version      0.4
// @description  Malaysian Lazada price in NPR
// @author       himalay
// @match        http://www.lazada.com.my/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const sNumberWithCommas = x => {
        x = x.split('.');
        x[0] = x[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
        return x.join('.');
    };

    fetch('https://api.eremit.com.my/EremitService.svc/GetExchangeRates')
        .then(res => res.json())
        .then(json => {
        const exchangeRateNp = json.ExchangeRatesList[5].ExchangeRate;
        console.log('Exchange rate for Np: ', exchangeRateNp);
        [...document.querySelectorAll('#special_currency_box')].map(e => e.parentElement.removeChild(e));
        [...document.querySelectorAll('.c-product-card__price-final,.c-product-card__old-price,#price_box,#special_price_box,.c-product-item__price')].map(p => {
            p.innerHTML = `Rs. ${sNumberWithCommas(((+p.textContent.replace(/[^\d.]/g, '')) * exchangeRateNp).toFixed(2))}`;
        });
    });
})();