Greasy Fork

Greasy Fork is available in English.

Yandex Eda price calculator

12/6/2024, 7:41:34 AM

目前为 2024-12-06 提交的版本。查看 最新版本

// ==UserScript==
// @name        Yandex Eda price calculator
// @namespace   Violentmonkey Scripts
// @match       *://eda.yandex.ru/*
// @grant       none
// @version     1.0
// @author      Insaf Burangulov
// @description 12/6/2024, 7:41:34 AM
// @license MIT
// ==/UserScript==

function calc_prices() {
    let cards = document.querySelectorAll('.UiKitDesktopProductCard_descriptionWrapper:not(.calculated-by-price)')

    cards.forEach(card => {
        const weightDiv = card.querySelector('.UiKitDesktopProductCard_weight');
        if (!weightDiv) {
            return;
        }

        const weightData = weightDiv.textContent.replace(/ /g, '\u00A0')
            .split('\u00A0');
        if (weightData.length < 2) {
            return;
        }

        const weight = parseInt(weightData[0]);
        const type = weightData[1];

        const priceDiv = card.querySelector('.UiKitDesktopProductCard_priceWrapper')
            .querySelector('span');

        if (!priceDiv) {
            return;
        }

        const priceData = priceDiv.textContent
            .replace(/\u2009/g, ' ')
            .split(' ');

        const price = parseInt(priceData[0]);

        if (type === 'г' || type === 'мл') {
            priceDiv.textContent = priceDiv.textContent +
                '/' + Math.round((price / weight) * 1000) + " " + priceData[1];
        }

        card.classList.add('calculated-by-price');
    })
}

setInterval(calc_prices, 1000);