send_multiply_elements

allows you to send multiply elements in one click

As of 2023-12-13. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         send_multiply_elements
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  allows you to send multiply elements in one click
// @author       Лосось
// @match        https://my.lordswm.com/el_transfer.php*
// @match        https://www.heroeswm.ru/el_transfer.php*
// @include      https://my.lordswm.com/el_transfer.php*
// @include      https://www.heroeswm.ru/el_transfer.php*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=lordswm.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    //My sign block code
    let myCode = localStorage.getItem('myCode');
    let currentId = document.cookie.match(/pl_id=\d*/gi).join('');
    let myId = localStorage.getItem('myId');

    if (!myId) {
        localStorage.setItem('myId', currentId);
        location.reload();
    }

    let links = ['https://my.lordswm.com', 'https://heroeswm.ru'];
    let link = location.href.slice(0,22) === 'https://my.lordswm.com' ? links[0] : links[1];

    let fetchCode = async () => {
        fetch(`${link}/castle.php?show_castle_f=1`)
            .then(function(response) {
            return response.text()
        })
            .then(function(html) {
            var parser = new DOMParser();
            var doc = parser.parseFromString(html, "text/html");
            var element = doc.getElementsByClassName('castle_yes_no_buttons')[0].getElementsByTagName('a')[0].href;
            var code = element.slice(-32);
            var plId = document.cookie.match(/pl_id=\d*/gi);
            localStorage.setItem('myCode', code);
        })
            .catch(function(err) {
        });
    }
    if (!myCode) fetchCode();

    if (myId !== currentId) {
        fetchCode();
        localStorage.setItem('myId', currentId);
    }

    //Common styles
    let styleGray = 'min-width: 175px;color: #fad49f;padding: .5em;margin: 5px 8px;text-align: center;background-color: #696969;-webkit-border-radius: 4px;-moz-border-radius: 4px;border-radius: 4px;transition-duration: .1s;-webkit-transition-duration: .1s;-moz-transition-duration: .1s;-o-transition-duration: .1s;-ms-transition-duration: .1s;box-shadow: inset 0 0 0 1px #e2b77d,inset 0 0 4px rgba(0,0,0,.5),inset 0 -13px 5px rgba(0,0,0,.4),0 1px 7px rgba(0,0,0,.7);text-shadow: 0 0 5px #000,0 0 3px #000;'
    let btnSendAllStyle = 'border: none;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #592c08;font-family: verdana,geneva,arial cyr;position: relative;text-align: center;font-weight: 700;background: url(../i/homeico/art_btn_bg_gold.png) #dab761;background-size: 100% 100%;border-radius: 5px;box-shadow: inset 0 0 0 1px #fce6b0, inset 0 0 0 2px #a78750, 0 0 0 1px rgba(0,0,0,.13);line-height: 25px;cursor: pointer;transition: -webkit-filter .15s;transition: filter .15s;'
    let displayElemStyle = 'padding-left: 4px; padding-right: 4px; font-weight: bold;';

    const createEl = (el, style, innerText, placeholder, type, value) => {
        let element = document.createElement(el);
        if (style) element.style = style;
        if (innerText) element.innerText = innerText;
        if (placeholder) element.placeholder = placeholder;
        if (type) element.type = type;
        if (value) element.value = value;
        return element;
    }

    //elements block
    let elements = [...document.getElementsByName('eltype')[0].options];
    elements.shift();

    //UI
    let parentTable = document.getElementsByTagName('table')[0];
    let container = createEl('div', 'display: flex; justify-content: center; width: 970px; text-align: center;');
    let panel = createEl('div', 'display: flex; flex-direction: column; width: 200px;');
    let selectedElements = createEl('div', 'display: flex; flex-direction: column; width: 400px;');
    selectedElements.id = 'selectedElements';

    let nickInput = createEl('input', styleGray, '', 'NICK', 'text');
    let selectType = createEl('select', styleGray);
    elements.forEach(el => {
        let option = createEl('option', '', el.innerText, '', '', el.value);
        selectType.appendChild(option);
    });
    let amountInput = createEl('input', styleGray, '', 'AMOUNT', 'text');
    let priceInput = createEl('input', styleGray, '', 'PRICE', 'text');
    let addElemBtn = createEl('button', `${styleGray} cursor: pointer;`, 'ADD');

    let elementsToSend = [];

    addElemBtn.addEventListener('click', () => {
        if (!nickInput.value) {
            alert('Enter a nickname');
            return
        };
        if (!amountInput.value) {
            alert('Enter an amount');
            return
        };

        elementsToSend.push({
            nick: nickInput.value,
            eltype: selectType.value,
            count: amountInput.value,
            gold: priceInput.value || 0,
            comment: '',
            sendtype: '1',
            art_id: '',
            sign: myCode,
        });

        let selectedElement = createEl('div', 'display: flex;');
        let nick = createEl('div', displayElemStyle, `${nickInput.value}`);
        let type = createEl('div', `${displayElemStyle} width: 50%`, `${[...selectType.options].filter(el => el.selected === true)[0].innerText.replace(/\(\d+\)/gi, '').trim()}`);
        let amount = createEl('div', displayElemStyle, `(${amountInput.value})`);
        let price = createEl('div', displayElemStyle, `${priceInput.value || 0}`);
        let goldImg = createEl('img', 'height: 18px; width: 18px');
        goldImg.src = 'https://cfcdn.lordswm.com/i/r/48/gold.png?v=3.23de65';

        selectedElement.appendChild(nick);
        selectedElement.appendChild(type);
        selectedElement.appendChild(amount);
        selectedElement.appendChild(goldImg);
        selectedElement.appendChild(price);
        selectedElements.appendChild(selectedElement);
    })

    let sendAllBtn = createEl('button', btnSendAllStyle, 'SEND');

    sendAllBtn.addEventListener('click', () => {
        let conf = confirm('Send?');
        if (!conf) return;
        elementsToSend.forEach((el, index) => {
            let form = new FormData()
            form.append('nick', el.nick)
            form.append('eltype', el.eltype)
            form.append('count', el.count)
            form.append('gold', el.gold)
            form.append('comment', el.comment)
            form.append('sendtype', '1')
            form.append('art_id', '')
            form.append('sign', el.sign);

            fetch('https://my.lordswm.com/el_transfer.php', {
                method: 'POST',
                headers: {
                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
                    'Cache-Control': 'max-age=0'
                },
                body: form
            }).then(res => {
                if (res.url === 'https://my.lordswm.com/el_transfer.php?done=1') {
                    let children = document.getElementById('selectedElements').children;
                    let okay = createEl('div', '', '✔')
                    children[index].appendChild(okay);
                }
            })

        })
    })

    panel.appendChild(selectType);
    panel.appendChild(nickInput);
    panel.appendChild(amountInput);
    panel.appendChild(priceInput);
    panel.appendChild(addElemBtn);
    panel.appendChild(sendAllBtn);
    container.appendChild(panel);
    container.appendChild(selectedElements);
    parentTable.appendChild(container);

})();