mirror of
https://github.com/Maks1mS/userscripts.git
synced 2024-12-23 16:22:59 +03:00
[SteamPriceConverter] update to 0.3
- add timeout and source price viewing (#1)
This commit is contained in:
parent
32a4239fe4
commit
db9d93407d
@ -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.2
|
// @version 0.3
|
||||||
// @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/*
|
||||||
@ -10,7 +10,7 @@
|
|||||||
// @grant GM_registerMenuCommand
|
// @grant GM_registerMenuCommand
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const SYMBOL_TO_CODE_MAPPING = {
|
const SYMBOL_TO_CODE_MAPPING = {
|
||||||
@ -28,7 +28,7 @@
|
|||||||
GM_xmlhttpRequest({
|
GM_xmlhttpRequest({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: 'https://www.cbr-xml-daily.ru/daily_utf8.xml',
|
url: 'https://www.cbr-xml-daily.ru/daily_utf8.xml',
|
||||||
onload: function(res) {
|
onload: function (res) {
|
||||||
const valutes = res.responseXML.getElementsByTagName('Valute');
|
const valutes = res.responseXML.getElementsByTagName('Valute');
|
||||||
resolve([...valutes].map((valute) => {
|
resolve([...valutes].map((valute) => {
|
||||||
const charCode = valute.getElementsByTagName('CharCode')[0].textContent;
|
const charCode = valute.getElementsByTagName('CharCode')[0].textContent;
|
||||||
@ -62,6 +62,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(75);
|
||||||
|
|
||||||
const convert = (n) => +(n * rates[source_valute].value).toFixed(2);
|
const convert = (n) => +(n * rates[source_valute].value).toFixed(2);
|
||||||
replace(convert);
|
replace(convert);
|
||||||
|
|
||||||
@ -69,12 +71,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replace(convert) {
|
function replace(convert) {
|
||||||
let r = document.evaluate(`//text()[contains(., \"${state.source_symbol}\")]`,document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
let r = document.evaluate(`//text()[contains(., \"${state.source_symbol}\")]`, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||||
|
|
||||||
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(',', '.'))
|
const value = parseFloat(n.textContent.replace(" ", "").replace(',', '.'))
|
||||||
n.replaceWith(`${convert(value)} ₽`);
|
|
||||||
|
n.replaceWith(`${convert(value)} ₽ / ${value} ${state.source_symbol}`);
|
||||||
console.log(n)
|
console.log(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user