(Steam 价格转换器)Steam Price Exchanger

Exchange price on steam and community

  1. // ==UserScript==
  2. // @name (Steam 价格转换器)Steam Price Exchanger
  3. // @version 0.3.2.0
  4. // @description Exchange price on steam and community
  5. // @author lzt,coralfox
  6. // @match *://*.steampowered.com/*
  7. // @match *://*.steamcommunity.com/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant unsafeWindow
  12. // @grant window
  13. // @connect api.augmentedsteam.com
  14. // @namespace steam_price_exchanger
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. "use strict";
  20.  
  21. // Your code here...
  22.  
  23. var style = document.createElement("style");
  24. style.type = "text/css";
  25. var text = document.createTextNode(".tab_item_discount {width: 180px;}");
  26. style.appendChild(text);
  27. var head = document.getElementsByTagName("head")[0];
  28. head.appendChild(style);
  29.  
  30. console.log(GM_getValue("timestamp"))
  31. if (GM_getValue("timestamp") == undefined) {GM_setValue("timestamp", 0);console.log("set timestamp to 0")};
  32. unsafeWindow.rub = {"rate": GM_getValue("rub"), "lock": 0};
  33. unsafeWindow.ars = {"rate": GM_getValue("ars"), "lock": 0};
  34.  
  35. function initobserver (rate, unit) {
  36. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  37. var target = document.body;
  38. var observer = new MutationObserver(function(mutations) {
  39. mutations.forEach(function(mutation) {
  40. unsafeWindow.fillprice(rate, unit, 500)
  41. });
  42. });
  43. var config = { attributes: true, childList: true, characterData: true, subtree: true}
  44. observer.observe(target, config);
  45. }
  46.  
  47. unsafeWindow.fillprice = function (rate, unit, delay){
  48. if (rate["lock"] == 1) {return -1};
  49. rate["lock"] = 1;
  50. var lists = document.evaluate("//*[contains(text(), '" + unit + "')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  51. var re = new RegExp(unit == "ARS"?"ARS\\$?\\s*[0-9.,]+":"[0-9.,]+\\s*pуб.?", "ig");
  52. for(let i = 0; i < lists.snapshotLength; i++) {
  53. var item = lists.snapshotItem(i)
  54. if (item.firstChild.nodeValue == null) {continue};
  55. if (item.firstChild.nodeValue.search("¥") != -1) {continue};
  56. if (item.classList.contains("es-regprice") & item.classList.contains("es-flag")) {continue};
  57. if (item.parentNode.classList.contains("es-flag--cn")) {continue};
  58.  
  59. var s = item.firstChild.nodeValue.match(re)
  60. if (s != null) {
  61. for(let j = 0; j < s.length; j++) {
  62. var price = s[j].replace(".", "");
  63. price = price.replace(",", ".");
  64. price = "¥" + parseInt(parseFloat(price.match(/[0-9.]+/))*rate["rate"]).toString();
  65. if ((item.classList.contains("col") & item.classList.contains("search_price")) |
  66. item.nodeName == "STRIKE") {
  67. item.firstChild.nodeValue = item.firstChild.nodeValue.replace(s[j], s[j].replace(" ", "") + "(" + price + ")").trim();
  68. }else {
  69. item.firstChild.nodeValue = item.firstChild.nodeValue.replace(s[j], s[j] + "(" + price + ")").trim()
  70. }
  71. }
  72. }
  73. }
  74. lists = document.getElementsByClassName("col search_price discounted");
  75. for (let i = 0; i < lists.length; i++) {
  76. if (lists[i].childNodes[3].nodeValue == null) {continue};
  77. if (lists[i].childNodes[3].nodeValue.search("¥") != -1) {continue};
  78. if (lists[i].childNodes[3].nodeValue.search(unit) == -1) {continue};
  79.  
  80. var price = lists[i].childNodes[3].nodeValue.replace(".", "");
  81. price = price.replace(",", ".");
  82. price = "¥" + parseInt(parseFloat(price.match(/[0-9.]+/))*rate["rate"]).toString();
  83. lists[i].childNodes[3].nodeValue = lists[i].childNodes[3].nodeValue.replace(" ", "").trim() + "(" + price + ")";
  84. }
  85. if (unit == "ARS") {setTimeout("window.ars['lock'] = 0", delay)}
  86. else{setTimeout("window.rub['lock'] = 0", delay)}
  87. }
  88.  
  89.  
  90. if ((new Date().getTime() - GM_getValue("timestamp")) >= 3600000*6 |
  91. typeof(unsafeWindow.rub) == undefined |
  92. typeof(unsafeWindow.ars) == undefined) {
  93. console.log("update rates")
  94. GM_xmlhttpRequest({
  95. method: "get",
  96. url: "https://api.augmentedsteam.com/v01/rates/?to=CNY",
  97. responseType: "json",
  98. onload: function(r) {
  99. unsafeWindow.ars["rate"] = r.response["data"]["ARS"]["CNY"];
  100. unsafeWindow.rub["rate"] =r.response["data"]["RUB"]["CNY"];
  101.  
  102. console.log(unsafeWindow.ars["rate"] + " ARS/CNY");
  103. console.log(unsafeWindow.rub["rate"] + " RUB/CNY");
  104. GM_setValue("rub", unsafeWindow.rub["rate"]);
  105. GM_setValue("ars", unsafeWindow.ars["rate"]);
  106. GM_setValue("timestamp", new Date().getTime());
  107.  
  108. unsafeWindow.fillprice(unsafeWindow.rub, "pуб", 0);
  109. unsafeWindow.fillprice(unsafeWindow.ars, "ARS", 0);
  110. initobserver(unsafeWindow.rub, "pуб");
  111. initobserver(unsafeWindow.ars, "ARS");
  112. }
  113. });
  114. }else{
  115. unsafeWindow.fillprice(unsafeWindow.rub, "pуб", 50);
  116. unsafeWindow.fillprice(unsafeWindow.ars, "ARS", 50);
  117. initobserver(unsafeWindow.rub, "pуб");
  118. initobserver(unsafeWindow.ars, "ARS");
  119. }
  120.  
  121.  
  122. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址