USDPrices

USD price for catalog.onliner.by

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);