lazada-MR2RS

Malaysian Lazada price in NPR

Versión del día 21/07/2017. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         lazada-MR2RS
// @namespace    http://www.lazada.com.my/
// @version      0.1
// @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 is: ', exchangeRateNp);
    [...document.querySelectorAll('.c-product-card__price-final,.c-product-card__old-price')].map(p => {
      p.innerHTML = `Rs. ${sNumberWithCommas(((+p.textContent.replace(/[^\d.]/g, '')) * exchangeRateNp).toFixed(2))}`;
    });
  });
})();