Skip to content

Instantly share code, notes, and snippets.

@phts
Last active August 15, 2022 15:38
Show Gist options
  • Save phts/b7d7e0e5ead60066e38ba11af4eb1468 to your computer and use it in GitHub Desktop.
Save phts/b7d7e0e5ead60066e38ba11af4eb1468 to your computer and use it in GitHub Desktop.
USD prices on Onliner catalog
// ==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