Загрузка...

Маркет Автоматизация Утилита Калькулятор для массовых покупок на маркете

Тема в разделе Дополнения создана пользователем PowerDevil 24 мар 2025. 128 просмотров

Загрузка...
  1. PowerDevil
    PowerDevil Автор темы 24 мар 2025 12 076 27 авг 2022
    Калькулятор для массовых покупок на маркете
    [IMG]
    [IMG]
    JS
    // ==UserScript==
    // @name LZT MassBuy Calculator
    // @namespace http://tampermonkey.net/
    // @version 1.0
    // @description Автоматически рассчитывает общую стоимость покупки на lzt.market
    // @author HashBrute
    // @match https://lzt.market/mass-buy/*
    // @grant GM_addStyle
    // ==/UserScript==
    (function() {
    'use strict';

    const style = 2;











    if (style === 2) {
    const customStyles = `
    .calc-box {
    background-color: #1a1a1a;
    border: 1px solid #2d2d2d;
    border-radius: 4px;
    padding: 10px 12px;
    margin: 12px 0;
    }
    .calc-heading {
    font-size: 13px;
    color: #cccccc;
    margin-bottom: 8px;
    font-weight: bold;
    }
    .calc-price {
    font-size: 16px;
    font-weight: bold;
    color: #00ba78;
    margin-bottom: 6px;
    }
    .calc-note {
    font-size: 11px;
    color: #999;
    padding: 4px;
    background-color: #222;
    border-radius: 2px;
    }
    `;
    if (typeof GM_addStyle !== 'undefined') {
    GM_addStyle(customStyles);
    } else {
    const styleNode = document.createElement('style');
    styleNode.innerHTML = customStyles;
    document.head.appendChild(styleNode);
    }
    }
    function calculateTotalPrice() {
    const quantityInput = document.querySelector('input[name="account_amount"]');
    const priceInput = document.getElementById('PmaxInput');
    if (!quantityInput || !priceInput) return;
    const quantity = parseInt(quantityInput.value) || 0;
    const price = parseFloat(priceInput.value) || 0;
    const totalPrice = quantity * price;

    if (style === 1) {
    const calculatorBlock = document.querySelector('.FinishPriceCalculator');
    if (calculatorBlock) {
    calculatorBlock.classList.remove('hidden');
    const valueElement = calculatorBlock.querySelector('.Value');
    if (valueElement) {
    valueElement.textContent = totalPrice.toFixed(2);
    }
    } else {
    createClassicCalculatorBlock(totalPrice);
    }
    } else {
    const calculatorBlock = document.querySelector('#calc-box');
    if (calculatorBlock) {
    const valueElement = calculatorBlock.querySelector('.calc-price');
    if (valueElement) {
    valueElement.textContent = totalPrice.toFixed(2) + ' ₽';
    }
    } else {
    createDarkCalculatorBlock(totalPrice);
    }
    }
    }

    function createClassicCalculatorBlock(totalPrice) {
    const form = document.getElementById('MassBuyStartForm');
    if (!form) return;
    if (document.querySelector('.FinishPriceCalculator')) return;
    const calculatorDiv = document.createElement('div');
    calculatorDiv.className = 'FinishPriceCalculator';
    const heading = document.createElement('div');
    heading.className = 'textHeading mn-30-0-0';
    heading.innerHTML = '<strong>Цена за все аккаунты</strong>';
    const valueSpan = document.createElement('span');
    valueSpan.className = 'Value bold';
    valueSpan.style.fontWeight = 'bold';
    valueSpan.style.fontSize = '18px';
    valueSpan.textContent = totalPrice.toFixed(2);
    const rubSpan = document.createElement('span');
    rubSpan.className = 'svgIcon--rub bold';
    rubSpan.style.fontWeight = 'bold';
    rubSpan.style.fontSize = '18px';
    rubSpan.innerHTML = ' ₽';
    const noteSpan = document.createElement('div');
    noteSpan.style.color = '#999999';
    noteSpan.style.fontSize = '12px';
    noteSpan.style.marginTop = '5px';
    noteSpan.style.opacity = '0.7';
    noteSpan.textContent = 'Расчет при максимальной указанной цене за аккаунт';
    calculatorDiv.appendChild(heading);
    calculatorDiv.appendChild(valueSpan);
    calculatorDiv.appendChild(rubSpan);
    calculatorDiv.appendChild(noteSpan);

    insertCalculatorAtCorrectPosition(form, calculatorDiv);
    }

    function createDarkCalculatorBlock(totalPrice) {
    const form = document.getElementById('MassBuyStartForm');
    if (!form) return;
    if (document.querySelector('#calc-box')) return;
    const calculatorDiv = document.createElement('div');
    calculatorDiv.id = 'calc-box';
    calculatorDiv.className = 'calc-box';
    const heading = document.createElement('div');
    heading.className = 'calc-heading';
    heading.textContent = 'Цена за все аккаунты';
    const priceDiv = document.createElement('div');
    priceDiv.className = 'calc-price';
    priceDiv.textContent = totalPrice.toFixed(2) + ' ₽';
    const noteDiv = document.createElement('div');
    noteDiv.className = 'calc-note';
    noteDiv.textContent = 'Расчет при максимальной указанной цене за аккаунт';
    calculatorDiv.appendChild(heading);
    calculatorDiv.appendChild(priceDiv);
    calculatorDiv.appendChild(noteDiv);

    insertCalculatorAtCorrectPosition(form, calculatorDiv);
    }

    function insertCalculatorAtCorrectPosition(form, calculatorDiv) {
    const balanceBox = form.querySelector('.balanceBox');
    const mainc = form.querySelector('.mn-15-0-0.bold.mainc');
    if (balanceBox && mainc) {
    const balanceBoxParent = findParentElement(balanceBox);
    const maincParent = findParentElement(mainc);

    if (balanceBoxParent && balanceBoxParent.nextSibling === maincParent) {
    balanceBoxParent.parentNode.insertBefore(calculatorDiv, maincParent);
    return;
    }

    mainc.parentNode.insertBefore(calculatorDiv, mainc);
    return;
    }

    if (balanceBox) {
    const nextElement = findNextElement(balanceBox);
    if (nextElement) {
    nextElement.parentNode.insertBefore(calculatorDiv, nextElement);
    } else {
    balanceBox.parentNode.appendChild(calculatorDiv);
    }
    return;
    }

    const submitButton = form.querySelector('.mn-30-0-0');
    if (submitButton) {
    form.insertBefore(calculatorDiv, submitButton);
    } else {
    form.appendChild(calculatorDiv);
    }
    }

    function findParentElement(element) {
    let parent = element;
    while (parent && parent.tagName !== 'DIV') {
    parent = parent.parentNode;
    }
    return parent;
    }

    function findNextElement(element) {
    let parent = element;
    while (parent && parent.tagName !== 'DIV') {
    parent = parent.parentNode;
    }
    if (parent && parent.nextElementSibling) {
    return parent.nextElementSibling;
    }
    return element.nextElementSibling;
    }

    function init() {
    const quantityInput = document.querySelector('input[name="account_amount"]');
    const priceInput = document.getElementById('PmaxInput');
    if (quantityInput && priceInput) {
    quantityInput.addEventListener('input', calculateTotalPrice);
    priceInput.addEventListener('input', calculateTotalPrice);
    setTimeout(calculateTotalPrice, 500);
    }
    }

    window.addEventListener('load', init);
    setTimeout(init, 1000);
    })();
    Чтобы менять стиль меняйте цифру на 13 строчке const style = 2;
     
  2. llimonix
    Как этот функционал вышел больше чем на 10 строк или я чего то не понимаю
     
    1. Посмотреть предыдущие комментарии (21)
    2. MeloniuM
      llimonix, ты готов, сын мой. Мне больше нечему тебя учить :peace:
Top