Last active
June 9, 2023 19:09
-
-
Save Saoneth/a158783a218e2d0ad59a67663f2d0ff5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Steam: convert ARS currency to another | |
// @namespace http://tampermonkey.net/ | |
// @version 0.9 | |
// @author Saoneth | |
// @match https://store.steampowered.com/* | |
// @match https://steamcommunity.com/* | |
// @grant GM.xmlHttpRequest | |
// @grant GM.setValue | |
// @grant GM.getValue | |
// @connect stooq.pl | |
// @run-at document-end | |
// @updateURL https://gist.github.com/Saoneth/a158783a218e2d0ad59a67663f2d0ff5/raw/steam-currency-converter.meta.js | |
// @downloadURL https://gist.github.com/Saoneth/a158783a218e2d0ad59a67663f2d0ff5/raw/steam-currency-converter.user.js | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Steam: convert ARS currency to another | |
// @namespace http://tampermonkey.net/ | |
// @version 0.9 | |
// @author Saoneth | |
// @match https://store.steampowered.com/* | |
// @match https://steamcommunity.com/* | |
// @grant GM.xmlHttpRequest | |
// @grant GM.setValue | |
// @grant GM.getValue | |
// @connect stooq.pl | |
// @run-at document-end | |
// @updateURL https://gist.github.com/Saoneth/a158783a218e2d0ad59a67663f2d0ff5/raw/steam-currency-converter.meta.js | |
// @downloadURL https://gist.github.com/Saoneth/a158783a218e2d0ad59a67663f2d0ff5/raw/steam-currency-converter.user.js | |
// ==/UserScript== | |
(async function() { | |
'use strict'; | |
const currencies = ['AUD', 'BGN', 'BRL', 'BTC', 'CAD', 'CHF', 'CLP', 'CNY', 'CZK', 'DKK', 'EGP', 'EUR', 'GBP', 'HKD', 'HRK', 'HUF', 'IDR', 'ILS', 'INR', 'ISK', 'JPY', 'KRW', 'MXN', 'MYR', 'NAD', 'NOK', 'NZD', 'PHP', 'PLN', 'RON', 'RUB', 'SEK', 'SGD', 'THB', 'TRY', 'TWD', 'UAH', 'XAG', 'XAU', 'XDR', 'XPD', 'XPT', 'ZAR', 'USD']; | |
async function getData() { | |
let data = await GM.getValue('currency_data'); | |
if (!data) { | |
return {currency: null, rate: null, time: 0}; | |
} | |
data = JSON.parse(data); | |
if ((new Date).getTime() - data.time > 24*3600*1000) { | |
data.rate = null; | |
} | |
return data; | |
} | |
async function setData(currency, rate) { | |
data = {currency: currency, rate: rate, time: (new Date).getTime()}; | |
return await GM.setValue('currency_data', JSON.stringify(data)); | |
} | |
async function ajax(url) { | |
return new Promise(function(resolve, reject) { | |
GM.xmlHttpRequest({ | |
method: "GET", | |
url: url, | |
onload: function(response) { | |
resolve(response.responseText); | |
} | |
}); | |
}); | |
} | |
async function promptCurrency(url) { | |
return new Promise(function(resolve, reject) { | |
const modal = ShowPromptDialog('Select Currency', '', 'Save', 'Cancel'); | |
jQuery('input', modal.m_$StandardContent) | |
.css('display', 'none') | |
.after('<select style="outline:none; background-color:rgba(0,0,0,0.2); border:1px solid #000; box-shadow:1px 1px 0 0 rgba(91, 132, 181, 0.2); font-size:13px; color:#BFBFBF; width:100%;" onchange="this.parentNode.querySelector(\'input\').value = this.value"><option value="" style="color:initial">Select...</option>' + currencies.map(v => '<option style="color:initial">' + v + '</option>').join('') + '</select>'); | |
modal.done(currency => { | |
if (!currency) { | |
return; | |
} | |
resolve(currency); | |
}); | |
}); | |
} | |
let data = await getData(); | |
if (!data.currency) { | |
setData(await promptCurrency(), null); | |
} | |
if (!data.rate) { | |
const rate = (await ajax('https://stooq.pl/cmp/?q=' + data.currency.toLowerCase() + 'ars')).split('~')[3]; | |
setData(data.currency, rate); | |
} | |
convert(); | |
function convert() { | |
const conversion_factor = parseFloat(data.rate); | |
const a = function() { | |
[...document.querySelectorAll([ | |
'.discount_final_price', | |
'.discount_original_price', | |
'.game_purchase_price', | |
'.broadcastwidgets_StoreSalePriceBox_2A_NW', | |
'#header_wallet_balance', | |
'#marketWalletBalanceAmount', | |
'.market_commodity_orders_header_promote', | |
'.market_commodity_orders_table tr td:first-child', | |
'.normal_price', | |
'.sale_price', | |
'.price', | |
'.search_price', | |
'.match_price', | |
'.game_area_dlc_price', | |
'.itad-pricing__price', | |
'.itad-pricing__main', | |
'.es_regional_converted', | |
'.browse_tag_game_price', | |
'.wht_total', | |
'.wallet_column', | |
'.specials_under10', | |
'.recommended_spotlight_price', | |
'.pageheader', | |
'.steamtown_bubble_ctn', | |
'.reward_discount_desc', | |
'.bundle_savings', | |
'.steamdb_prices', | |
'.btn_small_tall > span', | |
'.home_title', | |
'.market_listing_my_price', | |
'.market_listing_price', | |
'#my_market_sellistings_total_price', | |
'#receipt_total_price', | |
'.inventory_item_link', | |
'.game_area_purchase_game_dropdown_menu_item_text', | |
'.steamdb_prices', | |
'#price_range_display', | |
'#listings_group', | |
'a[id^="quick_sell"]', | |
'.steamdb_quick_sell a', | |
'.inventory_item_price', | |
'.jqplot-highlighter-tooltip', | |
'.jqplot-yaxis-tick', | |
'.jqplot-xaxis-tick', | |
'.responsive_menu_user_wallet', | |
'#logger', | |
'#loggerTotal', | |
].join(', '))] | |
.filter(el => el.innerText.indexOf('ARS$') > -1) | |
.forEach(el => { | |
if (!el.innerHTML.match(/ARS\$ [0-9]+\.[0-9]+,[0-9]+/g) && el.innerHTML.match(/ARS\$ [0-9]+\.[0-9]+/g)) { | |
el.innerHTML = el.innerHTML | |
.replace( | |
/ARS\$ (([0-9]+\.)?[0-9]+)/g, | |
(all, price) => (parseFloat(price.replace('.', ',')) / conversion_factor).toLocaleString( | |
'pl-PL', | |
{ | |
style: 'currency', | |
currency: data.currency, | |
minimumFractionDigits: 2, | |
maximumFractionDigits: 2, | |
} | |
) | |
) | |
} else { | |
el.innerHTML = el.innerHTML | |
.replace( | |
/ARS\$ (([0-9]+\.)?[0-9]+(,[0-9]+)?)/g, | |
(all, price) => (parseFloat(price.replace('.', '').replace(',', '.')) / conversion_factor).toLocaleString( | |
'pl-PL', | |
{ | |
style: 'currency', | |
currency: data.currency, | |
minimumFractionDigits: 2, | |
maximumFractionDigits: 2, | |
} | |
) | |
) | |
.replace( | |
/(([0-9]+\.)?[0-9]+(,[0-9]+)?)ARS\$/g, | |
(all, price) => (parseFloat(price) / conversion_factor).toLocaleString( | |
'pl-PL', | |
{ | |
style: 'currency', | |
currency: data.currency, | |
minimumFractionDigits: 2, | |
maximumFractionDigits: 2, | |
} | |
) | |
) | |
.replace( | |
/ARS\$(([0-9]+\.)?[0-9]+(,[0-9]+)?)/g, | |
(all, price) => (parseFloat(price) / conversion_factor).toLocaleString( | |
'pl-PL', | |
{ | |
style: 'currency', | |
currency: data.currency, | |
minimumFractionDigits: 2, | |
maximumFractionDigits: 2, | |
} | |
) | |
) | |
} | |
}); | |
}; | |
a(); | |
setInterval(a, 100); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ппривет