USDPrices

USD price for catalog.onliner.by

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name USDPrices
// @include     http://catalog.onliner.by/*
// @version 0.2
// @grant  none
// @description USD price for catalog.onliner.by
// @namespace https://greasyfork.org/users/11143
// ==/UserScript==

function convertPricesToUSD() {
	var $ = unsafeWindow.jQuery;
	var selector = [".b-offers-desc__info-price > .b-offers-desc__info-sub", ".b-offers-desc__info-price > .b-offers-desc__info-sub > a", ".price > .js-currency-primary"];
	$.ajax({
		dataType: "json",
		url: "http://catalog.onliner.by/sdapi/kurs/api/bestrate?currency=USD&type=nbrb"
	}).then(function (usd) {
		var USDExchangeRate = +usd.amount.replace(/\s+/g, "");
		$.each($(".pprice, .product-aside__price > .product-aside__price--primary"), function () {
			var node = $(this).hasClass("pprice_byr") ? this : this.firstChild;
			var prices = node.textContent.replace(/[\sруб.]/g, "").split("–");
			if (!$(this).hasClass("pprice_byr")) {
				$(node).after("<br /><span style=\"color:#999;font-size:10px;font-weight:normal;\">" + node.textContent + "</span>");
			} else {
				$(node).after(node.textContent + "<br />");
			}
			node.textContent = prices.map(function (value) { return "$" + Math.ceil((value/USDExchangeRate)*2)/2; }).join(" - ");
		});

		$.each($(selector.join(", ")), function () {
			var node = this.firstChild;
			if (!node.textContent.replace(/\s/g, "")) {
				return;
			}
			var prices = node.textContent.replace(/\s/g, "").split("–");
			$(this).find("small").attr("style", "color:#999;font-size:10px;font-weight:normal;");
			$(node).after("<br /><span style=\"color:#999;font-size:10px;font-weight:normal;\">" + node.textContent + "</span>");
			node.textContent = prices.map(function (value) { return "$" + Math.ceil((value/USDExchangeRate)*2)/2; }).join(" - ");
		});
	});
}
window.addEventListener("load", convertPricesToUSD);