Steam Price Exchanger

Exchange price on steam

目前为 2020-09-03 提交的版本。查看 最新版本

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

QingJ © 2025

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