Greasy Fork is available in English.

Steam Price Exchanger

Exchange price on steam and community

< Feedback em Steam Price Exchanger

Avaliação: Bom - o script funciona

§
Publicado: 24/12/2021
Editado: 24/12/2021

稍微改写了一下,代码发下面了,添加了土耳其里拉转人民币,另外把保留到元改成了保留到分,有需要的可以直接用。
不过有个问题是不知道为什么获取不到itad的汇率信息,总之就直接用当前汇率了,所以仅供参考用。
另外作者若觉得不妥可以删除。

// ==UserScript==
// @name Steam Price Exchanger
// @version 0.3.1.0 ?
// @description Exchange price on steam and community
// @author lzt
// @match *://*.steampowered.com/*
// @match *://*.steamcommunity.com/*
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant unsafeWindow
// @grant window
// @connect esapi.isthereanydeal.com
// @namespace steam_price_exchanger
// ==/UserScript==

(function() {
"use strict";

// Your code here...

var style = document.createElement("style");
style.type = "text/css";
var text = document.createTextNode(".tab_item_discount {width: 180px;}");
style.appendChild(text);
var head = document.getElementsByTagName("head")[0];
head.appendChild(style);

console.log(GM_getValue("timestamp"))
if (GM_getValue("timestamp") == undefined) {GM_setValue("timestamp", 0);console.log("set timestamp to 0")};
unsafeWindow.rub = {"rate": GM_getValue("rub"), "lock": 0};
unsafeWindow.ars = { "rate": GM_getValue("ars"), "lock": 0 };
unsafeWindow.try = { "rate": GM_getValue("try"), "lock": 0 };

function initobserver (rate, unit) {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var target = document.body;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
unsafeWindow.fillprice(rate, unit, 500)
});
});
var config = { attributes: true, childList: true, characterData: true, subtree: true}
observer.observe(target, config);
}
unsafeWindow.fillprice = function (rate, unit, delay){
if (rate["lock"] == 1) {return -1};
rate["lock"] = 1;
var lists = document.evaluate("//*[contains(text(), '" + unit + "')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var re;
switch (unit) {
case "ARS":
re = new RegExp("ARS\\$?\\s*[0-9.,]+", "ig");
break;
case "pуб":
re = new RegExp("[0-9.,]+\\s*pуб.?", "ig");
break;
case "TL":
re = new RegExp("[0-9.,]+\\s*TL?", "ig")
break;
}

for (let i = 0; i < lists.snapshotLength; i++) {
var item = lists.snapshotItem(i)
if (item.firstChild.nodeValue == null) {continue};
if (item.firstChild.nodeValue.search("¥") != -1) {continue};
if (item.classList.contains("es-regprice") & item.classList.contains("es-flag")) {continue};
if (item.parentNode.classList.contains("es-flag--cn")) {continue};

var s = item.firstChild.nodeValue.match(re)
if (s != null) {
for (let j = 0; j < s.length; j++) {
if (unit != "TL") {
var price = s[j].replace(".", "");
price = price.replace(",", ".");
price = "¥" + parseInt(parseFloat(price.match(/[0-9.]+/))*rate["rate"]).toString();
}
else {
var price = s[j].replace(",", ".");
//price = "¥" + parseInt(parseFloat(price.match(/[0-9.]+/)) * rate["rate"]).toString();
price = rate["rate"];

}
if ((item.classList.contains("col") & item.classList.contains("search_price")) |
item.nodeName == "STRIKE") {
item.firstChild.nodeValue = item.firstChild.nodeValue.replace(s[j], s[j].replace(" ", "") + "(" + price + ")").trim();
}else {
item.firstChild.nodeValue = item.firstChild.nodeValue.replace(s[j], s[j] + "(" + price + ")").trim()
}
}
}
}
lists = document.getElementsByClassName("col search_price discounted");
for (let i = 0; i < lists.length; i++) {
if (lists[i].childNodes[3].nodeValue == null) {continue};
if (lists[i].childNodes[3].nodeValue.search("¥") != -1) {continue};
if (lists[i].childNodes[3].nodeValue.search(unit) == -1) {continue};

var price = lists[i].childNodes[3].nodeValue.replace(".", "");
price = price.replace(",", ".");
price = "¥" + parseInt(parseFloat(price.match(/[0-9.]+/))*rate["rate"]).toString();
lists[i].childNodes[3].nodeValue = lists[i].childNodes[3].nodeValue.replace(" ", "").trim() + "(" + price + ")";
}
switch (unit) {
case "ARS":
setTimeout("window.ars['lock'] = 0", delay);
break;
case "py6":
setTimeout("window.rub['lock'] = 0", delay);
break;
case "TL":
setTimeout("window.try['lock'] = 0", delay);
break;
}
}
if ((new Date().getTime() - GM_getValue("timestamp")) >= 3600000*6 |
typeof(unsafeWindow.rub) == undefined | typeof(unsafeWindow.ars) == undefined | typeof(unsafeWindow.try) == undefined) {
console.log("update rates")
GM_xmlhttpRequest({
method: "get",
url: "https://esapi.isthereanydeal.com/v01/rates/?to=CNY",
responseType: "json",
onload: function(r) {
unsafeWindow.ars["rate"] = r.response["data"]["ARS"]["CNY"];
unsafeWindow.rub["rate"] = r.response["data"]["RUB"]["CNY"];
unsafeWindow.try["rate"] = r.response["data"]["TRY"]["CNY"];

console.log(unsafeWindow.ars["rate"] + " ARS/CNY");
console.log(unsafeWindow.rub["rate"] + " RUB/CNY");
console.log(unsafeWindow.try["rate"] + " TRY/CNY");
GM_setValue("rub", unsafeWindow.rub["rate"]);
GM_setValue("ars", unsafeWindow.ars["rate"]);
GM_setValue("try", unsafeWindow.try["rate"]);
GM_setValue("timestamp", new Date().getTime());

unsafeWindow.fillprice(unsafeWindow.rub, "pуб", 0);
unsafeWindow.fillprice(unsafeWindow.ars, "ARS", 0);
unsafeWindow.fillprice(unsafeWindow.try, "TL", 0);
initobserver(unsafeWindow.rub, "pуб");
initobserver(unsafeWindow.ars, "ARS");
initobserver(unsafeWindow.try, "TL");
}
});
}else{
unsafeWindow.fillprice(unsafeWindow.rub, "pуб", 50);
unsafeWindow.fillprice(unsafeWindow.ars, "ARS", 50);
unsafeWindow.fillprice(unsafeWindow.try, "TL", 50);
initobserver(unsafeWindow.rub, "pуб");
initobserver(unsafeWindow.ars, "ARS");
initobserver(unsafeWindow.try, "TL");
}


})();

§
Publicado: 28/06/2022

兄弟,不好使了啊,能搞个土耳其的吗?

Publicar resposta

Faça o login para publicar uma resposta.