zeloff / Ozon sale percent

// ==UserScript==
// @name         Ozon sale percent
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  calc percent of sale price
// @author       zeloff
// @match        https://*.ozon.ru/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    console.log('hello ozon')

    let getPrice = (rawPrice) => {
        return rawPrice.slice(0, rawPrice.length-2).replace(' ', '')
    }
    let addPercents = () => {
        for (let div of document.querySelectorAll('[data-widget="searchResultsV2"]>div>div>div>div>div[style]')) {
            if (
                !div.attributes.style.value.includes('ozTextPrimaryNegative') || div.innerText.includes('%')
            ) continue

            let salePrice = getPrice(div.innerText)
            let commonPrice = getPrice(div.parentElement.nextElementSibling.childNodes[0].innerText)
            let percent = (100-salePrice/commonPrice*100).toFixed(1)
            div.innerText += ` -${percent}%`
            // console.log(commonPrice, salePrice)
        }
    }

    setInterval(addPercents, 1000)

    // Your code here...
})();