LztCurrencyApi

Отображает курс валют на маркете

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         LztCurrencyApi
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Отображает курс валют на маркете
// @author       vuchaev2015
// @match        https://lzt.market/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=lzt.market
// @grant        none
// ==/UserScript==

const api_url = 'https://raw.githubusercontent.com/fawazahmed0/currency-api/1/latest/currencies/';

const currencyMap = {
    'Рубль': 'rub',
    'Гривна': 'uah',
    'Тенге': 'kzt',
    'Бел. рубль': 'byn',
    'Доллар': 'usd',
    'Евро': 'eur',
    'Фунт стерлингов': 'gbp',
    'Юань': 'cny',
    'Турецкая лира': 'try'
};

const currencySymbolMap = {
    'rub': '₽',
    'uah': '₴',
    'kzt': '₸',
    'byn': 'BYN',
    'usd': '$',
    'eur': '€',
    'gbp': '£',
    'cny': '¥',
    'try': '₺'
};

const chosenCurrencyText = document.querySelector("#content > div > div > aside > div > div > div:nth-child(2) > div > div.marketSidebarMenu.bordered-top > div > form > div > a > span").textContent.trim();

const chosenCurrency = chosenCurrencyText.split(' — ')[0];
console.log(chosenCurrencyText)
const currency = currencyMap[chosenCurrency];
console.log(currency)
const currencySymbol = currencySymbolMap[currency];
console.log(currencySymbol)

const usd_url = `${api_url}/usd/${currency}.json`;
const eur_url = `${api_url}/eur/${currency}.json`;
const cny_url = `${api_url}/cny/${currency}.json`;

async function getCurrencyValue(url) {
    const response = await fetch(url);
    const data = await response.json();
    return data[currency];
}

async function addCurrencyValues() {
    const usd_value = await getCurrencyValue(usd_url);
    const eur_value = await getCurrencyValue(eur_url);
    const cny_value = await getCurrencyValue(cny_url);

    const currencies = [
        { name: 'USD', value: usd_value },
        { name: 'EUR', value: eur_value },
        { name: 'CNY', value: cny_value }
    ];

   const currencyHtml = currencies.map((currency, index) => `
    <div class="item">
        <div class="trimmedTitle">${currency.name}</div>
        <div class="paymentFooter">
            <span class="priceBadgeTransparent">${currency.value} ${currencySymbol}</span>
        </div>
    </div>
    ${index === currencies.length - 1 ? '' : '<br>'}
`).join('');


    const html = `
        <br><div class="secondaryContent">
            <h3><a href="https://github.com/fawazahmed0/currency-api/tree/1/latest">Курс валют</a></h3>
            <div class="marketCurrencyApi marketCurrencyItems">
                <div class="wrapper">
                    ${currencyHtml}
                </div>
            </div>
            <a href="https://github.com/fawazahmed0/currency-api/tree/1/latest/" class="mn-15-0-0 button full">Посмотреть все</a>
        </div>
    `;

    document.querySelector('#content > div > div > aside > div > div > div:nth-child(3)').innerHTML += html;
}

addCurrencyValues();