Last active
August 15, 2022 15:38
-
-
Save phts/b7d7e0e5ead60066e38ba11af4eb1468 to your computer and use it in GitHub Desktop.
USD prices on Onliner catalog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @grant none | |
// @match https://catalog.onliner.by/* | |
// @name USD prices on Onliner catalog | |
// @namespace https://github.com/phts/ | |
// @version 1.0.2 | |
// ==/UserScript== | |
setTimeout(() => { | |
const rateText = $('.helpers_hide_desktop .js-currency-widget').text().replace(/[^0-9,]/g, '').replace(/,/g, '.') | |
const rate = parseFloat(rateText) | |
$('.offers-description__price > a').each((i, a) => { | |
const $a = $(a) | |
const text = $a.text() | |
const prices = text.replace(/[^0-9,–]/g, "").replace(/,/g, '.').split("–") | |
const usdPrices = prices | |
.map(x => parseFloat(x)) | |
.map(x => x / rate) | |
.map(x => x.toFixed(2)) | |
.map(x => `$${x}`) | |
const usdPricesText = ` (${usdPrices.join(' – ')})` | |
$a.append(usdPricesText) | |
}) | |
}, 2000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment