USDPrices

USD price for catalog.onliner.by

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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