0
0
mirror of https://github.com/Maks1mS/userscripts.git synced 2024-12-24 00:33:03 +03:00

[SteamPriceConverter] update to 0.5

replace only price in textContent
This commit is contained in:
Maxim Slipenko 2024-06-22 23:55:35 +03:00
parent 5de1a557f1
commit fbe2e6e830

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Steam Price Converter // @name Steam Price Converter
// @namespace https://github.com/Maks1mS/userscripts // @namespace https://github.com/Maks1mS/userscripts
// @version 0.4 // @version 0.5
// @description Converts prices to rubles // @description Converts prices to rubles
// @author Maxim Slipenko // @author Maxim Slipenko
// @match https://store.steampowered.com/* // @match https://store.steampowered.com/*
@ -78,10 +78,22 @@
for (let i = 0; i < r.snapshotLength; i++) { for (let i = 0; i < r.snapshotLength; i++) {
let n = r.snapshotItem(i); let n = r.snapshotItem(i);
const value = parseFloat(n.textContent.replace(" ", "").replace(',', '.')) let textContent = n.textContent;
let regex = new RegExp(`(${state.source_symbol}\\s*[0-9\\s]+[.,]?[0-9]*|[0-9\\s]+[.,]?[0-9]*\\s*${state.source_symbol})`, 'g');
n.replaceWith(`${convert(value)} ₽ / ${value} ${state.source_symbol}`); let newContent = textContent.replace(regex, (match) => {
console.log(n) let value;
if (match.includes(state.source_symbol)) {
value = parseFloat(match.replace(state.source_symbol, '').replace(' ', '').replace(',', '.').trim());
} else {
value = parseFloat(match.replace(' ', '').replace(',', '.'));
}
return `${convert(value)} ₽ / ${value} ${state.source_symbol}`;
});
let newNode = document.createTextNode(newContent);
n.parentNode.replaceChild(newNode, n);
console.log(newNode);
} }
} }