LztCurrencyApi

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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