Скрипт для tampermonkey
Протестировал с Хрома на ПК
На телефоне не тестировал
// ==UserScript==
// @name GWARS price per item
// @match
https://www.gwars.io/market-i.php*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function waitForElements(callback) {
const interval = setInterval(() => {
const priceInput = document.querySelector('input[name="submitprice"]');
const itemSelect = document.querySelector('select[name="item_iid"]');
if (priceInput && itemSelect) {
clearInterval(interval);
callback(priceInput, itemSelect);
}
}, 300);
}
function parseItem(select) {
const text = select.options[select.selectedIndex].text;
const match = text.match(/[(d+)/(d+)]/);
if (!match) return null;
return {
count: parseInt(match[1], 10),
second: parseInt(match[2], 10)
};
}
waitForElements((priceInput, itemSelect) => {
itemSelect.addEventListener('change', () => {
location.reload();
});
let tr = null;
function updateUI() {
const data = parseItem(itemSelect);
if (!data || data.second !== 0) return;
tr = document.createElement('tr');
const tdLabel = document.createElement('td');
tdLabel.className = 'wb';
tdLabel.setAttribute('bgcolor', '#d0eed0');
tdLabel.setAttribute('align', 'right');
tdLabel.textContent = 'Цена за 1шт:';
const tdInput = document.createElement('td');
tdInput.className = 'wb';
const perItemInput = document.createElement('input');
perItemInput.type = 'number';
perItemInput.placeholder = '0';
const info = document.createElement('span');
info.style.marginLeft = '10px';
tdInput.appendChild(perItemInput);
tdInput.appendChild(info);
tr.appendChild(tdLabel);
tr.appendChild(tdInput);
const priceRow = priceInput.closest('tr');
priceRow.parentNode.insertBefore(tr, priceRow);
function updatePrice() {
const count = data.count;
const perItem = parseFloat(perItemInput.value) || 0;
priceInput.value = Math.round(count * perItem);
info.textContent = `(${count} шт.)`;
}
perItemInput.addEventListener('input', updatePrice);
updatePrice();
}
updateUI();
});
})();